BasicToken.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const assertJump = require('./helpers/assertJump');
  2. var BasicTokenMock = artifacts.require("./helpers/BasicTokenMock.sol");
  3. contract('BasicToken', function(accounts) {
  4. it("should return the correct totalSupply after construction", async function() {
  5. let token = await BasicTokenMock.new(accounts[0], 100);
  6. let totalSupply = await token.totalSupply();
  7. assert.equal(totalSupply, 100);
  8. })
  9. it("should return correct balances after transfer", async function(){
  10. let token = await BasicTokenMock.new(accounts[0], 100);
  11. let transfer = await token.transfer(accounts[1], 100);
  12. let firstAccountBalance = await token.balanceOf(accounts[0]);
  13. assert.equal(firstAccountBalance, 0);
  14. let secondAccountBalance = await token.balanceOf(accounts[1]);
  15. assert.equal(secondAccountBalance, 100);
  16. });
  17. it('should throw an error when trying to transfer more than balance', async function() {
  18. let token = await BasicTokenMock.new(accounts[0], 100);
  19. try {
  20. let transfer = await token.transfer(accounts[1], 101);
  21. assert.fail('should have thrown before');
  22. } catch(error) {
  23. assertJump(error);
  24. }
  25. });
  26. it('should throw an error when trying to transfer to 0x0', async function() {
  27. let token = await BasicTokenMock.new(accounts[0], 100);
  28. try {
  29. let transfer = await token.transfer(0x0, 100);
  30. assert.fail('should have thrown before');
  31. } catch(error) {
  32. assertJump(error);
  33. }
  34. });
  35. });