From 7a523161cf4e17cef31dc9703d3a0dab8824e89b Mon Sep 17 00:00:00 2001 From: s2quake Date: Mon, 9 Dec 2024 15:54:48 +0900 Subject: [PATCH 1/2] fix: Cannot set commission with the same value --- Lib9c/ValidatorDelegation/ValidatorDelegatee.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs index 7ebe20bea4..69513711e9 100644 --- a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs +++ b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs @@ -162,6 +162,12 @@ FungibleAssetValue commission public void SetCommissionPercentage(BigInteger percentage, long height) { + if (CommissionPercentage == percentage) + { + throw new InvalidOperationException( + "The commission percentage is already set to the requested value."); + } + if (height - CommissionPercentageLastUpdateHeight < CommissionPercentageUpdateCooldown) { throw new InvalidOperationException( From c90b637d15671b95bef3d48ddab9c8571497e432 Mon Sep 17 00:00:00 2001 From: s2quake Date: Mon, 9 Dec 2024 15:55:10 +0900 Subject: [PATCH 2/2] test: Test code for SetValidatorCommission action --- .../SetValidatorCommissionTest.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs index 97eacf55f1..1b6ef02a35 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs @@ -266,5 +266,33 @@ public void Execute_NotValidator_Throw() Assert.Throws( () => setValidatorCommission.Execute(actionContext)); } + + [Fact] + public void Execute_With_SameValue_Throw() + { + // Given + var world = World; + var validatorKey = new PrivateKey(); + var validatorGold = DelegationCurrency * 10; + var height = 1L; + world = EnsureToMintAsset(world, validatorKey, validatorGold, height++); + world = EnsurePromotedValidator(world, validatorKey, validatorGold, height); + + // When + var repository = new ValidatorRepository(world, new ActionContext()); + var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var commissionPercentage = delegatee.CommissionPercentage; + var setValidatorCommission = new SetValidatorCommission( + commissionPercentage: commissionPercentage); + var actionContext = new ActionContext + { + PreviousState = world, + Signer = validatorKey.Address, + BlockIndex = height + CommissionPercentageChangeCooldown, + }; + + Assert.Throws( + () => setValidatorCommission.Execute(actionContext)); + } } }