CanReclaimToken.js 1.3 KB

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