Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transferOwnership to MR #425

Merged
merged 2 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});

})
});
});
});