StandardToken.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. contract('StandardToken', function(accounts) {
  2. it("should return the correct totalSupply after construction", async function(done) {
  3. let token = await StandardTokenMock.new(accounts[0], 100);
  4. let totalSupply = await token.totalSupply();
  5. assert.equal(totalSupply, 100);
  6. done();
  7. })
  8. it("should return the correct allowance amount after approval", async function(done) {
  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. done();
  14. });
  15. it("should return correct balances after transfer", async function(done) {
  16. let token = await StandardTokenMock.new(accounts[0], 100);
  17. let transfer = await token.transfer(accounts[1], 100);
  18. let balance0 = await token.balanceOf(accounts[0]);
  19. assert.equal(balance0, 0);
  20. let balance1 = await token.balanceOf(accounts[1]);
  21. assert.equal(balance1, 100);
  22. done();
  23. });
  24. it("should throw an error when trying to transfer more than balance", async function(done) {
  25. let token = await StandardTokenMock.new(accounts[0], 100);
  26. try {
  27. let transfer = await token.transfer(accounts[1], 101);
  28. } catch(error) {
  29. if (error.message.search('invalid JUMP') == -1) throw error
  30. assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
  31. done();
  32. }
  33. });
  34. it("should return correct balances after transfering from another account", async function(done) {
  35. let token = await StandardTokenMock.new(accounts[0], 100);
  36. let approve = await token.approve(accounts[1], 100);
  37. let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  38. let balance0 = await token.balanceOf(accounts[0]);
  39. assert.equal(balance0, 0);
  40. let balance1 = await token.balanceOf(accounts[2]);
  41. assert.equal(balance1, 100);
  42. let balance2 = await token.balanceOf(accounts[1]);
  43. assert.equal(balance2, 0);
  44. done();
  45. });
  46. it("should throw an error when trying to transfer more than allowed", async function(done) {
  47. let token = await StandardTokenMock.new();
  48. let approve = await token.approve(accounts[1], 99);
  49. try {
  50. let transfer = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  51. } catch (error) {
  52. if (error.message.search('invalid JUMP') == -1) throw error
  53. assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
  54. done();
  55. }
  56. });
  57. });