SimpleToken.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const { decodeLogs } = require('../helpers/decodeLogs');
  2. const SimpleToken = artifacts.require('SimpleToken');
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. contract('SimpleToken', function ([_, creator]) {
  8. let token;
  9. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  10. beforeEach(async function () {
  11. token = await SimpleToken.new({ from: creator });
  12. });
  13. it('has a name', async function () {
  14. const name = await token.name();
  15. name.should.eq('SimpleToken');
  16. });
  17. it('has a symbol', async function () {
  18. const symbol = await token.symbol();
  19. symbol.should.eq('SIM');
  20. });
  21. it('has 18 decimals', async function () {
  22. const decimals = await token.decimals();
  23. decimals.should.be.bignumber.equal(18);
  24. });
  25. it('assigns the initial total supply to the creator', async function () {
  26. const totalSupply = await token.totalSupply();
  27. const creatorBalance = await token.balanceOf(creator);
  28. creatorBalance.should.be.bignumber.equal(totalSupply);
  29. const receipt = await web3.eth.getTransactionReceipt(token.transactionHash);
  30. const logs = decodeLogs(receipt.logs, SimpleToken, token.address);
  31. logs.length.should.eq(1);
  32. logs[0].event.should.equal('Transfer');
  33. logs[0].args.from.valueOf().should.equal(ZERO_ADDRESS);
  34. logs[0].args.to.valueOf().should.equal(creator);
  35. logs[0].args.value.should.be.bignumber.equal(totalSupply);
  36. });
  37. });