SimpleToken.test.js 1.4 KB

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