From 8aec813dfead7860ab89f5a00e0abcee5715896b Mon Sep 17 00:00:00 2001 From: anhductn2001 Date: Mon, 14 Oct 2024 12:38:19 +0700 Subject: [PATCH 1/2] add TestGenesisBridgeInvalid --- Makefile | 3 + tests/genesis_bridge_test.go | 874 +++++++++++++++++++++++++++++++++ tests/genesis_transfer_test.go | 644 ------------------------ 3 files changed, 877 insertions(+), 644 deletions(-) create mode 100644 tests/genesis_bridge_test.go delete mode 100644 tests/genesis_transfer_test.go diff --git a/Makefile b/Makefile index 973b37f9..e59e160f 100644 --- a/Makefile +++ b/Makefile @@ -218,6 +218,9 @@ e2e-test-rollapp-genesis-transfer-bridge-blocking-evm: clean-e2e e2e-test-rollapp-genesis-transfer-connection-blocking-evm: clean-e2e cd tests && go test -timeout=45m -race -v -run TestGenesisTransferConnectionBlock_EVM . +e2e-test-genesis-bridge-invalid-evm: clean-e2e + cd tests && go test -timeout=45m -race -v -run TestGenesisBridgeInvalid_EVM . + e2e-test-non-rollapp-unaffected-evm: clean-e2e cd tests && go test -timeout=45m -race -v -run Test_Non_Rollappchain_Unaffected_EVM . diff --git a/tests/genesis_bridge_test.go b/tests/genesis_bridge_test.go new file mode 100644 index 00000000..15d4360b --- /dev/null +++ b/tests/genesis_bridge_test.go @@ -0,0 +1,874 @@ +package tests + +import ( + "context" + "fmt" + "testing" + + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" + + 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" +) + +// TestGenesisTransfer_EVM +func TestGenesisTransferBridgeBlocking_EVM(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // 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: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.NoError(t, err) + + CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) + + // Create some user accounts on both chains + users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) + + // Get our Bech32 encoded user addresses + dymensionUser, rollappUser := users[0], users[1] + + dymensionUserAddr := dymensionUser.FormattedAddress() + rollappUserAddr := rollappUser.FormattedAddress() + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) + require.NoError(t, err) + + err = r.StartRelayer(ctx, eRep, ibcPath) + require.NoError(t, err) + + // Send a normal ibc tx from RA -> Hub + transferData := ibc.WalletData{ + Address: dymensionUserAddr, + Denom: rollapp1.Config().Denom, + Amount: transferAmount, + } + _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) + require.Error(t, err) + + // Compose an IBC transfer and send from dymension -> rollapp + transferData = ibc.WalletData{ + Address: rollappUserAddr, + Denom: dymension.Config().Denom, + Amount: transferAmount, + } + + // Compose an IBC transfer and send from Hub -> rollapp + _, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{}) + require.Error(t, err) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + require.NoError(t, err) + + // Get the IBC denom + dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom) + dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom() + + // 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() + + // after a while, refund token + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount) + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, zeroBal) + + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount) + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal) + + // Run invariant check + CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) +} + +func TestGenesisTransferBridgeBlocking_Wasm(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappwasm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // 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: "rollappwasm_1234-1", + Images: []ibc.DockerImage{rollappWasmImage}, + Bin: "rollappd", + Bech32Prefix: "rol", + Denom: "urax", + CoinType: "118", + GasPrices: "0.0urax", + GasAdjustment: 1.1, + TrustingPeriod: "112h", + EncodingConfig: encodingConfig(), + NoHostMount: false, + ModifyGenesis: modifyRollappWasmGenesis(rollappWasmGenesisKV), + ConfigFileOverrides: configFileOverrides, + }, + NumValidators: &numRollAppVals, + NumFullNodes: &numRollAppFn, + }, + { + Name: "dymension-hub", + ChainConfig: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.NoError(t, err) + + CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) + + // Create some user accounts on both chains + users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) + + // Get our Bech32 encoded user addresses + dymensionUser, rollappUser := users[0], users[1] + + dymensionUserAddr := dymensionUser.FormattedAddress() + rollappUserAddr := rollappUser.FormattedAddress() + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) + require.NoError(t, err) + + err = r.StartRelayer(ctx, eRep, ibcPath) + require.NoError(t, err) + + // Send a normal ibc tx from RA -> Hub + transferData := ibc.WalletData{ + Address: dymensionUserAddr, + Denom: rollapp1.Config().Denom, + Amount: transferAmount, + } + _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) + require.Error(t, err) + + // Compose an IBC transfer and send from dymension -> rollapp + transferData = ibc.WalletData{ + Address: rollappUserAddr, + Denom: dymension.Config().Denom, + Amount: transferAmount, + } + + // Compose an IBC transfer and send from Hub -> rollapp + _, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{}) + require.Error(t, err) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + require.NoError(t, err) + + // Get the IBC denom + dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom) + dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom() + + // 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() + + // after a while, refund token + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount) + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, zeroBal) + + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount) + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal) + + // Run invariant check + CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) +} + +func TestGenesisTransferConnectionBlock_EVM(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // 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: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.NoError(t, err) + + CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) + + // Create some user accounts on both chains + users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) + + // Get our Bech32 encoded user addresses + dymensionUser, rollappUser := users[0], users[1] + + dymensionUserAddr := dymensionUser.FormattedAddress() + rollappUserAddr := rollappUser.FormattedAddress() + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) + require.NoError(t, err) + + err = r.StartRelayer(ctx, eRep, ibcPath) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + require.NoError(t, err) + + // Send a normal ibc tx from RA -> Hub + transferData := ibc.WalletData{ + Address: dymensionUserAddr, + Denom: rollapp1.Config().Denom, + Amount: transferAmount, + } + _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) + require.NoError(t, err) + + rollappHeight, err := rollapp1.GetNode().Height(ctx) + require.NoError(t, err) + + // Assert balance was updated on the hub + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount)) + + // 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) + + // 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() + + // Minus 0.1% of transfer amount for bridge fee + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) + + // Try to open a connection with the relayer with RA as chainA + err = r.GeneratePath(ctx, eRep, rollapp1.Config().ChainID, dymension.Config().ChainID, "demo-dymension") + require.NoError(t, err) + + err = r.CreateClients(ctx, eRep, "demo-dymension", ibc.DefaultClientOpts()) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 20, rollapp1, dymension) + require.NoError(t, err) + + err = r.CreateConnectionsWithNumberOfRetries(ctx, eRep, "demo-dymension", "3") + require.NoError(t, err) + + connections, err := r.GetConnections(ctx, eRep, dymension.Config().ChainID) + require.NoError(t, err) + require.Equal(t, 1, len(connections)) + + // Run invariant check + CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) +} + +func TestGenesisTransferConnectionBlock_Wasm(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappwasm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // 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: "rollappwasm_1234-1", + Images: []ibc.DockerImage{rollappWasmImage}, + Bin: "rollappd", + Bech32Prefix: "rol", + Denom: "urax", + CoinType: "118", + GasPrices: "0.0urax", + GasAdjustment: 1.1, + TrustingPeriod: "112h", + EncodingConfig: encodingConfig(), + NoHostMount: false, + ModifyGenesis: modifyRollappWasmGenesis(rollappWasmGenesisKV), + ConfigFileOverrides: configFileOverrides, + }, + NumValidators: &numRollAppVals, + NumFullNodes: &numRollAppFn, + }, + { + Name: "dymension-hub", + ChainConfig: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.NoError(t, err) + + CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) + + // Create some user accounts on both chains + users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) + + // Get our Bech32 encoded user addresses + dymensionUser, rollappUser := users[0], users[1] + + dymensionUserAddr := dymensionUser.FormattedAddress() + rollappUserAddr := rollappUser.FormattedAddress() + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) + require.NoError(t, err) + + err = r.StartRelayer(ctx, eRep, ibcPath) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + require.NoError(t, err) + + // Send a normal ibc tx from RA -> Hub + transferData := ibc.WalletData{ + Address: dymensionUserAddr, + Denom: rollapp1.Config().Denom, + Amount: transferAmount, + } + _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) + require.NoError(t, err) + + rollappHeight, err := rollapp1.GetNode().Height(ctx) + require.NoError(t, err) + + // Assert balance was updated on the hub + testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount)) + + // 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) + + // 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() + + // Minus 0.1% of transfer amount for bridge fee + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) + + // Try to open a connection with the relayer with RA as chainA + err = r.GeneratePath(ctx, eRep, rollapp1.Config().ChainID, dymension.Config().ChainID, "demo-dymension") + require.NoError(t, err) + + err = r.CreateClients(ctx, eRep, "demo-dymension", ibc.DefaultClientOpts()) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 20, rollapp1, dymension) + require.NoError(t, err) + + err = r.CreateConnectionsWithNumberOfRetries(ctx, eRep, "demo-dymension", "3") + require.NoError(t, err) + + connections, err := r.GetConnections(ctx, eRep, dymension.Config().ChainID) + require.NoError(t, err) + require.Equal(t, 1, len(connections)) + + // Run invariant check + CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) +} + +// TestGenesisBridgeInvalid_EVM +func TestGenesisBridgeInvalid_EVM(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // Create chain factory with dymension + numHubVals := 1 + numHubFullNodes := 1 + numRollAppFn := 0 + numRollAppVals := 1 + + modifyEVMGenesisKV := append( + rollappEVMGenesisKV, + cosmos.GenesisKV{ + Key: "app_state.hubgenesis.genesis_accounts", + Value: []interface{}{ + map[string]interface{}{ + "address": "dym10hg2t064m9atzw46m4f8lyjmnfpyvmnt4ulmzf", + "amount": "100000000000000000", + }, + }, + }, + ) + + 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(modifyEVMGenesisKV), + ConfigFileOverrides: configFileOverrides, + }, + NumValidators: &numRollAppVals, + NumFullNodes: &numRollAppFn, + }, + { + Name: "dymension-hub", + ChainConfig: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.Error(t, err) +} + +// TestIBCTransferSuccess ensure that the transfer between Hub and Rollapp is accurate. +func TestGenesisBridgeInvalid_Wasm(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) + dymintTomlOverrides["rollapp_id"] = "rollappwasm_1234-1" + dymintTomlOverrides["settlement_gas_prices"] = "0adym" + dymintTomlOverrides["max_idle_time"] = "3s" + dymintTomlOverrides["max_proof_time"] = "500ms" + dymintTomlOverrides["batch_submit_time"] = "50s" + + configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + // Create chain factory with dymension + numHubVals := 1 + numHubFullNodes := 1 + numRollAppFn := 0 + numRollAppVals := 1 + + modifyWasmGenesisKV := append( + rollappEVMGenesisKV, + cosmos.GenesisKV{ + Key: "app_state.hubgenesis.genesis_accounts", + Value: []interface{}{ + map[string]interface{}{ + "address": "dym10hg2t064m9atzw46m4f8lyjmnfpyvmnt4ulmzf", + "amount": "100000000000000000", + }, + }, + }, + ) + + cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{ + { + Name: "rollapp1", + ChainConfig: ibc.ChainConfig{ + Type: "rollapp-dym", + Name: "rollapp-temp", + ChainID: "rollappwasm_1234-1", + Images: []ibc.DockerImage{rollappWasmImage}, + Bin: "rollappd", + Bech32Prefix: "rol", + Denom: "urax", + CoinType: "118", + GasPrices: "0.0urax", + GasAdjustment: 1.1, + TrustingPeriod: "112h", + EncodingConfig: encodingConfig(), + NoHostMount: false, + ModifyGenesis: modifyRollappWasmGenesis(modifyWasmGenesisKV), + ConfigFileOverrides: configFileOverrides, + }, + NumValidators: &numRollAppVals, + NumFullNodes: &numRollAppFn, + }, + { + Name: "dymension-hub", + ChainConfig: dymensionConfig, + 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), + ).Build(t, client, "relayer", network) + + 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(), + }, nil, "", nil, false, 780) + require.Error(t, err) +} diff --git a/tests/genesis_transfer_test.go b/tests/genesis_transfer_test.go deleted file mode 100644 index cd858718..00000000 --- a/tests/genesis_transfer_test.go +++ /dev/null @@ -1,644 +0,0 @@ -package tests - -// import ( -// "context" -// "fmt" -// "testing" - -// transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" -// "github.com/stretchr/testify/require" -// "go.uber.org/zap/zaptest" - -// test "github.com/decentrio/rollup-e2e-testing" -// "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" -// ) - -// TestGenesisTransfer_EVM -// func TestGenesisTransferBridgeBlocking_EVM(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) -// dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1" -// dymintTomlOverrides["settlement_gas_prices"] = "0adym" -// dymintTomlOverrides["max_idle_time"] = "3s" -// dymintTomlOverrides["max_proof_time"] = "500ms" -// dymintTomlOverrides["batch_submit_time"] = "50s" -// dymintTomlOverrides["p2p_blocksync_enabled"] = "false" - -// configFileOverrides["config/dymint.toml"] = dymintTomlOverrides -// // 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: dymensionConfig, -// 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), -// ).Build(t, client, "relayer", network) - -// 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(), -// }, nil, "", nil) -// require.NoError(t, err) - -// CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) - -// // Create some user accounts on both chains -// users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) - -// // Get our Bech32 encoded user addresses -// dymensionUser, rollappUser := users[0], users[1] - -// dymensionUserAddr := dymensionUser.FormattedAddress() -// rollappUserAddr := rollappUser.FormattedAddress() - -// channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) -// require.NoError(t, err) - -// err = r.StartRelayer(ctx, eRep, ibcPath) -// require.NoError(t, err) - -// // Send a normal ibc tx from RA -> Hub -// transferData := ibc.WalletData{ -// Address: dymensionUserAddr, -// Denom: rollapp1.Config().Denom, -// Amount: transferAmount, -// } -// _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) -// require.Error(t, err) - -// // Compose an IBC transfer and send from dymension -> rollapp -// transferData = ibc.WalletData{ -// Address: rollappUserAddr, -// Denom: dymension.Config().Denom, -// Amount: transferAmount, -// } - -// // Compose an IBC transfer and send from Hub -> rollapp -// _, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{}) -// require.Error(t, err) - -// err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) -// require.NoError(t, err) - -// // Get the IBC denom -// dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom) -// dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom() - -// // 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() - -// // after a while, refund token -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount) -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, zeroBal) - -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount) -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal) -// } - -// func TestGenesisTransferBridgeBlocking_Wasm(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) -// dymintTomlOverrides["rollapp_id"] = "rollappwasm_1234-1" -// dymintTomlOverrides["settlement_gas_prices"] = "0adym" -// dymintTomlOverrides["max_idle_time"] = "3s" -// dymintTomlOverrides["max_proof_time"] = "500ms" -// dymintTomlOverrides["batch_submit_time"] = "50s" -// dymintTomlOverrides["p2p_blocksync_enabled"] = "false" - -// configFileOverrides["config/dymint.toml"] = dymintTomlOverrides -// // 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: "rollappwasm_1234-1", -// Images: []ibc.DockerImage{rollappWasmImage}, -// Bin: "rollappd", -// Bech32Prefix: "rol", -// Denom: "urax", -// CoinType: "118", -// GasPrices: "0.0urax", -// GasAdjustment: 1.1, -// TrustingPeriod: "112h", -// EncodingConfig: encodingConfig(), -// NoHostMount: false, -// ModifyGenesis: modifyRollappWasmGenesis(rollappWasmGenesisKV), -// ConfigFileOverrides: configFileOverrides, -// }, -// NumValidators: &numRollAppVals, -// NumFullNodes: &numRollAppFn, -// }, -// { -// Name: "dymension-hub", -// ChainConfig: dymensionConfig, -// 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), -// ).Build(t, client, "relayer", network) - -// 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(), -// }, nil, "", nil) -// require.NoError(t, err) - -// CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) - -// // Create some user accounts on both chains -// users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) - -// // Get our Bech32 encoded user addresses -// dymensionUser, rollappUser := users[0], users[1] - -// dymensionUserAddr := dymensionUser.FormattedAddress() -// rollappUserAddr := rollappUser.FormattedAddress() - -// channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) -// require.NoError(t, err) - -// err = r.StartRelayer(ctx, eRep, ibcPath) -// require.NoError(t, err) - -// // Send a normal ibc tx from RA -> Hub -// transferData := ibc.WalletData{ -// Address: dymensionUserAddr, -// Denom: rollapp1.Config().Denom, -// Amount: transferAmount, -// } -// _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) -// require.Error(t, err) - -// // Compose an IBC transfer and send from dymension -> rollapp -// transferData = ibc.WalletData{ -// Address: rollappUserAddr, -// Denom: dymension.Config().Denom, -// Amount: transferAmount, -// } - -// // Compose an IBC transfer and send from Hub -> rollapp -// _, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{}) -// require.Error(t, err) - -// err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) -// require.NoError(t, err) - -// // Get the IBC denom -// dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom) -// dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom() - -// // 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() - -// // after a while, refund token -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount) -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, zeroBal) - -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount) -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, zeroBal) -// } - -// func TestGenesisTransferConnectionBlock_EVM(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) -// dymintTomlOverrides["rollapp_id"] = "rollappevm_1234-1" -// dymintTomlOverrides["settlement_gas_prices"] = "0adym" -// dymintTomlOverrides["max_idle_time"] = "3s" -// dymintTomlOverrides["max_proof_time"] = "500ms" -// dymintTomlOverrides["batch_submit_time"] = "50s" -// dymintTomlOverrides["p2p_blocksync_enabled"] = "false" - -// configFileOverrides["config/dymint.toml"] = dymintTomlOverrides -// // 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: dymensionConfig, -// 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), -// ).Build(t, client, "relayer", network) - -// 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(), -// }, nil, "", nil) -// require.NoError(t, err) - -// CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) - -// // Create some user accounts on both chains -// users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) - -// // Get our Bech32 encoded user addresses -// dymensionUser, rollappUser := users[0], users[1] - -// dymensionUserAddr := dymensionUser.FormattedAddress() -// rollappUserAddr := rollappUser.FormattedAddress() - -// channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) -// require.NoError(t, err) - -// err = r.StartRelayer(ctx, eRep, ibcPath) -// require.NoError(t, err) - -// err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) -// require.NoError(t, err) - -// // Send a normal ibc tx from RA -> Hub -// transferData := ibc.WalletData{ -// Address: dymensionUserAddr, -// Denom: rollapp1.Config().Denom, -// Amount: transferAmount, -// } -// _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) -// require.NoError(t, err) - -// rollappHeight, err := rollapp1.GetNode().Height(ctx) -// require.NoError(t, err) - -// // Assert balance was updated on the hub -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount)) - -// // 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) - -// // 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() - -// // Minus 0.1% of transfer amount for bridge fee -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) - -// // Try to open a connection with the relayer with RA as chainA -// err = r.GeneratePath(ctx, eRep, rollapp1.Config().ChainID, dymension.Config().ChainID, "demo-dymension") -// require.NoError(t, err) - -// err = r.CreateClients(ctx, eRep, "demo-dymension", ibc.DefaultClientOpts()) -// require.NoError(t, err) - -// err = testutil.WaitForBlocks(ctx, 20, rollapp1, dymension) -// require.NoError(t, err) - -// err = r.CreateConnectionsWithNumberOfRetries(ctx, eRep, "demo-dymension", "3") -// require.NoError(t, err) - -// connections, err := r.GetConnections(ctx, eRep, dymension.Config().ChainID) -// require.NoError(t, err) -// require.Equal(t, 2, len(connections)) -// } - -// func TestGenesisTransferConnectionBlock_Wasm(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["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) -// dymintTomlOverrides["rollapp_id"] = "rollappwasm_1234-1" -// dymintTomlOverrides["settlement_gas_prices"] = "0adym" -// dymintTomlOverrides["max_idle_time"] = "3s" -// dymintTomlOverrides["max_proof_time"] = "500ms" -// dymintTomlOverrides["batch_submit_time"] = "50s" -// dymintTomlOverrides["p2p_blocksync_enabled"] = "false" - -// configFileOverrides["config/dymint.toml"] = dymintTomlOverrides -// // 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: "rollappwasm_1234-1", -// Images: []ibc.DockerImage{rollappWasmImage}, -// Bin: "rollappd", -// Bech32Prefix: "rol", -// Denom: "urax", -// CoinType: "118", -// GasPrices: "0.0urax", -// GasAdjustment: 1.1, -// TrustingPeriod: "112h", -// EncodingConfig: encodingConfig(), -// NoHostMount: false, -// ModifyGenesis: modifyRollappWasmGenesis(rollappWasmGenesisKV), -// ConfigFileOverrides: configFileOverrides, -// }, -// NumValidators: &numRollAppVals, -// NumFullNodes: &numRollAppFn, -// }, -// { -// Name: "dymension-hub", -// ChainConfig: dymensionConfig, -// 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(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), -// ).Build(t, client, "relayer", network) - -// 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(), -// }, nil, "", nil) -// require.NoError(t, err) - -// CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) - -// // Create some user accounts on both chains -// users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, rollapp1) - -// // Get our Bech32 encoded user addresses -// dymensionUser, rollappUser := users[0], users[1] - -// dymensionUserAddr := dymensionUser.FormattedAddress() -// rollappUserAddr := rollappUser.FormattedAddress() - -// channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) -// require.NoError(t, err) - -// err = r.StartRelayer(ctx, eRep, ibcPath) -// require.NoError(t, err) - -// err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) -// require.NoError(t, err) - -// // Send a normal ibc tx from RA -> Hub -// transferData := ibc.WalletData{ -// Address: dymensionUserAddr, -// Denom: rollapp1.Config().Denom, -// Amount: transferAmount, -// } -// _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, ibc.TransferOptions{}) -// require.NoError(t, err) - -// rollappHeight, err := rollapp1.GetNode().Height(ctx) -// require.NoError(t, err) - -// // Assert balance was updated on the hub -// testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferData.Amount)) - -// // 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) - -// // 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() - -// // Minus 0.1% of transfer amount for bridge fee -// testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) - -// // Try to open a connection with the relayer with RA as chainA -// err = r.GeneratePath(ctx, eRep, rollapp1.Config().ChainID, dymension.Config().ChainID, "demo-dymension") -// require.NoError(t, err) - -// err = r.CreateClients(ctx, eRep, "demo-dymension", ibc.DefaultClientOpts()) -// require.NoError(t, err) - -// err = testutil.WaitForBlocks(ctx, 20, rollapp1, dymension) -// require.NoError(t, err) - -// err = r.CreateConnectionsWithNumberOfRetries(ctx, eRep, "demo-dymension", "3") -// require.NoError(t, err) - -// connections, err := r.GetConnections(ctx, eRep, dymension.Config().ChainID) -// require.NoError(t, err) -// require.Equal(t, 2, len(connections)) -// } From 48799e82bdd4956eb6a92ec3d10f38bc804455b2 Mon Sep 17 00:00:00 2001 From: anhductn2001 Date: Mon, 14 Oct 2024 12:40:15 +0700 Subject: [PATCH 2/2] makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index e59e160f..227c7e3b 100644 --- a/Makefile +++ b/Makefile @@ -515,6 +515,9 @@ e2e-test-rollapp_genesis_transfer_hub_to_rollapp_with_trigger_rollapp_wasm: clea e2e-test-rollapp_genesis_transfer_back_and_forth_with_trigger_both_wasm: clean-e2e cd tests && go test -timeout=45m -race -v -run TestTransferTriggerGenesisBoth_Wasm . +e2e-test-genesis-bridge-invalid-wasm: clean-e2e + cd tests && go test -timeout=45m -race -v -run TestGenesisBridgeInvalid_Wasm . + e2e-test-rollapp-freeze-cant-fulfill-pending-eibc-packet-wasm: clean-e2e cd tests && go test -timeout=45m -race -v -run TestRollAppFreezeEibcPending_Wasm .