StandardToken.js 2.3 KB

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