Skip to content

Commit

Permalink
Fix random method visibility in BaseFeeManager (#246)
Browse files Browse the repository at this point in the history
* Reduce random visibility
* Add FeeManagerMock to test random method
* Fix lint:sol:prettier:fix npm script
  • Loading branch information
patitonar authored and akolotov committed Jul 25, 2019
1 parent 8a5d652 commit b66a678
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
21 changes: 21 additions & 0 deletions contracts/test/FeeManagerMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pragma solidity 0.4.24;

import "../upgradeable_contracts/BaseFeeManager.sol";

contract FeeManagerMock is BaseFeeManager {
function distributeFeeFromAffirmation(uint256 _fee) external {
// solhint-disable-previous-line no-empty-blocks
}

function distributeFeeFromSignatures(uint256 _fee) external {
// solhint-disable-previous-line no-empty-blocks
}

function getFeeManagerMode() external pure returns (bytes4) {
return bytes4(keccak256(abi.encodePacked("manages-one-direction")));
}

function randomTest(uint256 _count) external view returns (uint256) {
return super.random(_count);
}
}
2 changes: 1 addition & 1 deletion contracts/upgradeable_contracts/BaseFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract BaseFeeManager is EternalStorage, FeeTypes {

function getFeeManagerMode() external pure returns (bytes4);

function random(uint256 _count) public view returns (uint256) {
function random(uint256 _count) internal view returns (uint256) {
return uint256(blockhash(block.number.sub(1))) % _count;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint:js": "eslint .",
"lint:js:fix": "eslint . --fix",
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
"lint:sol:prettier:fix": "prettier --write **/*.sol",
"lint:sol:prettier:fix": "prettier --write \"contracts/**/*.sol\"",
"watch-tests": "./node_modules/.bin/nodemon ./node_modules/.bin/truffle test --network test",
"coverage": "SOLIDITY_COVERAGE=true scripts/test.sh"
},
Expand Down
5 changes: 3 additions & 2 deletions test/erc_to_native/home_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const OldBlockReward = artifacts.require('oldBlockReward')
const RewardableValidators = artifacts.require('RewardableValidators.sol')
const FeeManagerErcToNative = artifacts.require('FeeManagerErcToNative.sol')
const FeeManagerErcToNativePOSDAO = artifacts.require('FeeManagerErcToNativePOSDAO')
const FeeManagerMock = artifacts.require('FeeManagerMock')

const { expect } = require('chai')
const { ERROR_MSG, ZERO_ADDRESS, toBN } = require('../setup')
Expand Down Expand Up @@ -2160,14 +2161,14 @@ contract('HomeBridge_ERC20_to_Native', async accounts => {
describe('#FeeManager_random', async () => {
it('should return value between 0 and 3', async () => {
// Given
const feeManager = await FeeManagerErcToNative.new()
const feeManager = await FeeManagerMock.new()

for (let i = 0; i < 10; i++) {
// send Tx to generate new blocks
await feeManager.setHomeFee(0).should.be.fulfilled

// When
const result = await feeManager.random(3)
const result = await feeManager.randomTest(3)

// Then
expect(result).to.be.bignumber.gte(ZERO)
Expand Down

0 comments on commit b66a678

Please sign in to comment.