Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Dec 24, 2024
1 parent abe404e commit 8662fe1
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ e2e-test-genesis-bridge-kick-proposer-wasm: clean-e2e
e2e-test-fraud-detection-da-p2p-wasm: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestFraudDetectionDA_P2P_Wasm .

e2e-test-tokenless-transfer-diff-gas-wasm: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestTokenlessTransferDiffGas_Wasm .

# Executes all tests via rollup-e2e-testing
e2e-test-all: e2e-test-ibc-success-evm \
e2e-test-ibc-timeout-evm \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ replace (

require (
github.com/decentrio/e2e-testing-live v0.0.0-20240718080249-ee255229c869
github.com/decentrio/rollup-e2e-testing v0.0.0-20241220064322-31dd72989026
github.com/decentrio/rollup-e2e-testing v0.0.0-20241223152339-fd578076e6e9
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241016085626-2b8c8898058b
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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-20241220064322-31dd72989026 h1:wxRixOHD8MIRNc+7e2u1H/5T8fKxyECNIdv3BGpYEP8=
github.com/decentrio/rollup-e2e-testing v0.0.0-20241220064322-31dd72989026/go.mod h1:QmBrZgZplhtgHRWC0Z7LC7TDsKuC8sDyQvZyXXaqw/c=
github.com/decentrio/rollup-e2e-testing v0.0.0-20241223152339-fd578076e6e9 h1:gf/bhF4Lnp49J7StXdo5bqvJu8U2Xev4eGMHsXes+ss=
github.com/decentrio/rollup-e2e-testing v0.0.0-20241223152339-fd578076e6e9/go.mod h1:QmBrZgZplhtgHRWC0Z7LC7TDsKuC8sDyQvZyXXaqw/c=
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
Expand Down
14 changes: 7 additions & 7 deletions tests/fullnode_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (

// StartDA start grpc DALC server
func StartDA(ctx context.Context, t *testing.T, client *client.Client, net string) {
// fmt.Println("Starting pull image ...")
// out, err := client.ImagePull(ctx, "ghcr.io/dymensionxyz/dymint:latest", types.ImagePullOptions{})
// require.NoError(t, err)
// defer out.Close()
fmt.Println("Starting pull image ...")
out, err := client.ImagePull(ctx, "ghcr.io/dymensionxyz/dymint:latest", types.ImagePullOptions{})
require.NoError(t, err)
defer out.Close()

networkConfig := &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
Expand All @@ -57,14 +57,14 @@ func StartDA(ctx context.Context, t *testing.T, client *client.Client, net strin
DNS: []string{},
ExtraHosts: []string{"host.docker.internal:host-gateway"},
}
// time.Sleep(2 * time.Minute)
time.Sleep(2 * time.Minute)
// Create the container
fmt.Println("Creating container ...")
resp, err := client.ContainerCreate(
ctx,
&container.Config{
Image: "ghcr.io/decentrio/dymint:srene-hardfork-fix-arm", // Image to run
Tty: true, // Attach to a TTY
Image: "ghcr.io/dymensionxyz/dymint:latest", // Image to run
Tty: true, // Attach to a TTY
},
hostConfig, networkConfig, nil, "grpc-da-container",
)
Expand Down
282 changes: 281 additions & 1 deletion tests/tokenless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,19 @@ func TestTokenlessTransferDiffGas_EVM(t *testing.T) {
Key: "app_state.evm.params.gas_denom",
Value: "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
},
cosmos.GenesisKV{
Key: "app_state.rollappparams.params.min_gas_prices",
Value: []interface{}{
map[string]interface{}{
"amount": "1",
"denom": "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
},
},
},
cosmos.GenesisKV{
Key: "app_state.feemarket.params.min_gas_price",
Value: "1.0",
},
)

cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{
Expand Down Expand Up @@ -679,7 +692,7 @@ func TestTokenlessTransferDiffGas_EVM(t *testing.T) {
keyDir := dymension.GetRollApps()[0].GetSequencerKeyDir()
keyPath := keyDir + "/sequencer_keys"

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

//Update white listed relayers
Expand Down Expand Up @@ -1129,3 +1142,270 @@ func TestUpdateMinGasPrice_EVM(t *testing.T) {
// Run invariant check
CheckInvariant(t, ctx, dymension, dymensionUser.KeyName())
}

func TestTokenlessTransferDiffGas_Wasm(t *testing.T) {
if testing.Short() {
t.Skip()
}

ctx := context.Background()

// setup config for rollapp
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

modifyWasmGenesisKV := append(
rollappWasmGenesisKV,
cosmos.GenesisKV{
Key: "app_state.bank.denom_metadata",
Value: []interface{}{
map[string]interface{}{
"base": "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
"denom_units": []interface{}{
map[string]interface{}{
"aliases": []interface{}{},
"denom": "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
"exponent": "0",
},
map[string]interface{}{
"aliases": []interface{}{},
"denom": "DYM",
"exponent": "18",
},
},
"description": "Denom metadata for Rollapp EVM",
"display": "DYM",
"name": "DYM",
"symbol": "DYM",
},
},
},
cosmos.GenesisKV{
Key: "app_state.mint.params.mint_denom",
Value: "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
},
cosmos.GenesisKV{
Key: "app_state.staking.params.bond_denom",
Value: "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
},
cosmos.GenesisKV{
Key: "app_state.rollappparams.params.min_gas_prices",
Value: []interface{}{
map[string]interface{}{
"amount": "1",
"denom": "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
},
},
},
)

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: "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
CoinType: "118",
GasPrices: "1.0ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
GasAdjustment: 1.3,
TrustingPeriod: "112h",
EncodingConfig: encodingConfig(),
NoHostMount: false,
ModifyGenesis: modifyRollappWasmGenesis(modifyWasmGenesisKV),
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(dymensionGenesisKV),
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)
// relayer for rollapp
r1 := test.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t),
relayer.CustomDockerImage(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage),
).Build(t, client, "relayer1", network)
ic := test.NewSetup().
AddRollUp(dymension, rollapp1).
AddRelayer(r1, "relayer1").
AddLink(test.InterchainLink{
Chain1: dymension,
Chain2: rollapp1,
Relayer: r1,
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, 1179360, true)
require.NoError(t, err)

wallet, found := r1.GetWallet(rollapp1.Config().ChainID)
require.True(t, found)

keyDir := dymension.GetRollApps()[0].GetSequencerKeyDir()
keyPath := keyDir + "/sequencer_keys"

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

//Update white listed relayers
_, err = dymension.GetNode().UpdateWhitelistedRelayers(ctx, "sequencer", keyPath, []string{wallet.FormattedAddress()})
require.NoError(t, err)

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

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

dymensionUserAddr := dymensionUser.FormattedAddress()
rollappUserAddr := rollappUser.FormattedAddress()

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

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

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

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

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

// Get the IBC denom
dymensionTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, dymension.Config().Denom)
dymensionIBCDenom := transfertypes.ParseDenomTrace(dymensionTokenDenom).IBCDenom()

// Compose an IBC transfer and send from Hub -> rollapp
_, err = dymension.SendIBCTransfer(ctx, channel.ChannelID, dymensionUserAddr, transferData, ibc.TransferOptions{})
require.NoError(t, err)

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

// Assert balance was updated on the hub
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Sub(transferData.Amount))

err = testutil.WaitForBlocks(ctx, 5, dymension, rollapp1)
require.NoError(t, err)
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, dymensionIBCDenom, walletAmount.Add(bigTransferAmount))

// Send a ibc tx from RA -> Hub
transferData = ibc.WalletData{
Address: dymensionUserAddr,
Denom: rollapp1.Config().Denom,
Amount: transferAmount,
}

command := []string{"rollappd", "tx", "ibc-transfer", "transfer", "transfer", "channel-0", transferData.Address, fmt.Sprintf("%s%s", transferData.Amount.String(), transferData.Denom), "--gas", "auto", "--gas-prices", "10.0urax", "--gas-adjustment", "1.1", "--from", rollappUserAddr, "--keyring-backend", "test", "--output", "json", "-y", "--home", rollapp1.HomeDir(), "--node", fmt.Sprintf("tcp://%s:26657", rollapp1.Validators[0].HostName()), "--chain-id", "rollappevm_1234-1"}

stdout, _, err := rollapp1.Validators[0].Exec(ctx, command, nil)
require.NoError(t, err)

fmt.Println(stdout)

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

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

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

res, err := dymension.GetNode().QueryPendingPacketsByAddress(ctx, dymensionUserAddr)
fmt.Println(res)
require.NoError(t, err)

for _, packet := range res.RollappPackets {
txhash, err := dymension.GetNode().FinalizePacket(ctx, dymensionUserAddr, packet.RollappId, fmt.Sprint(packet.ProofHeight), fmt.Sprint(packet.Type), packet.Packet.SourceChannel, fmt.Sprint(packet.Packet.Sequence))
require.NoError(t, err)

fmt.Println(txhash)
}

testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Sub(bigTransferAmount))

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

// Run invariant check
CheckInvariant(t, ctx, dymension, dymensionUser.KeyName())
}

0 comments on commit 8662fe1

Please sign in to comment.