StandardToken.js 2.3 KB

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