diff --git a/contracts/upgradeable_contracts/BaseFeeManager.sol b/contracts/upgradeable_contracts/BaseFeeManager.sol index 93c462265..258ba2afa 100644 --- a/contracts/upgradeable_contracts/BaseFeeManager.sol +++ b/contracts/upgradeable_contracts/BaseFeeManager.sol @@ -40,6 +40,8 @@ contract BaseFeeManager is EternalStorage { distributeFeeProportionally(_fee, REWARD_FOR_TRANSFERRING_FROM_HOME); } + function getFeeManagerMode() public pure returns(bytes4); + function random(uint256 _count) public view returns(uint256) { return uint256(blockhash(block.number.sub(1))) % _count; } diff --git a/contracts/upgradeable_contracts/RewardableBridge.sol b/contracts/upgradeable_contracts/RewardableBridge.sol index fdae05f6e..0d094acc7 100644 --- a/contracts/upgradeable_contracts/RewardableBridge.sol +++ b/contracts/upgradeable_contracts/RewardableBridge.sol @@ -23,6 +23,20 @@ contract RewardableBridge is Ownable { return fee; } + function getFeeManagerMode() public view returns(bytes4) { + bytes4 mode; + bytes memory callData = abi.encodeWithSignature("getFeeManagerMode()"); + address feeManager = feeManagerContract(); + assembly { + let result := callcode(gas, feeManager, 0x0, add(callData, 0x20), mload(callData), 0, 4) + mode := mload(0) + + switch result + case 0 { revert(0, 0) } + } + return mode; + } + function feeManagerContract() public view returns(address) { return addressStorage[keccak256(abi.encodePacked("feeManagerContract"))]; } diff --git a/contracts/upgradeable_contracts/erc20_to_native/FeeManagerErcToNative.sol b/contracts/upgradeable_contracts/erc20_to_native/FeeManagerErcToNative.sol index 645241a33..be80bdd03 100644 --- a/contracts/upgradeable_contracts/erc20_to_native/FeeManagerErcToNative.sol +++ b/contracts/upgradeable_contracts/erc20_to_native/FeeManagerErcToNative.sol @@ -7,6 +7,10 @@ import "../Sacrifice.sol"; contract FeeManagerErcToNative is BaseFeeManager { + function getFeeManagerMode() public pure returns(bytes4) { + return bytes4(keccak256(abi.encodePacked("manages-both-directions"))); + } + function blockRewardContract() internal view returns(IBlockReward) { return IBlockReward(addressStorage[keccak256(abi.encodePacked("blockRewardContract"))]); } diff --git a/contracts/upgradeable_contracts/native_to_erc20/FeeManagerNativeToErc.sol b/contracts/upgradeable_contracts/native_to_erc20/FeeManagerNativeToErc.sol index d20c1ac96..a1f5b4c4e 100644 --- a/contracts/upgradeable_contracts/native_to_erc20/FeeManagerNativeToErc.sol +++ b/contracts/upgradeable_contracts/native_to_erc20/FeeManagerNativeToErc.sol @@ -7,6 +7,10 @@ import "../Sacrifice.sol"; contract FeeManagerNativeToErc is BaseFeeManager { + function getFeeManagerMode() public pure returns(bytes4) { + return bytes4(keccak256(abi.encodePacked("manages-one-direction"))); + } + function erc677token() public view returns(IBurnableMintableERC677Token) { return IBurnableMintableERC677Token(addressStorage[keccak256(abi.encodePacked("erc677token"))]); } diff --git a/test/erc_to_native/home_bridge.test.js b/test/erc_to_native/home_bridge.test.js index 429d9eec2..73a4c5270 100644 --- a/test/erc_to_native/home_bridge.test.js +++ b/test/erc_to_native/home_bridge.test.js @@ -917,6 +917,18 @@ contract('HomeBridge_ERC20_to_Native', async (accounts) => { const bridgeFee = await homeBridge.getFee() bridgeFee.should.be.bignumber.equal(fee) }) + it('should be able to get fee manager mode', async () => { + // Given + const feeManager = await FeeManagerErcToNative.new() + const bothDirectionsModeHash = '0xd7de965f' + + // When + await homeBridge.setFeeManagerContract(feeManager.address, { from: owner }).should.be.fulfilled + + // Then + const feeManagerMode = await homeBridge.getFeeManagerMode() + feeManagerMode.should.be.equals(bothDirectionsModeHash) + }) }) describe('#feeManager_ExecuteAffirmation', async () => { it('should distribute fee to validator', async () => { diff --git a/test/native_to_erc/foreign_bridge_test.js b/test/native_to_erc/foreign_bridge_test.js index 747957925..d570a0737 100644 --- a/test/native_to_erc/foreign_bridge_test.js +++ b/test/native_to_erc/foreign_bridge_test.js @@ -590,6 +590,19 @@ contract('ForeignBridge', async (accounts) => { const bridgeFee = await foreignBridge.getFee() bridgeFee.should.be.bignumber.equal(newFee) }) + + it('should be able to get fee manager mode', async () => { + // Given + const feeManager = await FeeManagerNativeToErc.new() + const oneDirectionsModeHash = '0xf2aed8f7' + + // When + await foreignBridge.rewardableInitialize(rewardableValidators.address, token.address, oneEther, halfEther, minPerTx, gasPrice, requireBlockConfirmations, homeDailyLimit, homeMaxPerTx, owner, feeManager.address, fee).should.be.fulfilled; + + // Then + const feeManagerMode = await foreignBridge.getFeeManagerMode() + feeManagerMode.should.be.equals(oneDirectionsModeHash) + }) }) describe('#RewardableBridge_executeSignatures', async () => { diff --git a/test/native_to_erc/home_bridge_test.js b/test/native_to_erc/home_bridge_test.js index 2a798aff8..84323ca29 100644 --- a/test/native_to_erc/home_bridge_test.js +++ b/test/native_to_erc/home_bridge_test.js @@ -631,6 +631,18 @@ contract('HomeBridge', async (accounts) => { const bridgeFee = await homeBridge.getFee() bridgeFee.should.be.bignumber.equal(newFee) }) + it('should be able to get fee manager mode', async () => { + // Given + const feeManager = await FeeManagerNativeToErc.new() + const oneDirectionsModeHash = '0xf2aed8f7' + + // When + await homeBridge.rewardableInitialize(rewardableValidators.address, oneEther, halfEther, minPerTx, gasPrice, requireBlockConfirmations, foreignDailyLimit, foreignMaxPerTx, owner, feeManager.address, fee).should.be.fulfilled; + + // Then + const feeManagerMode = await homeBridge.getFeeManagerMode() + feeManagerMode.should.be.equals(oneDirectionsModeHash) + }) }) describe('#feeManager_ExecuteAffirmation', async () => {