Skip to content

Commit

Permalink
add dis and reconnecting celes da
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanhNhann committed Aug 2, 2024
1 parent 0bff5ff commit 340de42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 77 deletions.
Binary file added tests/__debug_bin2377556008
Binary file not shown.
98 changes: 21 additions & 77 deletions tests/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"

transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

Expand All @@ -19,7 +18,6 @@ import (
"github.com/decentrio/rollup-e2e-testing/cosmos/hub/celes_hub"
"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/relayer"

"github.com/decentrio/rollup-e2e-testing/ibc"
"github.com/decentrio/rollup-e2e-testing/testreporter"
Expand Down Expand Up @@ -276,20 +274,8 @@ func TestSequencerCelestia_EVM(t *testing.T) {
rollapp1 := chains[0].(*dym_rollapp.DymRollApp)
dymension := chains[1].(*dym_hub.DymHub)

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,
})

AddRollUp(dymension, rollapp1)
err = ic.Build(ctx, eRep, test.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
Expand All @@ -301,81 +287,39 @@ func TestSequencerCelestia_EVM(t *testing.T) {
}, 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)
celestia.StopAllNodes(ctx)

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)

// 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()
require.Error(t, err)
require.False(t, isFinalized)

// Minus 0.1% of transfer amount for bridge fee
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, rollappIBCDenom, transferAmount.Sub(bridgingFee))
celestia.StartAllNodes(ctx)

execIDResp, err = client.ContainerExecCreate(ctx, containerID, execConfig)
if err != nil {
panic(err)
}

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

// Compose an IBC transfer and send from dymension -> rollapp
transferData = ibc.WalletData{
Address: rollappUserAddr,
Denom: dymension.Config().Denom,
Amount: transferAmount,
// Start the exec instance
execStartCheck = types.ExecStartCheck{
Tty: false,
}

// 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))
if err := client.ContainerExecStart(ctx, execID, execStartCheck); err != nil {
panic(err)
}

err = testutil.WaitForBlocks(ctx, 10, dymension, rollapp1)
rollappHeight, err = rollapp1.GetNode().Height(ctx)
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")
// wait until the packet is finalized
isFinalized, err = dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollappHeight, 300)
require.NoError(t, err)
erc20MAccAddr := erc20MAcc.Account.BaseAccount.Address
testutil.AssertBalance(t, ctx, rollapp1, erc20MAccAddr, dymensionIBCDenom, transferData.Amount)
require.True(t, isFinalized)
}

0 comments on commit 340de42

Please sign in to comment.