forked from OpenZeppelin/openzeppelin-contracts
-
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.
- Loading branch information
Remco Bloemen
committed
Mar 23, 2017
1 parent
94d3c44
commit 166a107
Showing
2 changed files
with
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pragma solidity ^0.4.8; | ||
|
||
import "./Ownable.sol"; | ||
|
||
/// @title Contracts that should not own Contracts | ||
/// @author Remco Bloemen <remco@2π.com> | ||
/// | ||
/// Should contracts (anything Ownable) end up being owned by | ||
/// this contract, it allows the owner of this contract to | ||
/// reclaim ownership of the contracts. | ||
contract HasNoContracts is Ownable { | ||
|
||
/// Reclaim ownership of Ownable contracts | ||
function reclaimContract(address contractAddr) external onlyOwner { | ||
Ownable contractInst = Ownable(contractAddr); | ||
contractInst.transferOwnership(owner); | ||
} | ||
} |
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,35 @@ | ||
'use strict'; | ||
import expectThrow from './helpers/expectThrow'; | ||
import toPromise from './helpers/toPromise'; | ||
const Ownable = artifacts.require('../contracts/ownership/Ownable.sol'); | ||
const HasNoContracts = artifacts.require( | ||
'../contracts/ownership/HasNoContracts.sol', | ||
); | ||
|
||
contract('HasNoContracts', function(accounts) { | ||
let hasNoContracts = null; | ||
let ownable = null; | ||
|
||
beforeEach(async () => { | ||
// Create contract and token | ||
hasNoContracts = await HasNoContracts.new(); | ||
ownable = await Ownable.new(); | ||
|
||
// Force ownership into contract | ||
await ownable.transferOwnership(hasNoContracts.address); | ||
const owner = await ownable.owner(); | ||
assert.equal(owner, hasNoContracts.address); | ||
}); | ||
|
||
it('should allow owner to reclaim contracts', async function() { | ||
await hasNoContracts.reclaimContract(ownable.address); | ||
const owner = await ownable.owner(); | ||
assert.equal(owner, accounts[0]); | ||
}); | ||
|
||
it('should allow only owner to reclaim contracts', async function() { | ||
await expectThrow( | ||
hasNoContracts.reclaimContract(ownable.address, {from: accounts[1]}), | ||
); | ||
}); | ||
}); |