From 8181094cb33709b0f9142251a7a5d8bda79b8cca Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 21 Nov 2018 19:20:39 +0000 Subject: [PATCH 1/2] Add transferOwnership to MR --- contracts/ModuleRegistry.sol | 12 ++++++++++++ test/k_module_registry.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/contracts/ModuleRegistry.sol b/contracts/ModuleRegistry.sol index b2f1fbba5..65de42fa6 100644 --- a/contracts/ModuleRegistry.sol +++ b/contracts/ModuleRegistry.sol @@ -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 @@ -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 diff --git a/test/k_module_registry.js b/test/k_module_registry.js index 477ce62d5..6ead1a3cb 100644 --- a/test/k_module_registry.js +++ b/test/k_module_registry.js @@ -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); @@ -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 }) @@ -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 }) @@ -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") ); }); @@ -624,6 +624,28 @@ 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); + }); + }) }); }); }); From 895af2f833b5dd1a01620b5add4962d042257930 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 21 Nov 2018 19:30:55 +0000 Subject: [PATCH 2/2] New test case --- test/k_module_registry.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/k_module_registry.js b/test/k_module_registry.js index 6ead1a3cb..3ec2d0a0d 100644 --- a/test/k_module_registry.js +++ b/test/k_module_registry.js @@ -645,6 +645,13 @@ contract("ModuleRegistry", accounts => { 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); + }); + }) }); });