From 339bd4ab0411b83f093af33d1d6a00a39af79654 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Fri, 12 Oct 2018 10:56:13 -0300 Subject: [PATCH] Add bridgesAllowedLength method check on setBlockRewardContract --- contracts/IBlockReward.sol | 1 + contracts/test/BlockReward.sol | 4 ++++ .../erc20_to_native/HomeBridgeErcToNative.sol | 2 +- test/erc_to_native/home_bridge.test.js | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/IBlockReward.sol b/contracts/IBlockReward.sol index dfff214a3..2d9e1b89a 100644 --- a/contracts/IBlockReward.sol +++ b/contracts/IBlockReward.sol @@ -5,4 +5,5 @@ interface IBlockReward { function addExtraReceiver(uint256 _amount, address _receiver) external; function mintedTotally() public view returns (uint256); function mintedTotallyByBridge(address _bridge) public view returns(uint256); + function bridgesAllowedLength() external view returns(uint256); } diff --git a/contracts/test/BlockReward.sol b/contracts/test/BlockReward.sol index 70ebb2f95..ea5c4cfa9 100644 --- a/contracts/test/BlockReward.sol +++ b/contracts/test/BlockReward.sol @@ -14,6 +14,10 @@ contract BlockReward is IBlockReward { function () external payable { } + function bridgesAllowedLength() external view returns(uint256) { + return 3; + } + function addExtraReceiver(uint256 _amount, address _receiver) external { require(_amount > 0); require(_receiver != address(0)); diff --git a/contracts/upgradeable_contracts/erc20_to_native/HomeBridgeErcToNative.sol b/contracts/upgradeable_contracts/erc20_to_native/HomeBridgeErcToNative.sol index 463f4dfcc..7fc21aa37 100644 --- a/contracts/upgradeable_contracts/erc20_to_native/HomeBridgeErcToNative.sol +++ b/contracts/upgradeable_contracts/erc20_to_native/HomeBridgeErcToNative.sol @@ -66,7 +66,7 @@ contract HomeBridgeErcToNative is EternalStorage, BasicBridge, BasicHomeBridge { } function setBlockRewardContract(address _blockReward) public onlyOwner { - require(_blockReward != address(0) && isContract(_blockReward)); + require(_blockReward != address(0) && isContract(_blockReward) && (IBlockReward(_blockReward).bridgesAllowedLength() != 0)); addressStorage[keccak256(abi.encodePacked("blockRewardContract"))] = _blockReward; } diff --git a/test/erc_to_native/home_bridge.test.js b/test/erc_to_native/home_bridge.test.js index 1abf2d983..e6f20512b 100644 --- a/test/erc_to_native/home_bridge.test.js +++ b/test/erc_to_native/home_bridge.test.js @@ -71,6 +71,9 @@ contract('HomeBridge_ERC20_to_Native', async (accounts) => { const notAContract = accounts[5] await homeContract.setBlockRewardContract(notAContract).should.be.rejectedWith(ERROR_MSG) secondBlockRewardContract.address.should.be.equal(await homeContract.blockRewardContract()) + + await homeContract.setBlockRewardContract(validatorContract.address).should.be.rejectedWith(ERROR_MSG) + secondBlockRewardContract.address.should.be.equal(await homeContract.blockRewardContract()) }) it('cant set maxPerTx > dailyLimit', async () => {