Add validatorList method
This commit is contained in:
parent
c43f117fbe
commit
76d45e2861
|
@ -5,6 +5,6 @@ interface IBridgeValidators {
|
|||
function isValidator(address _validator) public view returns(bool);
|
||||
function requiredSignatures() public view returns(uint256);
|
||||
function owner() public view returns(address);
|
||||
function getNextValidator(address _validator) public view returns(address);
|
||||
function getValidatorRewardAddress(address _validator) public view returns(address);
|
||||
function validatorList() public view returns (address[]);
|
||||
}
|
||||
|
|
|
@ -142,6 +142,20 @@ contract BridgeValidators is IBridgeValidators, EternalStorage, Ownable {
|
|||
return addressStorage[keccak256(abi.encodePacked("validatorsList", _address))];
|
||||
}
|
||||
|
||||
function validatorList() public view returns (address[]) {
|
||||
address [] memory list = new address[](validatorCount());
|
||||
uint256 counter = 0;
|
||||
address nextValidator = getNextValidator(F_ADDR);
|
||||
|
||||
while (nextValidator != F_ADDR) {
|
||||
list[counter] = nextValidator;
|
||||
nextValidator = getNextValidator(nextValidator);
|
||||
counter++;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
function setValidatorRewardAddress(address _validator, address _reward) internal {
|
||||
addressStorage[keccak256(abi.encodePacked("validatorsRewards", _validator))] = _reward;
|
||||
}
|
||||
|
|
|
@ -228,4 +228,18 @@ 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, accounts.slice(5), owner, { from: owner }).should.be.fulfilled
|
||||
|
||||
// When
|
||||
const returnedList = await validatorList()
|
||||
|
||||
// Then
|
||||
returnedList.should.be.eql(validators)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue