TokenDestructible.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const { ethGetBalance } = require('../helpers/web3');
  2. const TokenDestructible = artifacts.require('TokenDestructible');
  3. const StandardTokenMock = artifacts.require('StandardTokenMock');
  4. contract('TokenDestructible', function ([_, owner]) {
  5. let tokenDestructible;
  6. beforeEach(async function () {
  7. tokenDestructible = await TokenDestructible.new({
  8. from: owner,
  9. value: web3.toWei('10', 'ether'),
  10. });
  11. });
  12. it('should send balance to owner after destruction', async function () {
  13. const initBalance = await ethGetBalance(owner);
  14. await tokenDestructible.destroy([], { from: owner });
  15. const newBalance = await ethGetBalance(owner);
  16. assert.isTrue(newBalance > initBalance);
  17. });
  18. it('should send tokens to owner after destruction', async function () {
  19. const token = await StandardTokenMock.new(tokenDestructible.address, 100);
  20. const initContractBalance = await token.balanceOf(tokenDestructible.address);
  21. const initOwnerBalance = await token.balanceOf(owner);
  22. assert.equal(initContractBalance, 100);
  23. assert.equal(initOwnerBalance, 0);
  24. await tokenDestructible.destroy([token.address], { from: owner });
  25. const newContractBalance = await token.balanceOf(tokenDestructible.address);
  26. const newOwnerBalance = await token.balanceOf(owner);
  27. assert.equal(newContractBalance, 0);
  28. assert.equal(newOwnerBalance, 100);
  29. });
  30. });