Coinmonks
Published in

Coinmonks

How to test a BEP20 token with Hardhat and not get SCAMmed

Table of contents

  1. Why was SCAM token chosen for this post?
  2. Inspect the SCAM contract source code
  3. Prepare tests for it
  4. Conclusion

1. Why was SCAM token chosen for this post?

2. Inspect the SCAM contract source code

3. Prepare tests for it

module.exports = {
defaultNetwork: "hardhat",
paths: {
artifacts: './src/artifacts',
},
networks: {
// $npx hardhat run scripts/deploy.js --network localhost
// https://hardhat.org/config/
hardhat: {
chainId: 1337,
},
},
solidity: "0.5.6", // This is where you should edit.
};
Creating Typechain artifacts in directory typechain for target ethers-v5
Successfully generated Typechain artifacts!
$python
>>> hex(1000000000000000000000000)
'0xd3c21bcecceda1000000'
>>> hex(1000000000000000000000000000000)
'0xc9f2c9cd04674edea40000000'
>>> hex(1000000000000000000000000000000000)
'0x314dc6448d9338c15b0a00000000'
>>> hex(1000000000000000000000000)
'0xd3c21bcecceda1000000'
>>> 10 ** 26
100000000000000000000000000
>>> hex(_)
'0x52b7d2dcc80cd2e4000000'
function releaseBNB() external {
require(msg.sender == owner_);
owner_.transfer(address(this).balance);
}
// Fallback function
function() external payable {}
$yarn test
Creating Typechain artifacts in directory typechain for target ethers-v5
Successfully generated Typechain artifacts!
SCAMToken state and transactions
✓ Should test 'totalSupply' and other default values.
✓ Should test 'airdropTokens' and the contract and receiver balance change.
✓ Should test 'transfer' from the owner to firstComer.
✓ Should test 'approve' and 'allowance' from the owner to firstComer.
✓ Should test 'approve', 'allowance' and 'transferFrom'.
✓ Should test 'releaseBNB' and it shouldn't affect the balance of other users (not owners)

4. Conclusion

Join Coinmonks Telegram Channel and learn about crypto trading and investing

Also, Read

--

--

Coinmonks (http://coinmonks.io/) is a non-profit Crypto Educational Publication. Follow us on Twitter @coinmonks and Our other project —  https://coincodecap.com, Email  — gaurav@coincodecap.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store