Skip to content

Commit

Permalink
SKALE-2157 Add sanity check for the input values in registerValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
yavrsky committed Feb 28, 2020
1 parent ecf5b06 commit 6cf1030
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions contracts/delegation/ValidatorService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ contract ValidatorService is Permissions {
uint feeRate;
uint registrationTime;
uint minimumDelegationAmount;
uint lastBountyCollectionMonth;
uint[] nodeIndexes;
}

Expand Down Expand Up @@ -64,6 +63,7 @@ contract ValidatorService is Permissions {
returns (uint validatorId)
{
require(_validatorAddressToId[validatorAddress] == 0, "Validator with such address already exists");
require(feeRate < 1000, "Fee rate of validator should be lower than 100%");
uint[] memory epmtyArray = new uint[](0);
validatorId = ++numberOfValidators;
validators[validatorId] = Validator(
Expand All @@ -74,7 +74,6 @@ contract ValidatorService is Permissions {
feeRate,
now,
minimumDelegationAmount,
0,
epmtyArray
);
setValidatorAddress(validatorId, validatorAddress);
Expand Down
15 changes: 11 additions & 4 deletions test/delegation/ValidatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ class Validator {
public feeRate: BigNumber;
public registrationTime: BigNumber;
public minimumDelegationAmount: BigNumber;
public lastBountyCollectionMonth: BigNumber;

constructor(arrayData: [string, string, string, string, BigNumber, BigNumber, BigNumber, BigNumber]) {
constructor(arrayData: [string, string, string, string, BigNumber, BigNumber, BigNumber]) {
this.name = arrayData[0];
this.validatorAddress = arrayData[1];
this.requestedAddress = arrayData[2];
this.description = arrayData[3];
this.feeRate = new BigNumber(arrayData[4]);
this.registrationTime = new BigNumber(arrayData[5]);
this.minimumDelegationAmount = new BigNumber(arrayData[6]);
this.lastBountyCollectionMonth = new BigNumber(arrayData[7]);

}
}

Expand Down Expand Up @@ -78,6 +75,16 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3
assert.isTrue(await validatorService.checkValidatorAddressToId(validator1, validatorId));
});

it("should reject if validator tried to register with a fee rate higher than 100 percent", async () => {
await delegationService.registerValidator(
"ValidatorName",
"Really good validator",
1500,
100,
{from: validator1})
.should.be.eventually.rejectedWith("Fee rate of validator should be lower than 100%");
});

describe("when validator registered", async () => {
beforeEach(async () => {
await delegationService.registerValidator(
Expand Down

0 comments on commit 6cf1030

Please sign in to comment.