Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Sep 24, 2024
1 parent fa97fda commit 264f5ae
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 71 deletions.
86 changes: 74 additions & 12 deletions tests/eibc_ack_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {
_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

rollappHeight, err = rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

Expand All @@ -279,7 +282,10 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

// Get the IBC denom for adym on rollapp
Expand Down Expand Up @@ -349,7 +355,17 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {
require.True(t, balance.Equal(zeroBal), fmt.Sprintf("Value mismatch. Expected %s, actual %s", zeroBal, balance))

// catch ACK errors
rollappHeight, err = rollapp1.Height(ctx)
err = testutil.WaitForBlocks(ctx, 10, dymension)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollappHeight, rollappHeight+80, ibcTx.Packet)
Expand Down Expand Up @@ -768,10 +784,20 @@ func TestEIBC_AckError_RA_Token_EVM(t *testing.T) {
require.True(t, balance.Equal(transferAmount.Sub(bridgingFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmount.Sub(bridgingFee), balance))

// catch ACK errors
rollapp1Height, err := rollapp1.Height(ctx)
err = testutil.WaitForBlocks(ctx, 10, dymension)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollapp1Height, rollapp1Height+30, ibcTx.Packet)
rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollappHeight, rollappHeight+30, ibcTx.Packet)
require.NoError(t, err)

// Make sure that the ack contains error
Expand Down Expand Up @@ -1103,6 +1129,9 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

rollappHeight, err = rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

Expand All @@ -1111,7 +1140,10 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

var options ibc.TransferOptions
Expand Down Expand Up @@ -1170,7 +1202,7 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
err = dymension.Validators[0].SendFunds(ctx, "validator", transferData)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
err = testutil.WaitForBlocks(ctx, 20, dymension, rollapp1)
require.NoError(t, err)

testutil.AssertBalance(t, ctx, dymension, marketMakerAddr, thirdPartyDenom, transferAmount)
Expand Down Expand Up @@ -1551,6 +1583,9 @@ func TestEIBC_AckError_Dym_Wasm(t *testing.T) {
_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

rollappHeight, err = rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

Expand All @@ -1562,7 +1597,10 @@ func TestEIBC_AckError_Dym_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

// Get the IBC denom for adym on rollapp
Expand Down Expand Up @@ -1630,7 +1668,15 @@ func TestEIBC_AckError_Dym_Wasm(t *testing.T) {
rollappHeight, err = rollapp1.Height(ctx)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollappHeight, rollappHeight+70, ibcTx.Packet)
// wait until the packet is finalized
isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp2.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollappHeight, rollappHeight+30, ibcTx.Packet)
require.NoError(t, err)

// Make sure that the ack contains error
Expand Down Expand Up @@ -2037,10 +2083,20 @@ func TestEIBC_AckError_RA_Token_Wasm(t *testing.T) {
require.True(t, balance.Equal(transferAmount.Sub(bridgingFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmount.Sub(bridgingFee), balance))

// catch ACK errors
rollapp1Height, err := rollapp1.Height(ctx)
err = testutil.WaitForBlocks(ctx, 10, dymension)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollapp1Height, rollapp1Height+30, ibcTx.Packet)
rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollappHeight, rollappHeight+30, ibcTx.Packet)
require.NoError(t, err)

// Make sure that the ack contains error
Expand Down Expand Up @@ -2372,6 +2428,9 @@ func TestEIBC_AckError_3rd_Party_Token_Wasm(t *testing.T) {
_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

rollappHeight, err = rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

Expand All @@ -2380,7 +2439,10 @@ func TestEIBC_AckError_3rd_Party_Token_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp2)
require.NoError(t, err)

var options ibc.TransferOptions
Expand All @@ -2396,7 +2458,7 @@ func TestEIBC_AckError_3rd_Party_Token_Wasm(t *testing.T) {
err = dymension.Validators[0].SendFunds(ctx, "validator", transferData)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
err = testutil.WaitForBlocks(ctx, 20, dymension, rollapp1)
require.NoError(t, err)

testutil.AssertBalance(t, ctx, dymension, marketMakerAddr, thirdPartyDenom, transferAmount)
Expand Down
8 changes: 3 additions & 5 deletions tests/eibc_fee_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,6 @@ func TestEIBCFulfillAlreadyFulfilledDemand_EVM(t *testing.T) {
_, err = rollapp1.SendIBCTransfer(ctx, dymChannel_ra1[0].ChannelID, rollappUserAddr, transferDataRollapp1, options)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)
balance, err = dymension.GetBalance(ctx, dymensionUserAddr, rollappIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of dymensionUserAddr right after sending eIBC transfer from rollapp 1 to dym hub:", balance)
Expand Down Expand Up @@ -326,6 +321,9 @@ func TestEIBCFulfillAlreadyFulfilledDemand_EVM(t *testing.T) {
fmt.Println("Balance of dymensionUserAddr after fulfilling the order:", balance)
require.True(t, balance.Equal(transferAmountWithoutFee.Add(transferAmount.Sub(bridgingFee)).Sub(bridgingFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmountWithoutFee.Add(transferAmount.Sub(bridgingFee)).Sub(bridgingFee), balance))

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

// wait until packet finalization and verify funds + fee were added to market maker's wallet address
isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 200)
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions tests/eibc_feemarket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,6 @@ func TestEIBC_Fee_Market_Success_Wasm(t *testing.T) {
_, err = rollapp1.SendIBCTransfer(ctx, channsRollApp1[0].ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

balance, err = dymension.GetBalance(ctx, dymensionUserAddr, rollappIBCDenom)
require.NoError(t, err)

Expand Down Expand Up @@ -612,6 +606,9 @@ func TestEIBC_Fee_Market_Success_Wasm(t *testing.T) {
require.True(t, balance.Equal(transferAmountWithoutFee.Sub(bridgingFee).Sub(eibcFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmountWithoutFee.Sub(bridgingFee).Sub(eibcFee), balance))

// wait until packet finalization and verify funds + fee were added to market maker's wallet address
rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down Expand Up @@ -1746,6 +1743,9 @@ func TestEIBCUpdateOnAckErrAndTimeout_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

Expand Down
35 changes: 20 additions & 15 deletions tests/eibc_fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ func TestEIBCFulfillOnOneRollApp_EVM(t *testing.T) {
rollappHeight, err := rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

rollapp2Height, err := rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

// wait until the packet is finalized
isFinalized, err := dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)

rollapp2Height, err := rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp2.GetChainID(), rollapp2Height, 300)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down Expand Up @@ -732,11 +732,6 @@ func TestEIBCFulfillOnOneRollApp_Wasm(t *testing.T) {
_, err = rollapp1.SendIBCTransfer(ctx, dymChannel_ra1[0].ChannelID, rollappUserAddr, transferDataRollapp1, options)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)
balance, err = dymension.GetBalance(ctx, dymensionUserAddr, rollappIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of dymensionUserAddr right after sending eIBC transfer:", balance)
Expand Down Expand Up @@ -784,6 +779,9 @@ func TestEIBCFulfillOnOneRollApp_Wasm(t *testing.T) {
require.True(t, balance.Equal(expMmBalanceRollappDenom), fmt.Sprintf("Value mismatch. Expected %s, actual %s", expMmBalanceRollappDenom, balance))

// wait until packet finalization and verify funds + fee were added to market maker's wallet address
rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 200)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down Expand Up @@ -1776,7 +1774,6 @@ func TestEIBCFulfillment_two_rollapps_EVM(t *testing.T) {
require.True(t, balance.Equal(transferAmountWithoutFee.Sub(bridgingFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmountWithoutFee.Sub(bridgingFee), balance))

// verify funds were deducted from market maker's wallet address

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

Expand All @@ -1785,9 +1782,20 @@ func TestEIBCFulfillment_two_rollapps_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

rollapp2Height, err = rollapp2.GetNode().Height(ctx)
require.NoError(t, err)

// wait until the packet is finalized
isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp2.GetChainID(), rollapp2Height, 300)
require.NoError(t, err)
require.True(t, isFinalized)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp2.GetChainID(), fmt.Sprint(rollapp2Height))
require.NoError(t, err)

balance, err = dymension.GetBalance(ctx, marketMakerAddr, rollappIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of marketMakerAddr after fulfilling the order:", balance)
Expand Down Expand Up @@ -2172,12 +2180,6 @@ func TestEIBCFulfillment_ThirdParty_EVM(t *testing.T) {
_, err = rollapp1.SendIBCTransfer(ctx, channsRollApp1[0].ChannelID, rollapp1UserAddr, transferData, options)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

// get eIbc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 10, false)
require.NoError(t, err)
Expand All @@ -2202,6 +2204,9 @@ func TestEIBCFulfillment_ThirdParty_EVM(t *testing.T) {
fmt.Println("Balance of dymensionUserAddr after fulfilling the order:", balance)
require.True(t, balance.Equal(transferAmountWithoutFee.Sub(bridgingFee)), fmt.Sprintf("Value mismatch. Expected %s, actual %s", transferAmountWithoutFee.Sub(bridgingFee), balance))

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

// wait until packet finalization and verify funds + fee were added to market maker's wallet address
isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
Expand Down
10 changes: 4 additions & 6 deletions tests/eibc_invariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ func TestEIBCInvariant_EVM(t *testing.T) {
require.NoError(t, err)
}

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

balance, err = dymension.GetBalance(ctx, dymensionUserAddr, rollappIBCDenom)
require.NoError(t, err)
fmt.Println("Balance of dymensionUserAddr right after sending eIBC transfer:", balance)
Expand Down Expand Up @@ -290,7 +284,11 @@ func TestEIBCInvariant_EVM(t *testing.T) {
fmt.Println("Balance of marketMakerAddr after fulfilling the order:", balance)
expMmBalanceRollappDenom = expMmBalanceRollappDenom.Sub(transferAmountWithoutFee.MulRaw(2)).Add(bridgingFee.MulRaw(2))
require.True(t, balance.Equal(expMmBalanceRollappDenom), fmt.Sprintf("Value mismatch. Expected %s, actual %s", expMmBalanceRollappDenom, balance))

// wait until packet finalization and verify funds + fee were added to market maker's wallet address
rollappHeight, err = rollapp1.GetNode().Height(ctx)
require.NoError(t, err)

isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down
12 changes: 6 additions & 6 deletions tests/eibc_pfm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ func TestEIBCPFM_EVM(t *testing.T) {
tx, err := rollapp1.SendIBCTransfer(ctx, channRollApp1Dym.ChannelID, rollapp1User.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollapp1Height, err := rollapp1.Height(ctx)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollapp1Height, rollapp1Height+30, tx.Packet)
require.NoError(t, err)

rollapp1Height, err = rollapp1.Height(ctx)
require.NoError(t, err)

isFinalized, err := dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollapp1Height, 300)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down Expand Up @@ -549,15 +549,15 @@ func TestEIBCPFM_Wasm(t *testing.T) {
tx, err := rollapp1.SendIBCTransfer(ctx, channRollApp1Dym.ChannelID, rollapp1User.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

rollapp1Height, err := rollapp1.Height(ctx)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, rollapp1, rollapp1Height, rollapp1Height+30, tx.Packet)
require.NoError(t, err)

rollapp1Height, err = rollapp1.Height(ctx)
require.NoError(t, err)

isFinalized, err := dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollapp1Height, 300)
require.NoError(t, err)
require.True(t, isFinalized)
Expand Down
Loading

0 comments on commit 264f5ae

Please sign in to comment.