StandardToken.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const assertJump = require('./helpers/assertJump');
  2. contract('StandardToken', function(accounts) {
  3. it("should return the correct totalSupply after construction", async function() {
  4. let token = await StandardTokenMock.new(accounts[0], 100);
  5. let totalSupply = await token.totalSupply();
  6. assert.equal(totalSupply, 100);
  7. })
  8. it("should return the correct allowance amount after approval", async function() {
  9. let token = await StandardTokenMock.new();
  10. let approve = await token.approve(accounts[1], 100);
  11. let allowance = await token.allowance(accounts[0], accounts[1]);
  12. assert.equal(allowance, 100);
  13. });
  14. it("should return correct balances after transfer", async function() {
  15. let token = await StandardTokenMock.new(accounts[0], 100);
  16. let transfer = await token.transfer(accounts[1], 100);
  17. let balance0 = await token.balanceOf(accounts[0]);
  18. assert.equal(balance0, 0);
  19. let balance1 = await token.balanceOf(accounts[1]);
  20. assert.equal(balance1, 100);
  21. });
  22. it("should throw an error when trying to transfer more than balance", async function() {
  23. let token = await StandardTokenMock.new(accounts[0], 100);
  24. try {
  25. let transfer = await token.transfer(accounts[1], 101);
  26. } catch(error) {
  27. return assertJump(error);
  28. }
  29. assert.fail('should have thrown before');
  30. });
  31. it("should return correct balances after transfering from another account", async function() {
  32. let token = await StandardTokenMock.new(accounts[0], 100);
  33. let approve = await token.approve(accounts[1], 100);
  34. let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  35. let balance0 = await token.balanceOf(accounts[0]);
  36. assert.equal(balance0, 0);
  37. let balance1 = await token.balanceOf(accounts[2]);
  38. assert.equal(balance1, 100);
  39. let balance2 = await token.balanceOf(accounts[1]);
  40. assert.equal(balance2, 0);
  41. });
  42. it("should throw an error when trying to transfer more than allowed", async function() {
  43. let token = await StandardTokenMock.new();
  44. let approve = await token.approve(accounts[1], 99);
  45. try {
  46. let transfer = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  47. } catch (error) {
  48. return assertJump(error);
  49. }
  50. assert.fail('should have thrown before');
  51. });
  52. });