diff --git a/test/e2e/btc_staking_e2e_test.go b/test/e2e/btc_staking_e2e_test.go index e1cb307b2..f2d0e4e0c 100644 --- a/test/e2e/btc_staking_e2e_test.go +++ b/test/e2e/btc_staking_e2e_test.go @@ -344,9 +344,9 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() { // finality provider reward gauge should not be fully withdrawn fpRgs, err := nonValidatorNode.QueryRewardGauge(fpBabylonAddr) s.NoError(err) - fpRg := fpRgs[itypes.FinalityProviderType.String()] - s.T().Logf("finality provider's withdrawable reward before withdrawing: %s", convertToRewardGauge(fpRg).GetWithdrawableCoins().String()) - s.False(convertToRewardGauge(fpRg).IsFullyWithdrawn()) + fpRg := fpRgs[itypes.FinalityProviderType.String()].ToRewardGauge() + s.T().Logf("finality provider's withdrawable reward before withdrawing: %s", fpRg.GetWithdrawableCoins().String()) + s.False(fpRg.IsFullyWithdrawn()) // withdraw finality provider reward nonValidatorNode.WithdrawReward(itypes.FinalityProviderType.String(), initialization.ValidatorWalletName) @@ -360,9 +360,9 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() { // finality provider reward gauge should be fully withdrawn now fpRgs2, err := nonValidatorNode.QueryRewardGauge(fpBabylonAddr) s.NoError(err) - fpRg2 := fpRgs2[itypes.FinalityProviderType.String()] - s.T().Logf("finality provider's withdrawable reward after withdrawing: %s", convertToRewardGauge(fpRg2).GetWithdrawableCoins().String()) - s.True(convertToRewardGauge(fpRg2).IsFullyWithdrawn()) + fpRg2 := fpRgs2[itypes.FinalityProviderType.String()].ToRewardGauge() + s.T().Logf("finality provider's withdrawable reward after withdrawing: %s", fpRg2.GetWithdrawableCoins().String()) + s.True(fpRg2.IsFullyWithdrawn()) // BTC delegation balance before withdraw btcDelBalance, err := nonValidatorNode.QueryBalances(delBabylonAddr.String()) @@ -370,9 +370,9 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() { // BTC delegation reward gauge should not be fully withdrawn btcDelRgs, err := nonValidatorNode.QueryRewardGauge(delBabylonAddr) s.NoError(err) - btcDelRg := btcDelRgs[itypes.BTCDelegationType.String()] - s.T().Logf("BTC delegation's withdrawable reward before withdrawing: %s", convertToRewardGauge(btcDelRg).GetWithdrawableCoins().String()) - s.False(convertToRewardGauge(btcDelRg).IsFullyWithdrawn()) + btcDelRg := btcDelRgs[itypes.BTCDelegationType.String()].ToRewardGauge() + s.T().Logf("BTC delegation's withdrawable reward before withdrawing: %s", btcDelRg.GetWithdrawableCoins().String()) + s.False(btcDelRg.IsFullyWithdrawn()) // withdraw BTC delegation reward nonValidatorNode.WithdrawReward(itypes.BTCDelegationType.String(), initialization.ValidatorWalletName) @@ -386,9 +386,9 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() { // BTC delegation reward gauge should be fully withdrawn now btcDelRgs2, err := nonValidatorNode.QueryRewardGauge(delBabylonAddr) s.NoError(err) - btcDelRg2 := btcDelRgs2[itypes.BTCDelegationType.String()] - s.T().Logf("BTC delegation's withdrawable reward after withdrawing: %s", convertToRewardGauge(btcDelRg2).GetWithdrawableCoins().String()) - s.True(convertToRewardGauge(btcDelRg2).IsFullyWithdrawn()) + btcDelRg2 := btcDelRgs2[itypes.BTCDelegationType.String()].ToRewardGauge() + s.T().Logf("BTC delegation's withdrawable reward after withdrawing: %s", btcDelRg2.GetWithdrawableCoins().String()) + s.True(btcDelRg2.IsFullyWithdrawn()) } // Test5SubmitStakerUnbonding is an end-to-end test for user unbonding @@ -1017,10 +1017,3 @@ func (s *BTCStakingTestSuite) BTCStakingUnbondSlashInfo( return testStakingInfo, blockWithStakingTx.SpvProof.BtcTransaction, inclusionProof, testUnbondingInfo, delegatorSig } - -func convertToRewardGauge(rg *itypes.RewardGaugesResponse) *itypes.RewardGauge { - return &itypes.RewardGauge{ - Coins: rg.Coins, - WithdrawnCoins: rg.WithdrawnCoins, - } -} diff --git a/test/e2e/configurer/chain/commands.go b/test/e2e/configurer/chain/commands.go index b01a2f328..2104ff98f 100644 --- a/test/e2e/configurer/chain/commands.go +++ b/test/e2e/configurer/chain/commands.go @@ -300,13 +300,14 @@ func (n *NodeConfig) WithdrawReward(sType, from string) (txHash string) { // WithdrawRewardCheckingBalances will withdraw the rewards and verify the amount was correctly withdraw func (n *NodeConfig) WithdrawRewardCheckingBalances(sType, fromAddr string) { + n.t.Helper() balanceBeforeRwdWithdraw, err := n.QueryBalances(fromAddr) require.NoError(n.t, err) rewardGauge, err := n.QueryRewardGauge(sdk.MustAccAddressFromBech32(fromAddr)) require.NoError(n.t, err) - fpRg := rewardGauge[sType] + fpRg := rewardGauge[sType].ToRewardGauge() n.t.Logf("address: %s withdrawable reward before withdrawing: %s", fromAddr, fpRg.WithdrawnCoins.String()) require.False(n.t, fpRg.Coins.Equal(fpRg.WithdrawnCoins)) @@ -321,10 +322,12 @@ func (n *NodeConfig) WithdrawRewardCheckingBalances(sType, fromAddr string) { require.NoError(n.t, err) actualAmt := balanceAfterRwdWithdraw.String() - expectedAmt := balanceBeforeRwdWithdraw.Add(fpRg.WithdrawnCoins...).Sub(txResp.AuthInfo.Fee.Amount...).String() + + coinsReceivedWithdraw := fpRg.GetWithdrawableCoins() + expectedAmt := balanceBeforeRwdWithdraw.Add(coinsReceivedWithdraw...).Sub(txResp.AuthInfo.Fee.Amount...).String() require.Equal(n.t, expectedAmt, actualAmt, "Expected(after withdraw): %s, actual(before withdraw + withdraw - TxFees): %s", expectedAmt, actualAmt) - n.t.Logf("BalanceAfterRwdWithdraw: %s; BalanceBeforeRwdWithdraw: %s", balanceAfterRwdWithdraw.String(), balanceBeforeRwdWithdraw.String()) + n.t.Logf("BalanceAfterRwdWithdraw: %s; BalanceBeforeRwdWithdraw: %s, txFees: %s, CoinsReceivedWithdraw", balanceAfterRwdWithdraw.String(), balanceBeforeRwdWithdraw.String(), txResp.AuthInfo.Fee.Amount.String(), coinsReceivedWithdraw.String()) } // TxMultisigSign sign a tx in a file with one wallet for a multisig address. diff --git a/x/incentive/types/types.go b/x/incentive/types/types.go index b2cb2d67b..987100ee4 100644 --- a/x/incentive/types/types.go +++ b/x/incentive/types/types.go @@ -10,3 +10,11 @@ func HashMsg(msg sdk.Msg) []byte { msgHash := tmhash.Sum(msgBytes) return msgHash } + +// ToRewardGauge parses to RewardGauge +func (rgr RewardGaugesResponse) ToRewardGauge() RewardGauge { + return RewardGauge{ + Coins: rgr.Coins, + WithdrawnCoins: rgr.WithdrawnCoins, + } +}