From 5d67571a8e217d22b425ae009866fb48866f09c6 Mon Sep 17 00:00:00 2001 From: satyam Date: Mon, 27 May 2019 07:58:33 +0530 Subject: [PATCH] Fix setProtocolFactory() --- contracts/SecurityTokenRegistry.sol | 2 ++ test/n_security_token_registry.js | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/contracts/SecurityTokenRegistry.sol b/contracts/SecurityTokenRegistry.sol index f16baab30..cac8fcf2f 100644 --- a/contracts/SecurityTokenRegistry.sol +++ b/contracts/SecurityTokenRegistry.sol @@ -831,6 +831,8 @@ contract SecurityTokenRegistry is EternalStorage, Proxy { function _setProtocolFactory(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) internal { require(_STFactoryAddress != address(0), "Bad address"); uint24 _packedVersion = VersionUtils.pack(_major, _minor, _patch); + address stFactoryAddress = getAddressValue(Encoder.getKey("protocolVersionST", uint256(_packedVersion))); + require(stFactoryAddress == address(0), "Already exists"); set(Encoder.getKey("protocolVersionST", uint256(_packedVersion)), _STFactoryAddress); emit ProtocolFactorySet(_STFactoryAddress, _major, _minor, _patch); } diff --git a/test/n_security_token_registry.js b/test/n_security_token_registry.js index 2629f098c..2ac076d6c 100644 --- a/test/n_security_token_registry.js +++ b/test/n_security_token_registry.js @@ -684,7 +684,10 @@ contract("SecurityTokenRegistry", async (accounts) => { assert.equal(_protocol[0], 2); assert.equal(_protocol[1], 2); assert.equal(_protocol[2], 0); - await I_STRProxied.setProtocolFactory(I_STFactory.address, new BN(3), new BN(0), new BN(0), { from: account_polymath}); + await catchRevert( + I_STRProxied.setProtocolFactory(I_STFactory.address, new BN(3), new BN(0), new BN(0), { from: account_polymath}) + ); + await I_STRProxied.setProtocolFactory(I_STFactory.address, new BN(3), new BN(0), new BN(1), { from: account_polymath}); await I_STRProxied.setLatestVersion(new BN(3), new BN(0), new BN(0), { from: account_polymath}); _protocol = await I_Getter.getLatestProtocolVersion.call(); assert.equal(_protocol[0], 3);