Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix ack_err tests #417

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 91 additions & 39 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 @@ -746,7 +754,7 @@ func TestEIBC_AckError_RA_Token_EVM(t *testing.T) {
require.True(t, bytes.Contains(ack.Acknowledgement, []byte("error")))

// We transfered once to enable ibc-transfer from dym to rollapp
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount))
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount).Sub(bigTransferAmount))

// 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 Expand Up @@ -801,7 +809,7 @@ func TestEIBC_AckError_RA_Token_EVM(t *testing.T) {

// wait for a few blocks and check if the fund returns to rollapp
testutil.WaitForBlocks(ctx, 20, rollapp1)
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferAmount))
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferAmount).Sub(bigTransferAmount))
})
}

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 @@ -1952,7 +1981,7 @@ func TestEIBC_AckError_RA_Token_Wasm(t *testing.T) {
require.True(t, bytes.Contains(ack.Acknowledgement, []byte("error")))

// We transfered once to enable ibc-transfer from dym to rollapp
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount))
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount).Sub(bigTransferAmount))

// 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 Expand Up @@ -2007,7 +2036,7 @@ func TestEIBC_AckError_RA_Token_Wasm(t *testing.T) {

// wait for a few blocks and check if the fund returns to rollapp
testutil.WaitForBlocks(ctx, 20, rollapp1)
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferAmount))
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferAmount).Sub(bigTransferAmount))
})
}

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
20 changes: 14 additions & 6 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, 30, 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 @@ -1437,7 +1437,7 @@ func TestEIBCUpdateOnAckErrAndTimeout_EVM(t *testing.T) {
balance, err = dymension.GetBalance(ctx, marketMakerAddr, dymension.Config().Denom)
require.NoError(t, err)
fmt.Println("Balance of marketMakerAddr after fulfilling the order:", balance)
expBalanceMarketMaker := walletAmount.Add((globalEIbcFee.Mul(math.NewInt(2))))
expBalanceMarketMaker := walletAmount.Add(globalEIbcFee.Mul(math.NewInt(2))).Sub(transferAmount)
require.True(t, balance.Equal(expBalanceMarketMaker), fmt.Sprintf("Value mismatch. Expected %s, actual %s", expBalanceMarketMaker, balance))

t.Cleanup(
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 Expand Up @@ -1652,7 +1660,7 @@ func TestEIBCUpdateOnAckErrAndTimeout_Wasm(t *testing.T) {
require.NoError(t, err)

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

// get eibc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 30, false)
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 20, false)
require.NoError(t, err)
fmt.Println("Event:", eibcEvents)
require.Equal(t, eibcEvents[0].Price, fmt.Sprintf("%s%s", transferAmountWithoutFee, dymension.Config().Denom))
Expand Down Expand Up @@ -2149,7 +2157,7 @@ func TestEIBCUpdateOnTimeout_Unallowed_Wasm(t *testing.T) {
require.NoError(t, err)

// get eibc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 50, false)
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 20, false)
require.NoError(t, err)
fmt.Println("Event:", eibcEvents)
require.Equal(t, eibcEvents[0].Price, fmt.Sprintf("%s%s", transferAmountWithoutFee, dymension.Config().Denom))
Expand Down
26 changes: 7 additions & 19 deletions tests/eibc_fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1688,20 +1688,6 @@ func TestEIBCFulfillment_two_rollapps_EVM(t *testing.T) {
fmt.Println("Balance of dymensionUserAddr right after sending eIBC transfer from rollapp 2 to dym hub:", balance)
require.True(t, balance.Equal(zeroBalance), fmt.Sprintf("Value mismatch. Expected %s, actual %s", zeroBalance, balance))

// get eIbc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 30, false)
require.NoError(t, err)
require.Equal(t, eibcEvents[len(eibcEvents)-1].PacketStatus, "PENDING")

// fulfill demand order 1
txhash, err := dymension.FullfillDemandOrder(ctx, eibcEvents[len(eibcEvents)-1].OrderId, marketMakerAddr, eibcFee)
require.NoError(t, err)
fmt.Println(txhash)
eibcEvent := getEibcEventFromTx(t, dymension, txhash)
if eibcEvent != nil {
fmt.Println("After order fulfillment:", eibcEvent)
}

_, err = rollapp1.SendIBCTransfer(ctx, dymChannel_ra1[0].ChannelID, rollappUserAddr, transferDataRollapp1, options)
require.NoError(t, err)

Expand All @@ -1711,16 +1697,19 @@ func TestEIBCFulfillment_two_rollapps_EVM(t *testing.T) {
require.True(t, balance.Equal(zeroBalance), fmt.Sprintf("Value mismatch. Expected %s, actual %s", zeroBalance, balance))

// get eIbc event
eibcEvents, err = getEIbcEventsWithinBlockRange(ctx, dymension, 50, false)
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 50, false)
fmt.Println(eibcEvents)
require.NoError(t, err)
require.Equal(t, "PENDING", eibcEvents[0].PacketStatus)
require.Equal(t, "PENDING", eibcEvents[1].PacketStatus)

// fulfill demand order 2
txhash, err = dymension.FullfillDemandOrder(ctx, eibcEvents[1].OrderId, marketMakerAddr, eibcFee)
_, err = dymension.FullfillDemandOrder(ctx, eibcEvents[1].OrderId, marketMakerAddr, eibcFee)
require.NoError(t, err)
fmt.Println(txhash)
eibcEvent = getEibcEventFromTx(t, dymension, txhash)
txhash, err := dymension.FullfillDemandOrder(ctx, eibcEvents[0].OrderId, marketMakerAddr, eibcFee)
require.NoError(t, err)

eibcEvent := getEibcEventFromTx(t, dymension, txhash)
if eibcEvent != nil {
fmt.Println("After order fulfillment:", eibcEvent)
}
Expand Down Expand Up @@ -1750,7 +1739,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
2 changes: 1 addition & 1 deletion tests/eibc_not_fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func TestEIBCNotFulfillment_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

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

// Get the IBC denom for urax on Hub
Expand Down
2 changes: 1 addition & 1 deletion tests/eibc_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func TestEIBCTimeoutFulFillDymToRollapp_EVM(t *testing.T) {
require.NoError(t, err)

// get eibc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 80, false)
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 50, false)
require.NoError(t, err)
fmt.Println("Event:", eibcEvents[0])
require.Equal(t, eibcEvents[0].Price, fmt.Sprintf("%s%s", transferAmountWithoutFee, gaiaIBCDenom))
Expand Down
12 changes: 0 additions & 12 deletions tests/ibc_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ 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)
require.NoError(t, err)

// Assert funds were returned to the sender after the timeout has occured
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount))
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee))
Expand Down Expand Up @@ -244,9 +241,6 @@ func TestIBCTransferTimeout_EVM(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

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

// Assert funds were returned to the sender after the timeout has occured
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal)
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount)
Expand Down Expand Up @@ -445,9 +439,6 @@ 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)
require.NoError(t, err)

// Assert funds were returned to the sender after the timeout has occured
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount))
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee))
Expand Down Expand Up @@ -484,9 +475,6 @@ func TestIBCTransferTimeout_Wasm(t *testing.T) {
require.NoError(t, err)
require.True(t, isFinalized)

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

// Assert funds were returned to the sender after the timeout has occured
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal)
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount)
Expand Down
Loading