Skip to content

Commit

Permalink
Add transferOwnership to MR (#425)
Browse files Browse the repository at this point in the history
* Add transferOwnership to MR

* New test case
  • Loading branch information
adamdossa authored Nov 21, 2018
1 parent 4e73466 commit 3439b3d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
12 changes: 12 additions & 0 deletions contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
event ModuleVerified(address indexed _moduleFactory, bool _verified);
// Emit when a ModuleFactory is removed by Polymath
event ModuleRemoved(address indexed _moduleFactory, address indexed _decisionMaker);
// Emit when ownership gets transferred
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

///////////////
//// Modifiers
Expand Down Expand Up @@ -374,6 +376,16 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
set(Encoder.getKey("polyToken"), IPolymathRegistry(_polymathRegistry).getAddress("PolyToken"));
}

/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
require(_newOwner != address(0), "Invalid address");
emit OwnershipTransferred(owner(), _newOwner);
set(Encoder.getKey("owner"), _newOwner);
}

/**
* @notice Gets the owner of the contract
* @return address owner
Expand Down
37 changes: 33 additions & 4 deletions test/k_module_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ contract("ModuleRegistry", accounts => {

let sto1 = (await I_MRProxied.getModulesByType.call(3))[0];
let sto2 = (await I_MRProxied.getModulesByType.call(3))[1];
let sto3 = (await I_MRProxied.getModulesByType.call(3))[2];
let sto3 = (await I_MRProxied.getModulesByType.call(3))[2];
let sto4 = (await I_MRProxied.getModulesByType.call(3))[3];

assert.equal(sto1, I_CappedSTOFactory1.address);
Expand Down Expand Up @@ -542,7 +542,7 @@ contract("ModuleRegistry", accounts => {
I_MRProxied.reclaimERC20("0x000000000000000000000000000000000000000", { from: account_polymath })
);
});

it("Should successfully reclaim POLY tokens -- not authorised", async() => {
catchRevert(
I_MRProxied.reclaimERC20(I_PolyToken.address, { from: account_temp })
Expand Down Expand Up @@ -592,7 +592,7 @@ contract("ModuleRegistry", accounts => {
I_ReclaimERC20.reclaimERC20("0x000000000000000000000000000000000000000", { from: account_polymath })
);
});

it("Should successfully reclaim POLY tokens -- not authorised", async() => {
catchRevert(
I_ReclaimERC20.reclaimERC20(I_PolyToken.address, { from: account_temp })
Expand All @@ -614,7 +614,7 @@ contract("ModuleRegistry", accounts => {
describe("Test case for the PolymathRegistry", async() => {

it("Should successfully get the address -- fail because key is not exist", async() => {
catchRevert(
catchRevert(
I_PolymathRegistry.getAddress("PolyOracle")
);
});
Expand All @@ -624,6 +624,35 @@ contract("ModuleRegistry", accounts => {
assert.equal(_moduleR, I_ModuleRegistryProxy.address);
})
})


describe("Test cases for the transferOwnership", async() => {

it("Should fail to transfer the ownership -- not authorised", async() => {
catchRevert(
I_MRProxied.transferOwnership(account_temp, { from: account_issuer})
);
});

it("Should fail to transfer the ownership -- 0x address is not allowed", async() => {
catchRevert(
I_MRProxied.transferOwnership("0x000000000000000000000000000000000000000", { from: account_polymath})
);
});

it("Should successfully transfer the ownership of the STR", async() => {
let tx = await I_MRProxied.transferOwnership(account_temp, { from: account_polymath });
assert.equal(tx.logs[0].args.previousOwner, account_polymath);
assert.equal(tx.logs[0].args.newOwner, account_temp);
});

it("New owner has authorisation", async() => {
let tx = await I_MRProxied.transferOwnership(account_polymath, { from: account_temp });
assert.equal(tx.logs[0].args.previousOwner, account_temp);
assert.equal(tx.logs[0].args.newOwner, account_polymath);
});

})
});
});
});

0 comments on commit 3439b3d

Please sign in to comment.