From 6cf10304c5d2aa48c838c62778e196cd00126f97 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Fri, 28 Feb 2020 15:05:38 +0200 Subject: [PATCH] SKALE-2157 Add sanity check for the input values in registerValidator --- contracts/delegation/ValidatorService.sol | 3 +-- test/delegation/ValidatorService.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/contracts/delegation/ValidatorService.sol b/contracts/delegation/ValidatorService.sol index 6332be996..9666fc066 100644 --- a/contracts/delegation/ValidatorService.sol +++ b/contracts/delegation/ValidatorService.sol @@ -35,7 +35,6 @@ contract ValidatorService is Permissions { uint feeRate; uint registrationTime; uint minimumDelegationAmount; - uint lastBountyCollectionMonth; uint[] nodeIndexes; } @@ -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( @@ -74,7 +74,6 @@ contract ValidatorService is Permissions { feeRate, now, minimumDelegationAmount, - 0, epmtyArray ); setValidatorAddress(validatorId, validatorAddress); diff --git a/test/delegation/ValidatorService.ts b/test/delegation/ValidatorService.ts index 8de43177b..8bb0df6d2 100644 --- a/test/delegation/ValidatorService.ts +++ b/test/delegation/ValidatorService.ts @@ -25,9 +25,8 @@ 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]; @@ -35,8 +34,6 @@ class Validator { this.feeRate = new BigNumber(arrayData[4]); this.registrationTime = new BigNumber(arrayData[5]); this.minimumDelegationAmount = new BigNumber(arrayData[6]); - this.lastBountyCollectionMonth = new BigNumber(arrayData[7]); - } } @@ -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(