Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tryfix: coins withdraw
Browse files Browse the repository at this point in the history
RafilxTenfen committed Jan 31, 2025
1 parent 37ec38f commit 80f24c7
Showing 3 changed files with 26 additions and 22 deletions.
31 changes: 12 additions & 19 deletions test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
@@ -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,19 +360,19 @@ 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())
s.NoError(err)
// 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,
}
}
9 changes: 6 additions & 3 deletions test/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
@@ -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())

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / lint_test / lint

printf: (*testing.common).Logf call needs 3 args but has 4 args (govet)

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / lint_test / unit-tests

(*testing.common).Logf call needs 3 args but has 4 args

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / e2e-run-btc-staking

(*testing.common).Logf call needs 3 args but has 4 args

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / e2e-run-btc-staking-pre-approval

(*testing.common).Logf call needs 3 args but has 4 args

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / e2e-run-btc-timestamping

(*testing.common).Logf call needs 3 args but has 4 args

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / e2e-run-btc-rewards

(*testing.common).Logf call needs 3 args but has 4 args

Check failure on line 330 in test/e2e/configurer/chain/commands.go

GitHub Actions / e2e-run-ibc-transfer

(*testing.common).Logf call needs 3 args but has 4 args
}

// TxMultisigSign sign a tx in a file with one wallet for a multisig address.
8 changes: 8 additions & 0 deletions x/incentive/types/types.go
Original file line number Diff line number Diff line change
@@ -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{

Check failure on line 16 in x/incentive/types/types.go

GitHub Actions / lint_test / lint

S1016: should convert rgr (type RewardGaugesResponse) to RewardGauge instead of using struct literal (gosimple)
Coins: rgr.Coins,
WithdrawnCoins: rgr.WithdrawnCoins,
}
}

0 comments on commit 80f24c7

Please sign in to comment.