-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clement Balestrat
committed
Dec 4, 2018
1 parent
003f89b
commit 00e2384
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |