Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E2E-Test]: add Test_EIBC_Client_NoFundForToken_EVM #456

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ e2e-test-eibc-client-lower-fee-evm: clean-e2e

e2e-test-eibc-client-fulfill-order-got-polled-evm: clean-e2e
cd tests && go test -timeout=30m -race -v -run Test_EIBC_Client_Got_Polled_EVM .

e2e-test-eibc-client-nofundfortoken-evm: clean-e2e
cd tests && go test -timeout=30m -race -v -run Test_EIBC_Client_NoFundForToken_EVM .

# Executes IBC tests via rollup-e2e-testing
e2e-test-ibc-success-wasm: clean-e2e
Expand Down
268 changes: 268 additions & 0 deletions tests/eibc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,271 @@ func Test_EIBC_Client_Lower_Fee_EVM(t *testing.T) {
// Run invariant check
CheckInvariant(t, ctx, dymension, dymensionUser.KeyName())
}

func Test_EIBC_Client_NoFundForToken_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: 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,
SidecarConfigs: []ibc.SidecarConfig{
{
ProcessName: "eibc-client",
Image: eibcClientImage,
HomeDir: "/root",
Ports: nil,
StartCmd: []string{"eibc-client", "start", "--config", "/root/.eibc-client/config.yaml"},
PreStart: true,
ValidatorProcess: false,
},
},
},
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, dymension, rollapp1)

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

dymensionUserAddr := dymensionUser.FormattedAddress()
dymensionUserAddr2 := dymensionUser2.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)

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it, not need

require.NoError(t, err)

rollappHeight, err := rollapp1.GetNode().Height(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same above

require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 5, dymension, rollapp1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove too

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()

StartDB(ctx, t, client, network)

configFile := "data/config.yaml"
content, err := os.ReadFile(configFile)
require.NoError(t, err)

// Unmarshal the YAML content into the Config struct
var config Config
err = yaml.Unmarshal(content, &config)
require.NoError(t, err)

dymensionHomeDir := strings.Split(dymension.HomeDir(), "/")
dymensionFolderName := dymensionHomeDir[len(dymensionHomeDir)-1]

// Modify a field
config.NodeAddress = fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name())
config.DBPath = "mongodb://mongodb-container:27017"
config.Gas.MinimumGasBalance = "100adym"
config.Gas.Fees = "100adym"
config.LogLevel = "debug"
config.HomeDir = "/root/.eibc-client"
config.OrderPolling.Interval = 30 * time.Second
config.OrderPolling.Enabled = false
config.Bots.KeyringBackend = "test"
config.Bots.KeyringDir = "/root/.eibc-client"
config.Bots.NumberOfBots = 3
config.Bots.MaxOrdersPerTx = 10
config.Bots.TopUpFactor = 5
config.Whale.AccountName = dymensionUser.KeyName()
config.Whale.AllowedBalanceThresholds = map[string]string{"adym": "1000", "ibc/278D6FE92E9722572773C899D688907EB9276DEBB40552278B96C17C41C59A11": "1000"}
config.Whale.KeyringBackend = "test"
config.Whale.KeyringDir = fmt.Sprintf("/root/%s", dymensionFolderName)
config.FulfillCriteria.MinFeePercentage.Asset = map[string]float32{"adym": 0.1, "ibc/278D6FE92E9722572773C899D688907EB9276DEBB40552278B96C17C41C59A11": 0.1}
config.FulfillCriteria.MinFeePercentage.Chain = map[string]float32{"rollappevm_1234-1": 0.1}
config.SkipRefund = true

// Marshal the updated struct back to YAML
modifiedContent, err := yaml.Marshal(&config)
require.NoError(t, err)

err = os.Chmod(configFile, 0777)
require.NoError(t, err)

// Write the updated content back to the file
err = os.WriteFile(configFile, modifiedContent, 0777)
require.NoError(t, err)

err = os.Mkdir("/tmp/.eibc-client", 0755)
require.NoError(t, err)

err = copyFile("data/config.yaml", "/tmp/.eibc-client/config.yaml")
require.NoError(t, err)

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

err = dymension.Sidecars[0].CreateContainer(ctx)
require.NoError(t, err)

err = dymension.Sidecars[0].StartContainer(ctx)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
require.NoError(t, err)

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

multiplier := math.NewInt(10)

eibcFee := transferAmount.Quo(multiplier)

// set eIBC specific memo
var options ibc.TransferOptions
options.Memo = BuildEIbcMemo(eibcFee)

_, err = rollapp1.SendIBCTransfer(ctx, channel.ChannelID, rollappUserAddr, transferData, options)
require.NoError(t, err)

// get eIbc event
eibcEvents, err := getEIbcEventsWithinBlockRange(ctx, dymension, 10, false)
require.NoError(t, err)
for i, eibcEvent := range eibcEvents {
fmt.Println(i, "EIBC Event:", eibcEvent)
}

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).Sub(bigTransferAmount))

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

_, err = dymension.GetNode().FinalizePacketsUntilHeight(ctx, dymensionUserAddr, rollapp1.GetChainID(), fmt.Sprint(rollappHeight))
require.NoError(t, err)

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

// Minus 0.1% of transfer amount for bridge fee
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr2, rollappIBCDenom, transferData.Amount.Sub(bridgingFee))

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