Add validators amount limit (#239)
This commit is contained in:
parent
786be68cd6
commit
a747842c95
|
@ -9,6 +9,7 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
|
|||
using SafeMath for uint256;
|
||||
|
||||
address public constant F_ADDR = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;
|
||||
uint256 internal constant MAX_VALIDATORS = 100;
|
||||
|
||||
event ValidatorAdded (address indexed validator);
|
||||
event ValidatorRemoved (address indexed validator);
|
||||
|
|
|
@ -18,6 +18,7 @@ contract BridgeValidators is BaseBridgeValidators {
|
|||
setOwner(_owner);
|
||||
require(_requiredSignatures != 0);
|
||||
require(_initialValidators.length >= _requiredSignatures);
|
||||
require(_initialValidators.length <= MAX_VALIDATORS);
|
||||
|
||||
for (uint256 i = 0; i < _initialValidators.length; i++) {
|
||||
require(_initialValidators[i] != address(0) && _initialValidators[i] != F_ADDR);
|
||||
|
|
|
@ -19,6 +19,7 @@ contract RewardableValidators is BaseBridgeValidators {
|
|||
setOwner(_owner);
|
||||
require(_requiredSignatures != 0);
|
||||
require(_initialValidators.length >= _requiredSignatures);
|
||||
require(_initialValidators.length <= MAX_VALIDATORS);
|
||||
require(_initialValidators.length == _initialRewards.length);
|
||||
|
||||
for (uint256 i = 0; i < _initialValidators.length; i++) {
|
||||
|
|
|
@ -162,3 +162,13 @@ function isBN(object) {
|
|||
}
|
||||
|
||||
module.exports.expectEventInLogs = expectEventInLogs
|
||||
|
||||
function createAccounts(web3, amount) {
|
||||
const array = []
|
||||
for (let i = 0; i < amount; i++) {
|
||||
array[i] = web3.eth.accounts.create().address
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
module.exports.createAccounts = createAccounts
|
||||
|
|
|
@ -3,7 +3,7 @@ const EternalStorageProxy = artifacts.require('EternalStorageProxy.sol')
|
|||
|
||||
const { expect } = require('chai')
|
||||
const { ERROR_MSG, ZERO_ADDRESS, F_ADDRESS, BN } = require('./setup')
|
||||
const { expectEventInLogs } = require('./helpers/helpers')
|
||||
const { expectEventInLogs, createAccounts } = require('./helpers/helpers')
|
||||
|
||||
const ZERO = new BN(0)
|
||||
|
||||
|
@ -60,6 +60,21 @@ contract('RewardableValidators', async accounts => {
|
|||
expect(minor).to.be.bignumber.gte(ZERO)
|
||||
expect(patch).to.be.bignumber.gte(ZERO)
|
||||
})
|
||||
it('should fail if exceed amount of validators', async () => {
|
||||
// Given
|
||||
const validators = createAccounts(web3, 101)
|
||||
|
||||
// When
|
||||
await bridgeValidators
|
||||
.initialize(99, validators, validators, accounts[2], { from: accounts[2] })
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await bridgeValidators.initialize(99, validators.slice(0, 100), validators.slice(0, 100), accounts[2], {
|
||||
from: accounts[2]
|
||||
}).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
expect(await bridgeValidators.validatorCount()).to.be.bignumber.equal('100')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#addValidator', async () => {
|
||||
|
|
|
@ -3,7 +3,7 @@ const EternalStorageProxy = artifacts.require('EternalStorageProxy.sol')
|
|||
|
||||
const { expect } = require('chai')
|
||||
const { ERROR_MSG, ZERO_ADDRESS, F_ADDRESS, BN } = require('./setup')
|
||||
const { expectEventInLogs } = require('./helpers/helpers')
|
||||
const { expectEventInLogs, createAccounts } = require('./helpers/helpers')
|
||||
|
||||
const ZERO = new BN(0)
|
||||
|
||||
|
@ -48,6 +48,20 @@ contract('BridgeValidators', async accounts => {
|
|||
expect(minor).to.be.bignumber.gte(ZERO)
|
||||
expect(patch).to.be.bignumber.gte(ZERO)
|
||||
})
|
||||
it('should fail if exceed amount of validators', async () => {
|
||||
// Given
|
||||
const validators = createAccounts(web3, 101)
|
||||
|
||||
// When
|
||||
await bridgeValidators
|
||||
.initialize(99, validators, accounts[2], { from: accounts[2] })
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await bridgeValidators.initialize(99, validators.slice(0, 100), accounts[2], { from: accounts[2] }).should.be
|
||||
.fulfilled
|
||||
|
||||
// Then
|
||||
expect(await bridgeValidators.validatorCount()).to.be.bignumber.equal('100')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#addValidator', async () => {
|
||||
|
|
Loading…
Reference in New Issue