Skip to content

Commit

Permalink
Merge pull request #167 from poanetwork/add-validator-list-method-bri…
Browse files Browse the repository at this point in the history
…dge-validators

Add validatorList on BaseBridgeValidators
  • Loading branch information
akolotov authored Apr 15, 2019
2 parents b117b21 + 7581f12 commit 3971866
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
21 changes: 20 additions & 1 deletion contracts/upgradeable_contracts/BaseBridgeValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,26 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
pure
returns (uint64 major, uint64 minor, uint64 patch)
{
return (2, 1, 0);
return (2, 2, 0);
}

function validatorList() public view returns (address[]) {
address [] memory list = new address[](validatorCount());
uint256 counter = 0;
address nextValidator = getNextValidator(F_ADDR);
require(nextValidator != address(0));

while (nextValidator != F_ADDR) {
list[counter] = nextValidator;
nextValidator = getNextValidator(nextValidator);
counter++;

if (nextValidator == address(0) ) {
revert();
}
}

return list;
}

function _addValidator(address _validator) internal {
Expand Down
19 changes: 0 additions & 19 deletions contracts/upgradeable_contracts/RewardableValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ contract RewardableValidators is BaseBridgeValidators {
emit ValidatorRemoved(_validator);
}

function validatorList() public view returns (address[]) {
address [] memory list = new address[](validatorCount());
uint256 counter = 0;
address nextValidator = getNextValidator(F_ADDR);
require(nextValidator != address(0));

while (nextValidator != F_ADDR) {
list[counter] = nextValidator;
nextValidator = getNextValidator(nextValidator);
counter++;

if (nextValidator == address(0) ) {
revert();
}
}

return list;
}

function getValidatorRewardAddress(address _validator) public view returns (address) {
return addressStorage[keccak256(abi.encodePacked("validatorsRewards", _validator))];
}
Expand Down
15 changes: 15 additions & 0 deletions test/validators_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,19 @@ contract('BridgeValidators', async (accounts) => {
})
})
})

describe('#Validators list', () => {
it('should return validators list', async () => {
// Given
const validators = accounts.slice(0, 5)
const { initialize, validatorList } = bridgeValidators
await initialize(1, validators, owner, { from: owner }).should.be.fulfilled

// When
const returnedList = await validatorList()

// Then
returnedList.should.be.eql(validators)
})
})
})

0 comments on commit 3971866

Please sign in to comment.