From 4794a729e75dd587b32939b8ecd8963c56e2d00d Mon Sep 17 00:00:00 2001 From: Francisco de Borja Aranda Castillejo Date: Mon, 25 Nov 2024 16:49:06 +0100 Subject: [PATCH] fixes based on PR review --- ...=> test_precompiles_distribute_and_claim.go} | 3 ++- ...es_distribute_and_claim_through_contract.go} | 3 ++- precompiles/staking/method_claim_rewards.go | 17 ++++++++--------- ...rds_test.go => method_claim_rewards_test.go} | 15 ++++++++++----- 4 files changed, 22 insertions(+), 16 deletions(-) rename e2e/e2etests/{test_precompiles_distribute.go => test_precompiles_distribute_and_claim.go} (99%) rename e2e/e2etests/{test_precompiles_distribute_through_contract.go => test_precompiles_distribute_and_claim_through_contract.go} (99%) rename precompiles/staking/{methiod_claim_rewards_test.go => method_claim_rewards_test.go} (86%) diff --git a/e2e/e2etests/test_precompiles_distribute.go b/e2e/e2etests/test_precompiles_distribute_and_claim.go similarity index 99% rename from e2e/e2etests/test_precompiles_distribute.go rename to e2e/e2etests/test_precompiles_distribute_and_claim.go index f5658a27a2..91aa81fc44 100644 --- a/e2e/e2etests/test_precompiles_distribute.go +++ b/e2e/e2etests/test_precompiles_distribute_and_claim.go @@ -42,13 +42,14 @@ func TestPrecompilesDistributeAndClaim(r *runner.E2ERunner, args []string) { fiveHundred = big.NewInt(500) fiveHundredOne = big.NewInt(501) zero = big.NewInt(0) + stake = "1000000000000000000000" previousGasLimit = r.ZEVMAuth.GasLimit ) // stakeAmt has to be as big as the validator self delegation. // This way the rewards will be distributed 50%. - _, ok := stakeAmt.SetString("1000000000000000000000", 10) + _, ok := stakeAmt.SetString(stake, 10) require.True(r, ok) // Set new gas limit to avoid out of gas errors. diff --git a/e2e/e2etests/test_precompiles_distribute_through_contract.go b/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go similarity index 99% rename from e2e/e2etests/test_precompiles_distribute_through_contract.go rename to e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go index ff2d2ad51a..284185de77 100644 --- a/e2e/e2etests/test_precompiles_distribute_through_contract.go +++ b/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go @@ -44,13 +44,14 @@ func TestPrecompilesDistributeAndClaimThroughContract(r *runner.E2ERunner, args fiveHundred = big.NewInt(500) fiveHundredOne = big.NewInt(501) zero = big.NewInt(0) + stake = "1000000000000000000000" previousGasLimit = r.ZEVMAuth.GasLimit ) // stakeAmt has to be as big as the validator self delegation. // This way the rewards will be distributed 50%. - _, ok := stakeAmt.SetString("1000000000000000000000", 10) + _, ok := stakeAmt.SetString(stake, 10) require.True(r, ok) // Set new gas limit to avoid out of gas errors. diff --git a/precompiles/staking/method_claim_rewards.go b/precompiles/staking/method_claim_rewards.go index c0ee56bc43..963e36b884 100644 --- a/precompiles/staking/method_claim_rewards.go +++ b/precompiles/staking/method_claim_rewards.go @@ -80,7 +80,7 @@ func (c *Contract) claimRewards( // Check if bank address has enough ZRC20 balance. // This check is also made inside UnlockZRC20, but repeat it here to avoid burning the coins. if err := c.fungibleKeeper.CheckZRC20Balance(ctx, zrc20Addr, bank.ContractAddress, zrc20Amount); err != nil { - ctx.Logger().Info( + ctx.Logger().Error( "Claimed invalid amount of ZRC20 Validator Rewards", "Total", zrc20Amount, "Denom", precompiletypes.ZRC20ToCosmosDenom(zrc20Addr), @@ -96,14 +96,6 @@ func (c *Contract) claimRewards( continue } - ctx.Logger().Info( - "Sentf ZRC20 coins from delegator to Module", - "Delegator", delegatorCosmosAddr, - "Module", fungibletypes.ModuleName, - "Denom", precompiletypes.ZRC20ToCosmosDenom(zrc20Addr), - "Amount", coin.Amount, - ) - if err := c.bankKeeper.BurnCoins(ctx, fungibletypes.ModuleName, coinSet); err != nil { return nil, &precompiletypes.ErrUnexpected{ When: "BurnCoins", @@ -127,6 +119,13 @@ func (c *Contract) claimRewards( Got: err.Error(), } } + + ctx.Logger().Debug( + "Claimed ZRC20 rewards", + "Delegator", delegatorCosmosAddr, + "Denom", precompiletypes.ZRC20ToCosmosDenom(zrc20Addr), + "Amount", coin.Amount, + ) } return method.Outputs.Pack(true) diff --git a/precompiles/staking/methiod_claim_rewards_test.go b/precompiles/staking/method_claim_rewards_test.go similarity index 86% rename from precompiles/staking/methiod_claim_rewards_test.go rename to precompiles/staking/method_claim_rewards_test.go index 07a4fb2920..3ff8222757 100644 --- a/precompiles/staking/methiod_claim_rewards_test.go +++ b/precompiles/staking/method_claim_rewards_test.go @@ -15,9 +15,6 @@ func Test_ClaimRewards(t *testing.T) { s := newTestSuite(t) validator := sample.Validator(t, rand.New(rand.NewSource(42))) - // Create staker. - //stakerEVMAddr := sample.EthAddress() - /* ACT */ // Call claimRewardsMethod. claimRewardsMethod := s.stkContractABI.Methods[ClaimRewardsMethodName] @@ -30,7 +27,11 @@ func Test_ClaimRewards(t *testing.T) { _, err := s.stkContract.Run(s.mockEVM, s.mockVMContract, false) require.Error(t, err) - require.Contains(t, err.Error(), "invalid address 0x0000000000000000000000000000000000000000, reason: empty address") + require.Contains( + t, + err.Error(), + "invalid address 0x0000000000000000000000000000000000000000, reason: empty address", + ) }) t.Run("should return an error when passing incorrect validator", func(t *testing.T) { @@ -75,6 +76,10 @@ func Test_ClaimRewards(t *testing.T) { _, err := s.stkContract.Run(s.mockEVM, s.mockVMContract, false) require.Error(t, err) - require.Contains(t, err.Error(), "unexpected error in WithdrawDelegationRewards: no delegation distribution info") + require.Contains( + t, + err.Error(), + "unexpected error in WithdrawDelegationRewards: no delegation distribution info", + ) }) }