From 81e43362f76351c52780f966ecf7e33a5a7e9fd2 Mon Sep 17 00:00:00 2001 From: hungdinh82 Date: Thu, 31 Oct 2024 19:39:39 +0700 Subject: [PATCH 1/5] TestZeroFee_RotatedSequencer_EVM --- Makefile | 3 + tests/zero_fee_relay_test.go | 332 +++++++++++++++++++++++++++++++++++ 2 files changed, 335 insertions(+) create mode 100644 tests/zero_fee_relay_test.go diff --git a/Makefile b/Makefile index b817730c..28f69d6d 100644 --- a/Makefile +++ b/Makefile @@ -386,6 +386,9 @@ e2e-test-sequencer-rotation-roatate-request-no-da-evm: clean-e2e e2e-test-timebaseupgradeinpast-evm: clean-e2e cd tests && go test -timeout=45m -race -v -run Test_TimeBaseUpgradeInPast_EVM . +e2e-test-zero-fee-rotated-sequencer-evm: clean-e2e + cd tests && go test -timeout=45m -race -v -run TestZeroFee_RotatedSequencer_EVM . + # Executes IBC tests via rollup-e2e-testing e2e-test-ibc-success-wasm: clean-e2e cd tests && go test -timeout=45m -race -v -run TestIBCTransferSuccess_Wasm . diff --git a/tests/zero_fee_relay_test.go b/tests/zero_fee_relay_test.go new file mode 100644 index 00000000..8298b076 --- /dev/null +++ b/tests/zero_fee_relay_test.go @@ -0,0 +1,332 @@ +package tests + +import ( + "bufio" + "context" + "fmt" + "os" + "strings" + "testing" + + "cosmossdk.io/math" + 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" +) + +func TestZeroFee_RotatedSequencer_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) + + containerID := fmt.Sprintf("ra-rollappevm_1234-1-val-0-%s", t.Name()) + + // Get the container details + containerJSON, err := client.ContainerInspect(context.Background(), containerID) + require.NoError(t, err) + + // Extract the IP address from the network settings + // If the container is using a custom network, the IP might be under a specific network name + var ipAddress string + for _, network := range containerJSON.NetworkSettings.Networks { + ipAddress = network.IPAddress + break // Assuming we only need the IP from the first network + } + + nodeId, err := rollapp1.Validators[0].GetNodeId(ctx) + require.NoError(t, err) + nodeId = strings.TrimRight(nodeId, "\n") + p2p_bootstrap_node := fmt.Sprintf("/ip4/%s/tcp/26656/p2p/%s", ipAddress, nodeId) + + rollapp1HomeDir := strings.Split(rollapp1.HomeDir(), "/") + rollapp1FolderName := rollapp1HomeDir[len(rollapp1HomeDir)-1] + + file, err := os.Open(fmt.Sprintf("/tmp/%s/config/dymint.toml", rollapp1FolderName)) + require.NoError(t, err) + defer file.Close() + + lines := []string{} + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + + for i, line := range lines { + if strings.HasPrefix(line, "p2p_bootstrap_nodes =") { + lines[i] = fmt.Sprintf("p2p_bootstrap_nodes = \"%s\"", p2p_bootstrap_node) + } + } + + output := strings.Join(lines, "\n") + file, err = os.Create(fmt.Sprintf("/tmp/%s/config/dymint.toml", rollapp1FolderName)) + require.NoError(t, err) + defer file.Close() + + _, err = file.Write([]byte(output)) + 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) + + // Create sequence + cmd := append([]string{rollapp1.FullNodes[0].Chain.Config().Bin}, "dymint", "show-sequencer", "--home", rollapp1.FullNodes[0].HomeDir()) + pub1, _, err := rollapp1.GetNode().Exec(ctx, cmd, nil) + require.NoError(t, err) + + err = dymension.GetNode().CreateKeyWithKeyDir(ctx, "sequencer", rollapp1.GetNode().HomeDir()) + require.NoError(t, err) + + sequencer, err := dymension.AccountKeyBech32WithKeyDir(ctx, "sequencer", rollapp1.GetNode().HomeDir()) + require.NoError(t, err) + + fund := ibc.WalletData{ + Address: sequencer, + Denom: dymension.Config().Denom, + Amount: math.NewInt(10_000_000_000_000).MulRaw(100_000_000), + } + err = dymension.SendFunds(ctx, "faucet", fund) + require.NoError(t, err) + + // Wait a few blocks for relayer to start and for user accounts to be created + err = testutil.WaitForBlocks(ctx, 5, dymension) + require.NoError(t, err) + + command := []string{"sequencer", "create-sequencer", string(pub1), rollapp1.Config().ChainID, "1000000000adym", rollapp1.GetSequencerKeyDir() + "/metadata_sequencer1.json", + "--broadcast-mode", "async", "--keyring-dir", rollapp1.GetNode().HomeDir() + "/sequencer_keys"} + + _, err = dymension.FullNodes[0].ExecTx(ctx, "sequencer", command...) + require.NoError(t, err) + + // 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) + + res, err := dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) + require.NoError(t, err) + require.Equal(t, len(res.Sequencers), 2, "should have 2 sequences") + + // 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) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + 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) + + txhash, err := dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight)) + require.NoError(t, err) + + fmt.Println(txhash) + + err = testutil.WaitForBlocks(ctx, 5, 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() + + // Canot minus 0.1% of transfer amount for bridge fee + // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount) + + res, err = dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) + sequencerAddr2 := res. // Get the address of the second sequencer + + // 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, sequencerAddr2, transferData, ibc.TransferOptions{}) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) + require.NoError(t, err) + + rollappHeight, err = rollapp1.GetNode().Height(ctx) + require.NoError(t, err) + + // 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) + + txhash, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight)) + require.NoError(t, err) + + fmt.Println(txhash) + + err = testutil.WaitForBlocks(ctx, 5, 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)) + + // Get original account balances + // dymensionOrigBal, err := dymension.GetBalance(ctx, dymensionUserAddr, dymension.Config().Denom) + // require.NoError(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.NoError(t, err) + + // // Assert balance was updated on the hub + // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) + + // 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() + + // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) + // erc20MAcc, err := rollapp1.Validators[0].QueryModuleAccount(ctx, "erc20") + // require.NoError(t, err) + // erc20MAccAddr := erc20MAcc.Account.BaseAccount.Address + // testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, dymensionIBCDenom, transferData.Amount) + + // Run invariant check + CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) +} From 7723a46cf9900095bfe7d9b7f93ae6ca157ec58b Mon Sep 17 00:00:00 2001 From: hungdinh82 Date: Thu, 31 Oct 2024 19:57:58 +0700 Subject: [PATCH 2/5] TestZeroFee_RotatedSequencer_EVM --- tests/zero_fee_relay_test.go | 38 ++---------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/tests/zero_fee_relay_test.go b/tests/zero_fee_relay_test.go index 8298b076..be38634a 100644 --- a/tests/zero_fee_relay_test.go +++ b/tests/zero_fee_relay_test.go @@ -250,13 +250,10 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { rollappTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, rollapp1.Config().Denom) rollappIBCDenom := transfertypes.ParseDenomTrace(rollappTokenDenom).IBCDenom() - // Canot minus 0.1% of transfer amount for bridge fee + // Don't need minus 0.1% of transfer amount for bridge fee because permissioned relayer address of sequencer can send free IBC txs on the rollapp // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount) - res, err = dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) - sequencerAddr2 := res. // Get the address of the second sequencer - // Send a normal ibc tx from RA -> Hub transferData = ibc.WalletData{ Address: dymensionUserAddr, @@ -264,7 +261,7 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { Amount: transferAmount, } - _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, sequencerAddr2, transferData, ibc.TransferOptions{}) + _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, sequencer, transferData, ibc.TransferOptions{}) require.NoError(t, err) err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) @@ -296,37 +293,6 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { // Minus 0.1% of transfer amount for bridge fee testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) - // Get original account balances - // dymensionOrigBal, err := dymension.GetBalance(ctx, dymensionUserAddr, dymension.Config().Denom) - // require.NoError(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.NoError(t, err) - - // // Assert balance was updated on the hub - // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) - - // 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() - - // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) - // erc20MAcc, err := rollapp1.Validators[0].QueryModuleAccount(ctx, "erc20") - // require.NoError(t, err) - // erc20MAccAddr := erc20MAcc.Account.BaseAccount.Address - // testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, dymensionIBCDenom, transferData.Amount) - // Run invariant check CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) } From 139d0e40e20c599d3565a0cca732fe31c71a15ca Mon Sep 17 00:00:00 2001 From: hungdinh82 Date: Fri, 1 Nov 2024 10:34:51 +0700 Subject: [PATCH 3/5] TestZeroFee_RotatedSequencer_EVM --- go.mod | 2 +- go.sum | 4 +- tests/zero_fee_relay_test.go | 159 ++++++++++++++++++++++++----------- 3 files changed, 114 insertions(+), 51 deletions(-) diff --git a/go.mod b/go.mod index e0168fcb..6c98bac5 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ replace ( require ( github.com/decentrio/e2e-testing-live v0.0.0-20240718080249-ee255229c869 - github.com/decentrio/rollup-e2e-testing v0.0.0-20241011125714-6812619fad58 + github.com/decentrio/rollup-e2e-testing v0.0.0-20241101030414-7ff68c4e7f57 github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240911123104-4782bc4e587f github.com/dymensionxyz/dymint v1.2.0-rc01.0.20240919105350-66f9b353655d ) diff --git a/go.sum b/go.sum index c36a83e3..4c6786dc 100644 --- a/go.sum +++ b/go.sum @@ -773,8 +773,8 @@ github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decentrio/e2e-testing-live v0.0.0-20240718080249-ee255229c869 h1:qWpUYGOsrSC+1Vmd2TjhbsSpntvvx9PsX3AoeMunFxc= github.com/decentrio/e2e-testing-live v0.0.0-20240718080249-ee255229c869/go.mod h1:HZNYnPwmSxkwTPjSD5yolauc1Vx1ZzKL4FFMxTq4H5Y= -github.com/decentrio/rollup-e2e-testing v0.0.0-20241011125714-6812619fad58 h1:cPxm8lalHGczlK+ztSaEmQMEG6M5aQwEGGUagcrpZZg= -github.com/decentrio/rollup-e2e-testing v0.0.0-20241011125714-6812619fad58/go.mod h1:QmBrZgZplhtgHRWC0Z7LC7TDsKuC8sDyQvZyXXaqw/c= +github.com/decentrio/rollup-e2e-testing v0.0.0-20241101030414-7ff68c4e7f57 h1:tlckq9RtiQUQDFaSLFdWz2DneMhK46zyJlTKrCyhJJE= +github.com/decentrio/rollup-e2e-testing v0.0.0-20241101030414-7ff68c4e7f57/go.mod h1:QmBrZgZplhtgHRWC0Z7LC7TDsKuC8sDyQvZyXXaqw/c= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= diff --git a/tests/zero_fee_relay_test.go b/tests/zero_fee_relay_test.go index be38634a..9f34d266 100644 --- a/tests/zero_fee_relay_test.go +++ b/tests/zero_fee_relay_test.go @@ -29,7 +29,7 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { ctx := context.Background() - configFileOverrides := make(map[string]any) + // setup config for rollapp 1 dymintTomlOverrides := make(testutil.Toml) dymintTomlOverrides["settlement_layer"] = "dymension" dymintTomlOverrides["settlement_node_address"] = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) @@ -38,14 +38,40 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { dymintTomlOverrides["max_idle_time"] = "3s" dymintTomlOverrides["max_proof_time"] = "500ms" dymintTomlOverrides["batch_submit_time"] = "50s" - dymintTomlOverrides["p2p_blocksync_enabled"] = "false" + dymintTomlOverrides["p2p_blocksync_enabled"] = "true" + configFileOverrides := make(map[string]any) configFileOverrides["config/dymint.toml"] = dymintTomlOverrides + + modifyHubGenesisKV := append( + dymensionGenesisKV, + cosmos.GenesisKV{ + Key: "app_state.sequencer.params.unbonding_time", + Value: "300s", + }, + cosmos.GenesisKV{ + Key: "app_state.staking.params.unbonding_time", + Value: "300s", + }, + ) + + modifyRAGenesisKV := append( + rollappEVMGenesisKV, + cosmos.GenesisKV{ + Key: "app_state.sequencers.params.unbonding_time", + Value: "300s", + }, + cosmos.GenesisKV{ + Key: "app_state.staking.params.unbonding_time", + Value: "300s", + }, + ) + // Create chain factory with dymension numHubVals := 1 numHubFullNodes := 1 - numRollAppFn := 0 numRollAppVals := 1 + numRollAppFn := 1 cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{ { @@ -64,15 +90,31 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { TrustingPeriod: "112h", EncodingConfig: encodingConfig(), NoHostMount: false, - ModifyGenesis: modifyRollappEVMGenesis(rollappEVMGenesisKV), + ModifyGenesis: modifyRollappEVMGenesis(modifyRAGenesisKV), ConfigFileOverrides: configFileOverrides, }, NumValidators: &numRollAppVals, NumFullNodes: &numRollAppFn, }, { - Name: "dymension-hub", - ChainConfig: dymensionConfig, + 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(modifyHubGenesisKV), + ConfigFileOverrides: nil, + }, NumValidators: &numHubVals, NumFullNodes: &numHubFullNodes, }, @@ -88,6 +130,7 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { // Relayer Factory client, network := test.DockerSetup(t) + // relayer for rollapp 1 r := test.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t), relayer.CustomDockerImage(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), ).Build(t, client, "relayer", network) @@ -110,10 +153,7 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { 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) + }, nil, "", nil, true, 195) require.NoError(t, err) containerID := fmt.Sprintf("ra-rollappevm_1234-1-val-0-%s", t.Name()) @@ -162,12 +202,45 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { _, err = file.Write([]byte(output)) require.NoError(t, err) + // Start full node + err = rollapp1.FullNodes[0].StopContainer(ctx) + require.NoError(t, err) + + err = rollapp1.FullNodes[0].StartContainer(ctx) + require.NoError(t, err) + + addrDym, _ := r.GetWallet(dymension.GetChainID()) + err = dymension.GetNode().SendFunds(ctx, "faucet", ibc.WalletData{ + Address: addrDym.FormattedAddress(), + Amount: math.NewInt(10_000_000_000_000), + Denom: dymension.Config().Denom, + }) + require.NoError(t, err) + + addrRA, _ := r.GetWallet(rollapp1.GetChainID()) + err = rollapp1.GetNode().SendFunds(ctx, "faucet", ibc.WalletData{ + Address: addrRA.FormattedAddress(), + Amount: math.NewInt(10_000_000_000_000), + Denom: rollapp1.Config().Denom, + }) + require.NoError(t, err) + + // Check IBC Transfer before switch 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) - // Create sequence + // Get our Bech32 encoded user addresses + dymensionUser, rollappUser := users[0], users[1] + + dymensionUserAddr := dymensionUser.FormattedAddress() + rollappUserAddr := rollappUser.FormattedAddress() + + keyDir := dymension.GetRollApps()[0].GetSequencerKeyDir() + sequencerAddr, err := dymension.AccountKeyBech32WithKeyDir(ctx, "sequencer", keyDir) + require.NoError(t, err) + cmd := append([]string{rollapp1.FullNodes[0].Chain.Config().Bin}, "dymint", "show-sequencer", "--home", rollapp1.FullNodes[0].HomeDir()) pub1, _, err := rollapp1.GetNode().Exec(ctx, cmd, nil) require.NoError(t, err) @@ -196,11 +269,14 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { _, err = dymension.FullNodes[0].ExecTx(ctx, "sequencer", command...) require.NoError(t, err) - // Get our Bech32 encoded user addresses - dymensionUser, rollappUser := users[0], users[1] + res, err := dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) + require.NoError(t, err) + require.Equal(t, len(res.Sequencers), 2, "should have 2 sequences") + fmt.Printf("Sequencer check: %v\n", res.Sequencers) - dymensionUserAddr := dymensionUser.FormattedAddress() - rollappUserAddr := rollappUser.FormattedAddress() + //Update white listed relayers + _, err = dymension.GetNode().UpdateWhitelistedRelayers(ctx, sequencerAddr, []string{wallet.FormattedAddress()}) + require.NoError(t, err) channel, err := ibc.GetTransferChannel(ctx, r, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) require.NoError(t, err) @@ -211,10 +287,6 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) require.NoError(t, err) - res, err := dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) - require.NoError(t, err) - require.Equal(t, len(res.Sequencers), 2, "should have 2 sequences") - // Send a normal ibc tx from RA -> Hub transferData := ibc.WalletData{ Address: dymensionUserAddr, @@ -250,48 +322,39 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { rollappTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, rollapp1.Config().Denom) rollappIBCDenom := transfertypes.ParseDenomTrace(rollappTokenDenom).IBCDenom() - // Don't need minus 0.1% of transfer amount for bridge fee because permissioned relayer address of sequencer can send free IBC txs on the rollapp - // testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) - testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount) + // Minus 0.1% of transfer amount for bridge fee + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee)) - // Send a normal ibc tx from RA -> Hub + // Get original account balances + dymensionOrigBal, err := dymension.GetBalance(ctx, dymensionUserAddr, dymension.Config().Denom) + require.NoError(t, err) + + // Compose an IBC transfer and send from dymension -> rollapp transferData = ibc.WalletData{ - Address: dymensionUserAddr, - Denom: rollapp1.Config().Denom, + Address: rollappUserAddr, + Denom: dymension.Config().Denom, Amount: transferAmount, } - _, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, sequencer, transferData, ibc.TransferOptions{}) - require.NoError(t, err) - - err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) - require.NoError(t, err) - - rollappHeight, err = rollapp1.GetNode().Height(ctx) + // Compose an IBC transfer and send from Hub -> rollapp + _, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{}) 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) + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) - txhash, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight)) + err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1) require.NoError(t, err) - fmt.Println(txhash) + // Get the IBC denom + dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom) + dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom() - err = testutil.WaitForBlocks(ctx, 5, dymension, rollapp1) + testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, dymensionOrigBal.Sub(transferData.Amount)) + erc20MAcc, err := rollapp1.Validators[0].QueryModuleAccount(ctx, "erc20") 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)) + erc20MAccAddr := erc20MAcc.Account.BaseAccount.Address + testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, dymensionIBCDenom, transferData.Amount) // Run invariant check CheckInvariant(t, ctx, dymension, dymensionUser.KeyName()) From 69daeb7712cdf1c19f69736ec24cc328d4df48c6 Mon Sep 17 00:00:00 2001 From: hungdinh82 Date: Fri, 1 Nov 2024 10:44:43 +0700 Subject: [PATCH 4/5] TestZeroFee_RotatedSequencer_EVM --- tests/zero_fee_relay_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/zero_fee_relay_test.go b/tests/zero_fee_relay_test.go index ff69e4b9..44643280 100644 --- a/tests/zero_fee_relay_test.go +++ b/tests/zero_fee_relay_test.go @@ -612,7 +612,9 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { Denom: rollapp1.Config().Denom, }) require.NoError(t, err) - + wallet, found := r.GetWallet(rollapp1.Config().ChainID) + require.True(t, found) + // Check IBC Transfer before switch CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) From d3f9246e45bd0aa1e7e8bf98a4ec5904f3ddd809 Mon Sep 17 00:00:00 2001 From: hungdinh82 Date: Fri, 1 Nov 2024 10:47:19 +0700 Subject: [PATCH 5/5] TestZeroFee_RotatedSequencer_EVM --- tests/zero_fee_relay_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/zero_fee_relay_test.go b/tests/zero_fee_relay_test.go index 44643280..0775e066 100644 --- a/tests/zero_fee_relay_test.go +++ b/tests/zero_fee_relay_test.go @@ -14,6 +14,7 @@ import ( "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" @@ -422,13 +423,17 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { ctx := context.Background() // setup config for rollapp 1 + 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"] = "true" - configFileOverrides := make(map[string]any) configFileOverrides["config/dymint.toml"] = dymintTomlOverrides modifyHubGenesisKV := append( @@ -614,7 +619,7 @@ func TestZeroFee_RotatedSequencer_EVM(t *testing.T) { require.NoError(t, err) wallet, found := r.GetWallet(rollapp1.Config().ChainID) require.True(t, found) - + // Check IBC Transfer before switch CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath)