Skip to content

Commit

Permalink
Merge pull request #3076 from s2quake/fix/commission-differenct-value
Browse files Browse the repository at this point in the history
Cannot set commission with the same value
  • Loading branch information
s2quake authored Dec 9, 2024
2 parents b3f4cec + c90b637 commit 9649a61
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,33 @@ public void Execute_NotValidator_Throw()
Assert.Throws<FailedLoadStateException>(
() => 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<InvalidOperationException>(
() => setValidatorCommission.Execute(actionContext));
}
}
}
6 changes: 6 additions & 0 deletions Lib9c/ValidatorDelegation/ValidatorDelegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9649a61

Please sign in to comment.