BasicToken.test.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import assertRevert from '../../helpers/assertRevert';
  2. const BasicToken = artifacts.require('BasicTokenMock');
  3. contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
  4. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  5. beforeEach(async function () {
  6. this.token = await BasicToken.new(owner, 100);
  7. });
  8. describe('total supply', function () {
  9. it('returns the total amount of tokens', async function () {
  10. const totalSupply = await this.token.totalSupply();
  11. assert.equal(totalSupply, 100);
  12. });
  13. });
  14. describe('balanceOf', function () {
  15. describe('when the requested account has no tokens', function () {
  16. it('returns zero', async function () {
  17. const balance = await this.token.balanceOf(anotherAccount);
  18. assert.equal(balance, 0);
  19. });
  20. });
  21. describe('when the requested account has some tokens', function () {
  22. it('returns the total amount of tokens', async function () {
  23. const balance = await this.token.balanceOf(owner);
  24. assert.equal(balance, 100);
  25. });
  26. });
  27. });
  28. describe('transfer', function () {
  29. describe('when the recipient is not the zero address', function () {
  30. const to = recipient;
  31. describe('when the sender does not have enough balance', function () {
  32. const amount = 101;
  33. it('reverts', async function () {
  34. await assertRevert(this.token.transfer(to, amount, { from: owner }));
  35. });
  36. });
  37. describe('when the sender has enough balance', function () {
  38. const amount = 100;
  39. it('transfers the requested amount', async function () {
  40. await this.token.transfer(to, amount, { from: owner });
  41. const senderBalance = await this.token.balanceOf(owner);
  42. assert.equal(senderBalance, 0);
  43. const recipientBalance = await this.token.balanceOf(to);
  44. assert.equal(recipientBalance, amount);
  45. });
  46. it('emits a transfer event', async function () {
  47. const { logs } = await this.token.transfer(to, amount, { from: owner });
  48. assert.equal(logs.length, 1);
  49. assert.equal(logs[0].event, 'Transfer');
  50. assert.equal(logs[0].args.from, owner);
  51. assert.equal(logs[0].args.to, to);
  52. assert(logs[0].args.value.eq(amount));
  53. });
  54. });
  55. });
  56. describe('when the recipient is the zero address', function () {
  57. const to = ZERO_ADDRESS;
  58. it('reverts', async function () {
  59. await assertRevert(this.token.transfer(to, 100, { from: owner }));
  60. });
  61. });
  62. });
  63. });