Skip to content

Commit

Permalink
add TestIBCTransfer_NoLightClient_EVM
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Sep 27, 2024
1 parent 5bb3e2b commit 66d5649
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ e2e-test: clean-e2e
e2e-test-ibc-success-evm: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestIBCTransferSuccess_EVM .

e2e-test-light-client-same-chain-id-transfer: clean-e2e
e2e-test-light-client-same-chain-id: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestIBCTransferRA_3rdSameChainID_EVM .

e2e-test-light-client-hub-3rd: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestIBCTransferBetweenHub3rd_EVM .

e2e-test-light-client-same-chain-id-no-light-client: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestIBCTransfer_NoLightClient_EVM .

e2e-test-spinup: clean-e2e
cd tests && go test -timeout=45m -race -v -run TestSpinUp .

Expand Down
206 changes: 206 additions & 0 deletions tests/canonical_light_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,209 @@ func TestIBCTransferRA_3rdSameChainID_EVM(t *testing.T) {
CheckInvariant(t, ctx, dymension, dymensionUser.KeyName())
})
}

func TestIBCTransfer_NoLightClient_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

// add modify gaia config so that it has the same chain-id as rollapp1
gaiaConfig := gaiaConfig.Clone()
gaiaConfig.ChainID = "rollappevm_1234-1"

// Create chain factory with dymension
numHubVals := 1
numHubFullNodes := 1
numRollAppFn := 0
numRollAppVals := 1
numVals := 1
numFullNodes := 0
cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{
{
Name: "rollapp1",
ChainConfig: ibc.ChainConfig{
Type: "rollapp-dym",
Name: "rollapp-test",
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,
},
{
Name: "gaia-1",
Version: "v14.2.0",
ChainConfig: gaiaConfig,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

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

// 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).
AddChain(gaia).
AddRelayer(r, "relayer").
AddLink(test.InterchainLink{
Chain1: dymension,
Chain2: gaia,
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)

t.Cleanup(func() {
_ = ic.Close()
})

// create ibc path between dymension and gaia, and between dymension and rollapp1
CreateChannel(ctx, t, r, eRep, dymension.CosmosChain, gaia, ibcPath)

// Get gaia -> dym channel
gaiaChan, err := r.GetChannels(ctx, eRep, gaia.GetChainID())
require.NoError(t, err)
require.Len(t, gaiaChan, 1)

dymGaiaChan := gaiaChan[0].Counterparty
require.NotEmpty(t, dymGaiaChan.ChannelID)

gaiaDymChan := gaiaChan[0]

// Start the relayer and set the cleanup function.
err = r.StartRelayer(ctx, eRep, ibcPath)
require.NoError(t, err)

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

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

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

// Get original account balances
dymensionOrigBal, err := dymension.GetBalance(ctx, dymensionUserAddr, dymension.Config().Denom)
require.NoError(t, err)
require.Equal(t, walletAmount, dymensionOrigBal)

gaiaOrigBal, err := gaia.GetBalance(ctx, gaiaUserAddr, gaia.Config().Denom)
require.NoError(t, err)
require.Equal(t, walletAmount, gaiaOrigBal)

rollappOrigBal, err := rollapp1.GetBalance(ctx, rollappUserAddr, rollapp1.Config().Denom)
require.NoError(t, err)
require.Equal(t, walletAmount, rollappOrigBal)

t.Run("canonial client test gaia<->dym", func(t *testing.T) {

// sending between gaia and dymension
firstHopDenom := transfertypes.GetPrefixedDenom(dymGaiaChan.PortID, dymGaiaChan.ChannelID, gaia.Config().Denom)
secondHopDenom := transfertypes.GetPrefixedDenom(gaiaDymChan.PortID, gaiaDymChan.ChannelID, dymension.Config().Denom)

firstHopDenomTrace := transfertypes.ParseDenomTrace(firstHopDenom)
secondHopDenomTrace := transfertypes.ParseDenomTrace(secondHopDenom)

firstHopIBCDenom := firstHopDenomTrace.IBCDenom()
secondHopIBCDenom := secondHopDenomTrace.IBCDenom()

// Send packet from gaia -> dym
transfer := ibc.WalletData{
Address: dymensionUserAddr,
Denom: gaia.Config().Denom,
Amount: transferAmount,
}

transferTx, err := gaia.SendIBCTransfer(ctx, gaiaDymChan.ChannelID, gaiaUser.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)
err = transferTx.Validate()
require.NoError(t, err)

// wait until dymension receive transferAmount
err = testutil.WaitForBlocks(ctx, 10, dymension, gaia)
require.NoError(t, err)

testutil.AssertBalance(t, ctx, gaia, gaiaUserAddr, gaia.Config().Denom, walletAmount.Sub(transferAmount))
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, firstHopIBCDenom, transferAmount)

// Send back packet from dym -> gaia
transfer = ibc.WalletData{
Address: gaiaUserAddr,
Denom: dymension.Config().Denom,
Amount: transferAmount,
}

transferTx, err = dymension.SendIBCTransfer(ctx, dymGaiaChan.ChannelID, dymensionUser.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)
err = transferTx.Validate()
require.NoError(t, err)

// wait until gaia receive transferAmount
err = testutil.WaitForBlocks(ctx, 10, gaia, dymension)
require.NoError(t, err)

testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Sub(transferAmount))
testutil.AssertBalance(t, ctx, gaia, gaiaUserAddr, secondHopIBCDenom, transferAmount)

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

0 comments on commit 66d5649

Please sign in to comment.