CanReclaimToken.test.js 1.4 KB

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