Skip to content

Commit

Permalink
Merge pull request #103 from skalenetwork/feature/whitelist-getter
Browse files Browse the repository at this point in the history
Feature/whitelist getter
  • Loading branch information
payvint authored Feb 28, 2020
2 parents 84545e1 + d41d1f6 commit f17c22a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/delegation/ValidatorService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ contract ValidatorService is Permissions {
trustedValidators[validatorId] = false;
}

function getTrustedValidators() external view returns (uint[] memory) {
uint numberOfTrustedValidators = 0;
for (uint i = 1; i <= numberOfValidators; i++) {
if (trustedValidators[i]) {
numberOfTrustedValidators++;
}
}
uint[] memory whitelist = new uint[](numberOfTrustedValidators);
uint cursor = 0;
for (uint i = 1; i <= numberOfValidators; i++) {
if (trustedValidators[i]) {
whitelist[cursor++] = i;
}
}
return whitelist;
}

function requestForNewAddress(address oldValidatorAddress, address newValidatorAddress) external allow("DelegationService") {
require(newValidatorAddress != address(0), "New address cannot be null");
uint validatorId = getValidatorId(oldValidatorAddress);
Expand Down
25 changes: 25 additions & 0 deletions test/delegation/ValidatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3
.should.be.eventually.rejectedWith("New address cannot be null");
});

it("should return list of trusted validators", async () => {
const validatorId1 = 1;
const validatorId2 = 2;
const validatorId3 = 3;
await delegationService.registerValidator(
"ValidatorName",
"Really good validator",
500,
100,
{from: validator2});
await delegationService.registerValidator(
"ValidatorName",
"Really good validator",
500,
100,
{from: validator3});
const whitelist = [];
await validatorService.enableValidator(validatorId1, {from: owner});
whitelist.push(validatorId1);
await validatorService.enableValidator(validatorId3, {from: owner});
whitelist.push(validatorId3);
const trustedList = (await validatorService.getTrustedValidators()).map(Number);
assert.deepEqual(whitelist, trustedList);
});

describe("when holder has enough tokens", async () => {
let validatorId: number;
let amount: number;
Expand Down

0 comments on commit f17c22a

Please sign in to comment.