CanReclaimToken.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const { expectThrow } = require('../helpers/expectThrow');
  2. const CanReclaimToken = artifacts.require('CanReclaimToken');
  3. const StandardTokenMock = artifacts.require('StandardTokenMock');
  4. contract('CanReclaimToken', function ([_, owner, anyone]) {
  5. let token = null;
  6. let canReclaimToken = null;
  7. beforeEach(async function () {
  8. // Create contract and token
  9. token = await StandardTokenMock.new(owner, 100, { from: owner });
  10. canReclaimToken = await CanReclaimToken.new({ from: owner });
  11. // Force token into contract
  12. await token.transfer(canReclaimToken.address, 10, { from: owner });
  13. const startBalance = await token.balanceOf(canReclaimToken.address);
  14. assert.equal(startBalance, 10);
  15. });
  16. it('should allow owner to reclaim tokens', async function () {
  17. const ownerStartBalance = await token.balanceOf(owner);
  18. await canReclaimToken.reclaimToken(token.address, { from: owner });
  19. const ownerFinalBalance = await token.balanceOf(owner);
  20. const finalBalance = await token.balanceOf(canReclaimToken.address);
  21. assert.equal(finalBalance, 0);
  22. assert.equal(ownerFinalBalance - ownerStartBalance, 10);
  23. });
  24. it('should allow only owner to reclaim tokens', async function () {
  25. await expectThrow(
  26. canReclaimToken.reclaimToken(token.address, { from: anyone })
  27. );
  28. });
  29. });