StandardToken.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. contract('StandardToken', function(accounts) {
  2. it("should return the correct totalSupply after construction", function(done) {
  3. return StandardTokenMock.new(accounts[0], 100)
  4. .then(function(token) {
  5. return token.totalSupply();
  6. })
  7. .then(function(totalSupply) {
  8. assert.equal(totalSupply, 100);
  9. })
  10. .then(done);
  11. })
  12. it("should return the correct allowance amount after approval", function(done) {
  13. var token;
  14. return StandardTokenMock.new()
  15. .then(function(_token) {
  16. token = _token;
  17. return token.approve(accounts[1], 100);
  18. })
  19. .then(function() {
  20. return token.allowance(accounts[0], accounts[1]);
  21. })
  22. .then(function(allowance) {
  23. assert.equal(allowance, 100);
  24. })
  25. .then(done);
  26. });
  27. it("should return correct balances after transfer", function(done) {
  28. var token;
  29. return StandardTokenMock.new(accounts[0], 100)
  30. .then(function(_token) {
  31. token = _token;
  32. return token.transfer(accounts[1], 100);
  33. })
  34. .then(function() {
  35. return token.balanceOf(accounts[0]);
  36. })
  37. .then(function(balance) {
  38. assert.equal(balance, 0);
  39. })
  40. .then(function() {
  41. return token.balanceOf(accounts[1]);
  42. })
  43. .then(function(balance) {
  44. assert.equal(balance, 100);
  45. })
  46. .then(done);
  47. });
  48. it("should throw an error when trying to transfer more than balance", function(done) {
  49. var token;
  50. return StandardTokenMock.new(accounts[0], 100)
  51. .then(function(_token) {
  52. token = _token;
  53. return token.transfer(accounts[1], 101);
  54. })
  55. .catch(function(error) {
  56. if (error.message.search('invalid JUMP') == -1) throw error
  57. })
  58. .then(done);
  59. });
  60. it("should return correct balances after transfering from another account", function(done) {
  61. var token;
  62. return StandardTokenMock.new(accounts[0], 100)
  63. .then(function(_token) {
  64. token = _token;
  65. return token.approve(accounts[1], 100);
  66. })
  67. .then(function() {
  68. return token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  69. })
  70. .then(function() {
  71. return token.balanceOf(accounts[0]);
  72. })
  73. .then(function(balance) {
  74. assert.equal(balance, 0);
  75. return token.balanceOf(accounts[2]);
  76. })
  77. .then(function(balance) {
  78. assert.equal(balance, 100)
  79. return token.balanceOf(accounts[1]);
  80. })
  81. .then(function(balance) {
  82. assert.equal(balance, 0);
  83. })
  84. .then(done);
  85. });
  86. it("should throw an error when trying to transfer more than allowed", function(done) {
  87. var token;
  88. return StandardTokenMock.new(accounts[0], 100)
  89. .then(function(_token) {
  90. token = _token;
  91. return token.approve(accounts[1], 99);
  92. })
  93. .then(function() {
  94. return token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
  95. })
  96. .catch(function(error) {
  97. if (error.message.search('invalid JUMP') == -1) throw error
  98. })
  99. .then(done);
  100. });
  101. });