This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ownable contract to allow for renouncement of ownership. Also added testing files for the contract so that we can ensure they are working as expected. Added assertThrow testing helpers for ownable testing files.
- Loading branch information
Chris Purta
committed
May 4, 2018
1 parent
1ea31fa
commit 875c696
Showing
3 changed files
with
48 additions
and
12 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
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 |
---|---|---|
@@ -1,51 +1,57 @@ | ||
const { assertRevert } = require('../helpers/assertThrow'); | ||
|
||
var Ownable = artifacts.require('Ownable'); | ||
const Ownable = artifacts.require('Ownable'); | ||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; | ||
|
||
contract('Ownable', function (accounts) { | ||
contract('Ownable', accounts => { | ||
let ownable; | ||
|
||
beforeEach(async function () { | ||
beforeEach(async () => { | ||
ownable = await Ownable.new(); | ||
}); | ||
|
||
it('should have an owner', async function () { | ||
it('should have an owner', async () => { | ||
let owner = await ownable.owner(); | ||
assert.isTrue(owner !== 0); | ||
}); | ||
|
||
it('changes owner after transfer', async function () { | ||
it('changes owner after transfer', async () => { | ||
let other = accounts[1]; | ||
await ownable.transferOwnership(other); | ||
let owner = await ownable.owner(); | ||
|
||
assert.isTrue(owner === other); | ||
}); | ||
|
||
it('should prevent non-owners from transfering', async function () { | ||
it('should prevent non-owners from transfering', async () => { | ||
const other = accounts[2]; | ||
const owner = await ownable.owner.call(); | ||
assert.isTrue(owner !== other); | ||
await assertRevert(ownable.transferOwnership(other, { from: other })); | ||
return assertRevert( async () => { | ||
await ownable.transferOwnership(other, { from: other }) | ||
}); | ||
}); | ||
|
||
it('should guard ownership against stuck state', async function () { | ||
it('should guard ownership against stuck state', async () => { | ||
let originalOwner = await ownable.owner(); | ||
await assertRevert(ownable.transferOwnership(null, { from: originalOwner })); | ||
return assertRevert( async () => { | ||
await ownable.transferOwnership(null, { from: originalOwner }) | ||
}); | ||
}); | ||
|
||
it('loses owner after renouncement', async function () { | ||
it('loses owner after renouncement', async () => { | ||
await ownable.renounceOwnership(); | ||
let owner = await ownable.owner(); | ||
|
||
assert.isTrue(owner === ZERO_ADDRESS); | ||
}); | ||
|
||
it('should prevent non-owners from renouncement', async function () { | ||
it('should prevent non-owners from renouncement', async () => { | ||
const other = accounts[2]; | ||
const owner = await ownable.owner.call(); | ||
assert.isTrue(owner !== other); | ||
await assertRevert(ownable.renounceOwnership({ from: other })); | ||
return assertRevert( async () => { | ||
await ownable.renounceOwnership({ from: other }) | ||
}); | ||
}); | ||
}); |