Skip to content

Commit 3439b3d

Browse files
authored
Add transferOwnership to MR (#425)
* Add transferOwnership to MR * New test case
1 parent 4e73466 commit 3439b3d

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

contracts/ModuleRegistry.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
5151
event ModuleVerified(address indexed _moduleFactory, bool _verified);
5252
// Emit when a ModuleFactory is removed by Polymath
5353
event ModuleRemoved(address indexed _moduleFactory, address indexed _decisionMaker);
54+
// Emit when ownership gets transferred
55+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
5456

5557
///////////////
5658
//// Modifiers
@@ -374,6 +376,16 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
374376
set(Encoder.getKey("polyToken"), IPolymathRegistry(_polymathRegistry).getAddress("PolyToken"));
375377
}
376378

379+
/**
380+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
381+
* @param _newOwner The address to transfer ownership to.
382+
*/
383+
function transferOwnership(address _newOwner) external onlyOwner {
384+
require(_newOwner != address(0), "Invalid address");
385+
emit OwnershipTransferred(owner(), _newOwner);
386+
set(Encoder.getKey("owner"), _newOwner);
387+
}
388+
377389
/**
378390
* @notice Gets the owner of the contract
379391
* @return address owner

test/k_module_registry.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ contract("ModuleRegistry", accounts => {
479479

480480
let sto1 = (await I_MRProxied.getModulesByType.call(3))[0];
481481
let sto2 = (await I_MRProxied.getModulesByType.call(3))[1];
482-
let sto3 = (await I_MRProxied.getModulesByType.call(3))[2];
482+
let sto3 = (await I_MRProxied.getModulesByType.call(3))[2];
483483
let sto4 = (await I_MRProxied.getModulesByType.call(3))[3];
484484

485485
assert.equal(sto1, I_CappedSTOFactory1.address);
@@ -542,7 +542,7 @@ contract("ModuleRegistry", accounts => {
542542
I_MRProxied.reclaimERC20("0x000000000000000000000000000000000000000", { from: account_polymath })
543543
);
544544
});
545-
545+
546546
it("Should successfully reclaim POLY tokens -- not authorised", async() => {
547547
catchRevert(
548548
I_MRProxied.reclaimERC20(I_PolyToken.address, { from: account_temp })
@@ -592,7 +592,7 @@ contract("ModuleRegistry", accounts => {
592592
I_ReclaimERC20.reclaimERC20("0x000000000000000000000000000000000000000", { from: account_polymath })
593593
);
594594
});
595-
595+
596596
it("Should successfully reclaim POLY tokens -- not authorised", async() => {
597597
catchRevert(
598598
I_ReclaimERC20.reclaimERC20(I_PolyToken.address, { from: account_temp })
@@ -614,7 +614,7 @@ contract("ModuleRegistry", accounts => {
614614
describe("Test case for the PolymathRegistry", async() => {
615615

616616
it("Should successfully get the address -- fail because key is not exist", async() => {
617-
catchRevert(
617+
catchRevert(
618618
I_PolymathRegistry.getAddress("PolyOracle")
619619
);
620620
});
@@ -624,6 +624,35 @@ contract("ModuleRegistry", accounts => {
624624
assert.equal(_moduleR, I_ModuleRegistryProxy.address);
625625
})
626626
})
627+
628+
629+
describe("Test cases for the transferOwnership", async() => {
630+
631+
it("Should fail to transfer the ownership -- not authorised", async() => {
632+
catchRevert(
633+
I_MRProxied.transferOwnership(account_temp, { from: account_issuer})
634+
);
635+
});
636+
637+
it("Should fail to transfer the ownership -- 0x address is not allowed", async() => {
638+
catchRevert(
639+
I_MRProxied.transferOwnership("0x000000000000000000000000000000000000000", { from: account_polymath})
640+
);
641+
});
642+
643+
it("Should successfully transfer the ownership of the STR", async() => {
644+
let tx = await I_MRProxied.transferOwnership(account_temp, { from: account_polymath });
645+
assert.equal(tx.logs[0].args.previousOwner, account_polymath);
646+
assert.equal(tx.logs[0].args.newOwner, account_temp);
647+
});
648+
649+
it("New owner has authorisation", async() => {
650+
let tx = await I_MRProxied.transferOwnership(account_polymath, { from: account_temp });
651+
assert.equal(tx.logs[0].args.previousOwner, account_temp);
652+
assert.equal(tx.logs[0].args.newOwner, account_polymath);
653+
});
654+
655+
})
627656
});
628657
});
629658
});

0 commit comments

Comments
 (0)