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

Additional EIBC tests #22

Merged
merged 39 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7177aed
eibc basic order fulfillment test
pgoos Feb 29, 2024
f943bc0
adjust function call
pgoos Feb 29, 2024
9783a8c
remove debug code
pgoos Feb 29, 2024
30062b8
exec tx from fullnode
anhductn2001 Mar 1, 2024
9cb1abe
add eibc encoding
anhductn2001 Mar 4, 2024
76d605c
revert image tag
anhductn2001 Mar 4, 2024
52880d3
improve test case flow
pgoos Mar 4, 2024
2d8cfe4
add assertion mismatch message
pgoos Mar 4, 2024
1c6f5c3
add new test to workflow file
pgoos Mar 4, 2024
ebf44e2
eibc corrupted memo test case
pgoos Mar 4, 2024
ebfaf05
add test case where fee is more than a transfer amount
pgoos Mar 5, 2024
6205124
add more tests
pgoos Mar 5, 2024
bf2be5e
check if an order can be fulfilled more than once
pgoos Mar 5, 2024
43e32e9
cleanup
pgoos Mar 5, 2024
7b17a4d
add eibc timeout test case
pgoos Mar 5, 2024
1010053
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 6, 2024
587d93b
add more eibc scenarios
pgoos Mar 6, 2024
0a12944
add new tests to workflow files
pgoos Mar 6, 2024
044dd48
fix function name
pgoos Mar 7, 2024
057fc86
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 13, 2024
19ad4de
adjust to rollap-evm
pgoos Mar 13, 2024
5bea20d
update eibc timeout case
pgoos Mar 14, 2024
aaf91ee
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 14, 2024
b9bef2a
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 15, 2024
a0d5b93
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 18, 2024
e8a89b2
update go.mod
pgoos Mar 18, 2024
ad65ff6
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 18, 2024
721130b
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 18, 2024
8dd0c10
improve waiting time for rollapp state finalization
pgoos Mar 18, 2024
9a7cce6
fix eibc timeout scenario
pgoos Mar 19, 2024
7a94dbe
Merge branch 'main' into feat/eibc-tests-2
pgoos Mar 19, 2024
9fc093a
Merge branch 'main' into feat/eibc-tests-2
anhductn2001 Apr 17, 2024
518a06d
set empty_block and set up relayer
anhductn2001 Apr 17, 2024
639c242
update workflow
anhductn2001 Apr 17, 2024
38e235a
cointype 60 and decrease dispute_blocks
anhductn2001 Apr 17, 2024
a756979
trigger genesis event
anhductn2001 Apr 19, 2024
38f45af
trigger genesis event
anhductn2001 Apr 19, 2024
ef0b34a
trigger genesis event
anhductn2001 Apr 19, 2024
3cacb08
fix wrong condition
anhductn2001 Apr 19, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/e2e-test-workflow-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
- "e2e-test-rollapp-freeze-evm"
- "e2e-test-other-rollapp-not-affected-evm"
- "e2e-test-rollapp-genesis-event-evm"
- "e2e-test-eibc-fulfill-no-balance"
- "e2e-test-eibc-corrupted-memo"
- "e2e-test-eibc-excessive-fee"
pgoos marked this conversation as resolved.
Show resolved Hide resolved
- "e2e-test-eibc-timeout"
fail-fast: false
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- "e2e-test-rollapp-freeze-evm"
- "e2e-test-other-rollapp-not-affected-evm"
- "e2e-test-rollapp-genesis-event-evm"
- "e2e-test-eibc-fulfill-no-balance-evm"
- "e2e-test-eibc-corrupted-memo-evm"
- "e2e-test-eibc-excessive-fee-evm"
- "e2e-test-eibc-timeout-evm"
fail-fast: false
runs-on: ubuntu-latest
steps:
Expand Down
33 changes: 28 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ e2e-test-ibc-timeout-evm: clean-e2e
e2e-test-eibc-fulfillment-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestEIBCFulfillment_EVM .


# Executes IBC tests via rollup-e2e-testing
e2e-test-ibc-grace-period-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestIBCGracePeriodCompliance_EVM .

# Executes IBC tests via rollup-e2e-testing
e2e-test-eibc-fulfill-no-balance-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestEIBCNoBalanceToFulfillOrder .

# Executes IBC tests via rollup-e2e-testing
e2e-test-eibc-corrupted-memo-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestEIBCCorruptedMemoNegative .

# Executes IBC tests via rollup-e2e-testing
e2e-test-eibc-excessive-fee-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestEIBCFeeTooHigh .

e2e-test-eibc-timeout-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestEIBCTimeoutHubToRollapp .

e2e-test-transfer-multi-hop-evm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestIBCTransferMultiHop_EVM .

Expand Down Expand Up @@ -71,7 +87,6 @@ e2e-test-rollapp-freeze-wasm: clean-e2e
e2e-test-other-rollapp-not-affected-wasm: clean-e2e
cd tests && go test -timeout=25m -race -v -run TestOtherRollappNotAffected_Wasm .

# Executes all tests via rollup-e2e-testing
e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-ibc-timeout-evm \
e2e-test-ibc-grace-period-evm \
Expand All @@ -80,7 +95,11 @@ e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-pfm-with-grace-period-evm \
e2e-test-batch-finalization-evm \
e2e-test-rollapp-freeze-evm \
e2e-test-other-rollapp-not-affected-evm \
e2e-test-other-rollapp-not-affected-evm \
e2e-test-eibc-fulfill-no-balance \
e2e-test-eibc-corrupted-memo \
e2e-test-eibc-excessive-fee \
e2e-test-eibc-timeout \
e2e-test-ibc-success-wasm \
e2e-test-ibc-timeout-wasm \
e2e-test-ibc-grace-period-wasm \
Expand All @@ -89,7 +108,7 @@ e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-pfm-with-grace-period-wasm \
e2e-test-batch-finalization-wasm \
e2e-test-rollapp-freeze-wasm \
e2e-test-other-rollapp-not-affected-wasm
e2e-test-other-rollapp-not-affected-wasm

.PHONY: clean-e2e \
e2e-test-all \
Expand All @@ -101,7 +120,11 @@ e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-pfm-with-grace-period-evm \
e2e-test-batch-finalization-evm \
e2e-test-rollapp-freeze-evm \
e2e-test-other-rollapp-not-affected-evm \
e2e-test-other-rollapp-not-affected-evm \
e2e-test-eibc-fulfill-no-balance \
e2e-test-eibc-corrupted-memo \
e2e-test-eibc-excessive-fee \
e2e-test-eibc-timeout \
e2e-test-ibc-success-wasm \
e2e-test-ibc-timeout-wasm \
e2e-test-ibc-grace-period-wasm \
Expand All @@ -110,4 +133,4 @@ e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-pfm-with-grace-period-wasm \
e2e-test-batch-finalization-wasm \
e2e-test-rollapp-freeze-wasm \
e2e-test-other-rollapp-not-affected-wasm
e2e-test-other-rollapp-not-affected-wasm
262 changes: 262 additions & 0 deletions tests/eibc_corrupted_memo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
package tests

import (
"context"
"fmt"
"testing"

"cosmossdk.io/math"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
test "github.com/decentrio/rollup-e2e-testing"
"github.com/decentrio/rollup-e2e-testing/cosmos"
"github.com/decentrio/rollup-e2e-testing/cosmos/hub/dym_hub"
"github.com/decentrio/rollup-e2e-testing/cosmos/rollapp/dym_rollapp"
"github.com/decentrio/rollup-e2e-testing/ibc"

"github.com/decentrio/rollup-e2e-testing/relayer"
"github.com/decentrio/rollup-e2e-testing/testreporter"
"github.com/decentrio/rollup-e2e-testing/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

// This test case verifies the system's behavior when an eIBC packet sent from the rollapp to the hub
// that has incorrect memo data
func TestEIBCCorruptedMemoNegative(t *testing.T) {
if testing.Short() {
t.Skip()
}

ctx := context.Background()

configFileOverrides := make(map[string]any)
dymintTomlOverrides := make(testutil.Toml)
dymintTomlOverrides["settlement_layer"] = "dymension"
dymintTomlOverrides["node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name())
dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1"
dymintTomlOverrides["gas_prices"] = "0adym"
dymintTomlOverrides["empty_blocks_max_time"] = "3s"

configFileOverrides["config/dymint.toml"] = dymintTomlOverrides
const BLOCK_FINALITY_PERIOD = 50
modifyGenesisKV := append(
dymensionGenesisKV,
cosmos.GenesisKV{
Key: "app_state.rollapp.params.dispute_period_in_blocks",
Value: fmt.Sprint(BLOCK_FINALITY_PERIOD),
},
)

// Create chain factory with dymension
numHubVals := 1
numHubFullNodes := 1
numRollAppFn := 0
numRollAppVals := 1
cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{
{
Name: "rollapp1",
ChainConfig: ibc.ChainConfig{
Type: "rollapp-dym",
Name: "rollapp-temp",
ChainID: "rollappevm_1234-1",
Images: []ibc.DockerImage{rollappEVMImage},
Bin: "rollappd",
Bech32Prefix: "ethm",
Denom: "urax",
CoinType: "60",
GasPrices: "0.0urax",
GasAdjustment: 1.1,
TrustingPeriod: "112h",
EncodingConfig: encodingConfig(),
NoHostMount: false,
ModifyGenesis: modifyRollappEVMGenesis(rollappEVMGenesisKV),
ConfigFileOverrides: configFileOverrides,
},
NumValidators: &numRollAppVals,
NumFullNodes: &numRollAppFn,
},
{
Name: "dymension-hub",
ChainConfig: ibc.ChainConfig{
Type: "hub-dym",
Name: "dymension",
ChainID: "dymension_100-1",
Images: []ibc.DockerImage{dymensionImage},
Bin: "dymd",
Bech32Prefix: "dym",
Denom: "adym",
CoinType: "60",
GasPrices: "0.0adym",
EncodingConfig: encodingConfig(),
GasAdjustment: 1.1,
TrustingPeriod: "112h",
NoHostMount: false,
ModifyGenesis: modifyDymensionGenesis(modifyGenesisKV),
ConfigFileOverrides: nil,
},
NumValidators: &numHubVals,
NumFullNodes: &numHubFullNodes,
},
})

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

rollapp1 := chains[0].(*dym_rollapp.DymRollApp)
dymension := chains[1].(*dym_hub.DymHub)

// Relayer Factory
client, network := test.DockerSetup(t)
r := test.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t),
relayer.CustomDockerImage("ghcr.io/decentrio/relayer", "e2e-amd", "100:1000"),
).Build(t, client, "relayer", network)
const ibcPath = "ibc-path"
ic := test.NewSetup().
AddRollUp(dymension, rollapp1).
AddRelayer(r, "relayer").
AddLink(test.InterchainLink{
Chain1: dymension,
Chain2: rollapp1,
Relayer: r,
Path: ibcPath,
})

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

err = ic.Build(ctx, eRep, test.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,

// This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc.
// BlockDatabaseFile: test.DefaultBlockDatabaseFilepath(),
})
require.NoError(t, err)

err = r.GeneratePath(ctx, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID, ibcPath)
require.NoError(t, err)

err = r.CreateClients(ctx, eRep, ibcPath, ibc.DefaultClientOpts())
require.NoError(t, err)

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

r.UpdateClients(ctx, eRep, ibcPath)
require.NoError(t, err)

err = r.CreateConnections(ctx, eRep, ibcPath)
require.NoError(t, err)

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

err = r.CreateChannel(ctx, eRep, ibcPath, ibc.DefaultChannelOpts())
require.NoError(t, err)

walletAmount := math.NewInt(1_000_000_000_000)

// Create some user accounts on both chains
users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, dymension, dymension, rollapp1)

// Wait a few blocks for relayer to start and for user accounts to be created
err = testutil.WaitForBlocks(ctx, 5, dymension, rollapp1)
require.NoError(t, err)

// Get our Bech32 encoded user addresses
dymensionUser, dymensionUser2, dymensionUser3, rollappUser := users[0], users[1], users[2], users[3]

dymensionUserAddr := dymensionUser.FormattedAddress()
dymensionUserAddr2 := dymensionUser2.FormattedAddress()
dymensionUserAddr3 := dymensionUser3.FormattedAddress()
rollappUserAddr := rollappUser.FormattedAddress()

// Assert the accounts were funded
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount)
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr2, dymension.Config().Denom, walletAmount)
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr3, dymension.Config().Denom, walletAmount)
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount)

transferAmount := math.NewInt(1_000_000)

channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID)
require.NoError(t, err)

rollapp := rollappParam{
rollappID: rollapp1.Config().ChainID,
channelID: channel.ChannelID,
userKey: dymensionUser.KeyName(),
}
triggerHubGenesisEvent(t, dymension, rollapp)

err = r.StartRelayer(ctx, eRep, ibcPath)
require.NoError(t, err)

// Get the IBC denom for urax on Hub
rollappTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, rollapp1.Config().Denom)
rollappIBCDenom := transfertypes.ParseDenomTrace(rollappTokenDenom).IBCDenom()
// end of preconditions

var options ibc.TransferOptions
// set eIBC specific memo

multiplier := math.NewInt(10)
eibcFee := transferAmount.Quo(multiplier) // transferAmount * 0.1

options.Memo = BuildEIbcMemo(eibcFee)
transferData := ibc.WalletData{
Address: dymensionUserAddr,
Denom: rollapp1.Config().Denom,
Amount: transferAmount,
}
_, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

invalidMemo2 := `{"eibc": {"feebaba": "200"}}`
options.Memo = invalidMemo2
transferData = ibc.WalletData{
Address: dymensionUserAddr2,
Denom: rollapp1.Config().Denom,
Amount: transferAmount,
}
_, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

invalidMemo3 := `{"eibc": {"fee": "this-should-be-number"}}`
options.Memo = invalidMemo3
transferData = ibc.WalletData{
Address: dymensionUserAddr3,
Denom: rollapp1.Config().Denom,
Amount: transferAmount,
}
_, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

// get eIbc events
eibcEvents, _ := getEIbcEventsWithinBlockRange(ctx, dymension, 30, false)
require.True(t, len(eibcEvents) == 1) // verify 1 EIBC event was registered on the hub

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)

testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferData.Amount)
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr2, rollappIBCDenom, math.NewInt(0))
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr3, rollappIBCDenom, math.NewInt(0))

t.Cleanup(
func() {
err := r.StopRelayer(ctx, eRep)
if err != nil {
t.Logf("an error occurred while stopping the relayer: %s", err)
}
},
)

}
Loading
Loading