SimpleToken.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. (await token.name()).should.equal('SimpleToken');
  15. });
  16. it('has a symbol', async function () {
  17. (await token.symbol()).should.equal('SIM');
  18. });
  19. it('has 18 decimals', async function () {
  20. (await token.decimals()).should.be.bignumber.equal(18);
  21. });
  22. it('assigns the initial total supply to the creator', async function () {
  23. const totalSupply = await token.totalSupply();
  24. const creatorBalance = await token.balanceOf(creator);
  25. creatorBalance.should.be.bignumber.equal(totalSupply);
  26. const receipt = await web3.eth.getTransactionReceipt(token.transactionHash);
  27. const logs = decodeLogs(receipt.logs, SimpleToken, token.address);
  28. logs.length.should.equal(1);
  29. logs[0].event.should.equal('Transfer');
  30. logs[0].args.from.valueOf().should.equal(ZERO_ADDRESS);
  31. logs[0].args.to.valueOf().should.equal(creator);
  32. logs[0].args.value.should.be.bignumber.equal(totalSupply);
  33. });
  34. });