Skip to content

Commit

Permalink
Fix/ackerr_tests (#341)
Browse files Browse the repository at this point in the history
Co-authored-by: anhductn2001 <[email protected]>
  • Loading branch information
hoangdv2429 and anhductn2001 committed Jul 25, 2024
1 parent 4861886 commit 4391b9e
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions tests/eibc_ack_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"testing"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/x/params/client/utils"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand Down Expand Up @@ -367,6 +369,12 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {

// At the moment, the ack returned and the demand order status became "finalized"
// We will execute the ibc transfer again and try to fulfill the demand order
balance, err = rollapp1.GetBalance(ctx, rollappUserAddr, dymensionIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of rollappUserAddr right before sending eIBC transfer (that fulfilled):", balance)
balance, err = rollapp1.GetBalance(ctx, erc20MAccAddr, dymensionIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of moduleAccAddr right before sending eIBC transfer (that fulfilled):", balance)
_, err = rollapp1.SendIBCTransfer(ctx, channRollApp1Dym.ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

Expand Down Expand Up @@ -417,8 +425,8 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {
require.True(t, balance.Equal(expMmBalanceDymDenom), fmt.Sprintf("Value mismatch. Expected %s, actual %s", expMmBalanceDymDenom, balance))

// wait for a few blocks and check if the fund returns to rollapp
testutil.WaitForBlocks(ctx, 20, rollapp1)
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, transferAmount)
testutil.WaitForBlocks(ctx, BLOCK_FINALITY_PERIOD+10, rollapp1)
testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, dymensionIBCDenom, transferAmount)
})

t.Cleanup(
Expand Down Expand Up @@ -1042,6 +1050,49 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {

var options ibc.TransferOptions

// register ibc denom on rollapp1
metadata := banktypes.Metadata{
Description: "IBC token from rollapp 2",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: thirdPartyIBCDenomOnRA,
Exponent: 0,
Aliases: []string{"urax"},
},
{
Denom: "urax",
Exponent: 6,
},
},
// Setting base as IBC hash denom since bank keepers's SetDenomMetadata uses
// Base as key path and the IBC hash is what gives this token uniqueness
// on the executing chain
Base: thirdPartyIBCDenomOnRA,
Display: "urax",
Name: "urax",
Symbol: "urax",
}

data := map[string][]banktypes.Metadata{
"metadata": {metadata},
}

contentFile, err := json.Marshal(data)
require.NoError(t, err)
rollapp1.GetNode().WriteFile(ctx, contentFile, "./ibcmetadata.json")
deposit := "500000000000" + rollapp1.Config().Denom
rollapp1.GetNode().HostName()
_, err = rollapp1.GetNode().RegisterIBCTokenDenomProposal(ctx, rollapp1UserAddr, deposit, rollapp1.GetNode().HomeDir()+"/ibcmetadata.json")
require.NoError(t, err)

err = rollapp1.VoteOnProposalAllValidators(ctx, "1", cosmos.ProposalVoteYes)
require.NoError(t, err, "failed to submit votes")

height, err := rollapp1.Height(ctx)
require.NoError(t, err, "error fetching height")
_, err = cosmos.PollForProposalStatus(ctx, rollapp1.CosmosChain, height, height+30, "1", cosmos.ProposalStatusPassed)
require.NoError(t, err, "proposal status did not change to passed")

t.Run("Demand order is created upon AckError for rollapp token", func(t *testing.T) {
transferData := ibc.WalletData{
Address: marketMakerAddr,
Expand Down Expand Up @@ -1130,7 +1181,7 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
// Make sure that the ack contains error
require.True(t, bytes.Contains(ack.Acknowledgement, []byte("error")))

testutil.AssertBalance(t, ctx, rollapp1, rollapp1UserAddr, thirdPartyIBCDenomOnRA, transferAmount)
testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, thirdPartyIBCDenomOnRA, transferAmount)

// At the moment, the ack returned and the demand order status became "finalized"
// We will execute the ibc transfer again and try to fulfill the demand order
Expand Down

0 comments on commit 4391b9e

Please sign in to comment.