Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validatorList on BaseBridgeValidators #167

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})