Skip to content

Commit

Permalink
fix ack_err tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Sep 16, 2024
1 parent c5269d3 commit 7af97f8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 42 deletions.
122 changes: 87 additions & 35 deletions tests/eibc_ack_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,6 @@ func TestEIBC_AckError_Dym_EVM(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 3, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err := rollapp1.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)

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

testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Sub(transferData.Amount))
erc20MAcc, err := rollapp1.Validators[0].QueryModuleAccount(ctx, "erc20")
require.NoError(t, err)
Expand Down Expand Up @@ -672,6 +661,26 @@ func TestEIBC_AckError_RA_Token_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

valAddr, err := dymension.Validators[0].AccountKeyBech32(ctx, "validator")
require.NoError(t, err)

transferData = ibc.WalletData{
Address: valAddr,
Denom: rollapp1.Config().Denom,
Amount: bigTransferAmount,
}

_, err = rollapp1.SendIBCTransfer(ctx, channRollApp1Dym.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

rollappHeight, err = rollapp1.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)

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

Expand All @@ -692,9 +701,8 @@ func TestEIBC_AckError_RA_Token_EVM(t *testing.T) {
require.NoError(t, err)

testutil.AssertBalance(t, ctx, dymension, marketMakerAddr, rollappIBCDenom, transferAmount)
// end of preconditions

//
// end of preconditions
// prop to disable ibc transfer on rollapp
receiveEnableParams := json.RawMessage(`false`)
_, err = dymension.GetNode().ParamChangeProposal(ctx, dymensionUser.KeyName(),
Expand Down Expand Up @@ -1047,6 +1055,29 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

valAddr, err := dymension.Validators[0].AccountKeyBech32(ctx, "validator")
require.NoError(t, err)

transferData = ibc.WalletData{
Address: valAddr,
Denom: rollapp2.Config().Denom,
Amount: bigTransferAmount,
}

_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

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

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

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

var options ibc.TransferOptions

// register ibc denom on rollapp1
Expand Down Expand Up @@ -1120,17 +1151,6 @@ func TestEIBC_AckError_3rd_Party_Token_EVM(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 3, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err := rollapp1.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)

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

erc20MAcc, err := rollapp1.Validators[0].QueryModuleAccount(ctx, "erc20")
require.NoError(t, err)
erc20MAccAddr := erc20MAcc.Account.BaseAccount.Address
Expand Down Expand Up @@ -1517,17 +1537,6 @@ func TestEIBC_AckError_Dym_Wasm(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 3, dymension, rollapp1)
require.NoError(t, err)

rollappHeight, err := rollapp1.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)

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

testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Sub(transferData.Amount))
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, transferAmount)

Expand Down Expand Up @@ -1881,6 +1890,26 @@ func TestEIBC_AckError_RA_Token_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

valAddr, err := dymension.Validators[0].AccountKeyBech32(ctx, "validator")
require.NoError(t, err)

transferData = ibc.WalletData{
Address: valAddr,
Denom: rollapp1.Config().Denom,
Amount: bigTransferAmount,
}

_, err = rollapp1.SendIBCTransfer(ctx, channRollApp1Dym.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

rollappHeight, err = rollapp1.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)

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

Expand Down Expand Up @@ -2253,6 +2282,29 @@ func TestEIBC_AckError_3rd_Party_Token_Wasm(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

valAddr, err := dymension.Validators[0].AccountKeyBech32(ctx, "validator")
require.NoError(t, err)

transferData = ibc.WalletData{
Address: valAddr,
Denom: rollapp2.Config().Denom,
Amount: bigTransferAmount,
}

_, err = rollapp2.SendIBCTransfer(ctx, channRollApp2Dym.ChannelID, rollapp2UserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

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

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

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

var options ibc.TransferOptions

t.Run("Demand order is created upon AckError for rollapp token", func(t *testing.T) {
Expand Down
12 changes: 10 additions & 2 deletions tests/eibc_feemarket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ func TestEIBCUpdateOnAckErrAndTimeout_EVM(t *testing.T) {
require.NoError(t, err)

// get eibc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 70, false)
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 50, false)
require.NoError(t, err)
fmt.Println(eibcEvents)
require.Equal(t, eibcEvents[0].Price, fmt.Sprintf("%s%s", transferAmountWithoutFee, dymension.Config().Denom))
Expand Down Expand Up @@ -1472,6 +1472,14 @@ func TestEIBCUpdateOnAckErrAndTimeout_Wasm(t *testing.T) {

configFileOverrides["config/dymint.toml"] = dymintTomlOverrides

modifyGenesisKV := append(
dymensionGenesisKV,
cosmos.GenesisKV{
Key: "app_state.rollapp.params.dispute_period_in_blocks",
Value: fmt.Sprint(100),
},
)

// Create chain factory with dymension
numHubVals := 1
numHubFullNodes := 1
Expand Down Expand Up @@ -1517,7 +1525,7 @@ func TestEIBCUpdateOnAckErrAndTimeout_Wasm(t *testing.T) {
GasAdjustment: 1.1,
TrustingPeriod: "112h",
NoHostMount: false,
ModifyGenesis: modifyDymensionGenesis(dymensionGenesisKV),
ModifyGenesis: modifyDymensionGenesis(modifyGenesisKV),
ConfigFileOverrides: nil,
},
NumValidators: &numHubVals,
Expand Down
1 change: 0 additions & 1 deletion tests/eibc_fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,6 @@ func TestEIBCFulfillment_two_rollapps_EVM(t *testing.T) {
balance, err = dymension.GetBalance(ctx, marketMakerAddr, rollapp2IBCDenom)
require.NoError(t, err)
fmt.Println("Balance of marketMakerAddr after fulfilling the order:", balance)
expMmBalanceRollappDenom = expMmBalanceRollappDenom.Add(transferAmount).Sub(bridgingFee)
require.True(t, balance.Equal(expMmBalanceRollappDenom), fmt.Sprintf("Value mismatch. Expected %s, actual %s", expMmBalanceRollappDenom, balance))

t.Cleanup(
Expand Down
8 changes: 4 additions & 4 deletions tests/ibc_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestIBCTransferTimeout_EVM(t *testing.T) {
rollappTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, rollapp1.Config().Denom)
rollappIBCDenom := transfertypes.ParseDenomTrace(rollappTokenDenom).IBCDenom()

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

// Assert funds were returned to the sender after the timeout has occured
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestIBCTransferTimeout_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

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

// Assert funds were returned to the sender after the timeout has occured
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestIBCTransferTimeout_Wasm(t *testing.T) {
rollappTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, rollapp1.Config().Denom)
rollappIBCDenom := transfertypes.ParseDenomTrace(rollappTokenDenom).IBCDenom()

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

// Assert funds were returned to the sender after the timeout has occured
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestIBCTransferTimeout_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

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

// Assert funds were returned to the sender after the timeout has occured
Expand Down

0 comments on commit 7af97f8

Please sign in to comment.