Skip to content

Commit

Permalink
SelfDestructible test added
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Balestrat committed Dec 4, 2018
1 parent 003f89b commit 00e2384
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions migrations/2_deploy_synthetix_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PublicSafeDecimalMath = artifacts.require('PublicSafeDecimalMath');
const SafeDecimalMath = artifacts.require('SafeDecimalMath');
const TokenState = artifacts.require('TokenState');
const Depot = artifacts.require('Depot');
const SelfDestructible = artifacts.require('SelfDestructible');

// Update values before deployment
const ZERO_ADDRESS = '0x' + '0'.repeat(40);
Expand Down Expand Up @@ -242,6 +243,12 @@ module.exports = async function(deployer, network, accounts) {
{ from: deployerAccount }
);

// ----------------
// Self Destructible
// ----------------
console.log('Deploying SelfDestructible...');
await deployer.deploy(SelfDestructible, owner, { from: deployerAccount });

const tableData = [
['Contract', 'Address'],
['Exchange Rates', ExchangeRates.address],
Expand All @@ -255,6 +262,7 @@ module.exports = async function(deployer, network, accounts) {
['Depot', Depot.address],
['Owned', Owned.address],
['SafeDecimalMath', SafeDecimalMath.address],
['SelfDestructible', SelfDestructible.address],
];

for (const synth of synths) {
Expand Down
29 changes: 29 additions & 0 deletions test/SelfDestructible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const SelfDestructible = artifacts.require('SelfDestructible');

const { fastForward } = require('../utils/testUtils');

contract('SelfDestructible', async function(accounts) {
const [, owner] = accounts;
let selfDestructible;
const SELFDESTRUCT_DELAY = 2419200;

beforeEach(async function() {
selfDestructible = await SelfDestructible.deployed();
});
it('should only be terminated after we reach the SELFDESTRUCT_DELAY', async function() {
// We initiate the self destruction of the contract
await selfDestructible.initiateSelfDestruct({ from: owner });

// Self destruct should revert as delay has not yet elapsed
await assert.revert(selfDestructible.selfDestruct({ from: owner }));

// We fast forward to reach the delay
await fastForward(SELFDESTRUCT_DELAY + 1);

// Self destruct should now work and emit the correct event
const transaction = await selfDestructible.selfDestruct({ from: owner });
assert.eventEqual(transaction, 'SelfDestructed', {
beneficiary: owner,
});
});
});

0 comments on commit 00e2384

Please sign in to comment.