Skip to content

Commit

Permalink
Added helper function to get the list of current validators (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl authored and celo-ci-bot-user committed Nov 15, 2019
1 parent 1700119 commit d0229ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/celotool/src/e2e-tests/governance_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,8 @@ describe('governance tests', () => {
await sleep(epoch)
})

const getValidatorSetAtBlock = async (blockNumber: number) => {
const validatorSetSize = await election.methods
.numberValidatorsInCurrentSet()
.call({}, blockNumber)
const validatorSet = []
for (let i = 0; i < validatorSetSize; i++) {
validatorSet.push(
await election.methods.validatorAddressFromCurrentSet(i).call({}, blockNumber)
)
}
return validatorSet
const getValidatorSetAtBlock = async (blockNumber: number): Promise<string[]> => {
return election.methods.currentValidators().call({}, blockNumber)
}

const getLastEpochBlock = (blockNumber: number) => {
Expand Down
13 changes: 13 additions & 0 deletions packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,17 @@ contract Election is
}
return array;
}

/**
* @notice Returns get current validators using the precompile.
* @return List of current validators.
*/
function currentValidators() public view returns (address[] memory) {
uint256 n = numberValidatorsInCurrentSet();
address[] memory res = new address[](n);
for (uint256 idx = 0; idx < n; idx++) {
res[idx] = validatorAddressFromCurrentSet(idx);
}
return res;
}
}

0 comments on commit d0229ce

Please sign in to comment.