From a5e0c772cebe000811da60782c4a7bc7bced59dd Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 18 Sep 2024 16:54:29 +0200 Subject: [PATCH] Reset pending payment to 0 when sending --- .../protocol/contracts-0.8/common/EpochManager.sol | 1 + .../protocol/test-sol/unit/common/EpochManager.t.sol | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/protocol/contracts-0.8/common/EpochManager.sol b/packages/protocol/contracts-0.8/common/EpochManager.sol index a22603b65b7..b1203032b2b 100644 --- a/packages/protocol/contracts-0.8/common/EpochManager.sol +++ b/packages/protocol/contracts-0.8/common/EpochManager.sol @@ -367,6 +367,7 @@ contract EpochManager is FixidityLib.Fraction memory totalPayment = FixidityLib.newFixed( validatorPendingPayments[signer] ); + validatorPendingPayments[signer] = 0; IValidators validators = getValidators(); address group = validators.getValidatorsGroup(validator); diff --git a/packages/protocol/test-sol/unit/common/EpochManager.t.sol b/packages/protocol/test-sol/unit/common/EpochManager.t.sol index 1b2074f4654..9b4dfe07db5 100644 --- a/packages/protocol/test-sol/unit/common/EpochManager.t.sol +++ b/packages/protocol/test-sol/unit/common/EpochManager.t.sol @@ -380,4 +380,15 @@ contract EpochManagerTest_sendValidatorPayment is EpochManagerTest { assertEq(beneficiaryBalanceAfter, 0); assertEq(epochManagerBalanceAfter, epochManagerBalanceBefore); } + + function test_doesntAllowDoubleSending() public { + epochManager.sendValidatorPayment(validator1); + epochManager.sendValidatorPayment(validator1); + + uint256 validatorBalanceAfter = stableToken.balanceOf(validator1); + uint256 epochManagerBalanceAfter = stableToken.balanceOf(address(epochManager)); + + assertEq(validatorBalanceAfter, paymentAmount); + assertEq(epochManagerBalanceAfter, epochManagerBalanceBefore - paymentAmount); + } }