Skip to content

Commit

Permalink
fixes based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Nov 25, 2024
1 parent 507ce08 commit 4794a72
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 8 additions & 9 deletions precompiles/staking/method_claim_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) {
Expand Down Expand Up @@ -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",
)
})
}

0 comments on commit 4794a72

Please sign in to comment.