-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add base for seq rotation with mul seqs
- Loading branch information
1 parent
0412235
commit 4d56660
Showing
2 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"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/testreporter" | ||
"github.com/decentrio/rollup-e2e-testing/testutil" | ||
"github.com/decentrio/rollup-e2e-testing/relayer" | ||
) | ||
|
||
func Test_SeqRotation_MulSeq_EVM(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip() | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
go StartDA() | ||
|
||
// setup config for rollapp 1 | ||
settlement_layer_rollapp1 := "dymension" | ||
settlement_node_address := fmt.Sprintf("http://dymension_100-1-val-0-%s:26657", t.Name()) | ||
rollapp1_id := "rollappevm_1234-1" | ||
gas_price_rollapp1 := "0adym" | ||
maxIdleTime1 := "5s" | ||
maxProofTime := "500ms" | ||
configFileOverrides := overridesDymintToml(settlement_layer_rollapp1, settlement_node_address, rollapp1_id, gas_price_rollapp1, maxIdleTime1, maxProofTime, "20s", true) | ||
|
||
// Create chain factory with dymension | ||
numHubVals := 1 | ||
numHubFullNodes := 1 | ||
numRollAppVals := 3 | ||
numRollAppFn := 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) | ||
|
||
ic := test.NewSetup(). | ||
AddRollUp(dymension, rollapp1) | ||
|
||
rep := testreporter.NewNopReporter() | ||
eRep := rep.RelayerExecReporter(t) | ||
|
||
// relayer for rollapp 1 | ||
r1 := test.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t), | ||
relayer.CustomDockerImage(RelayerMainRepo, relayerVersion, "100:1000"), relayer.ImagePull(pullRelayerImage), | ||
).Build(t, client, "relayer1", network) | ||
|
||
err = ic.Build(ctx, eRep, test.InterchainBuildOptions{ | ||
TestName: t.Name(), | ||
Client: client, | ||
NetworkID: network, | ||
SkipPathCreation: true, | ||
}, nil, "", nil) | ||
require.Error(t, err) | ||
|
||
// create 3 sequencers | ||
_, _, err = rollapp1.GetNode().ExecInit(ctx, "sequencer1", "/var/cosmos-chain/sequencer1") | ||
require.NoError(t, err) | ||
|
||
cmd := append([]string{rollapp1.Validators[0].Chain.Config().Bin}, "dymint", "show-sequencer", "--home", "/var/cosmos-chain/sequencer1") | ||
pub1, _, err := rollapp1.GetNode().Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
_, _, err = rollapp1.Validators[1].ExecInit(ctx, "sequencer2", "/var/cosmos-chain/sequencer2") | ||
require.NoError(t, err) | ||
|
||
cmd2 := append([]string{rollapp1.GetNode().Chain.Config().Bin}, "dymint", "show-sequencer", "--home", "/var/cosmos-chain/sequencer2") | ||
pub2, _, err := rollapp1.GetNode().Exec(ctx, cmd2, nil) | ||
require.NoError(t, err) | ||
|
||
// Create some user accounts on both chains | ||
users := test.GetAndFundTestUsers(t, ctx, t.Name(), walletAmount, dymension, dymension, dymension) | ||
|
||
// Wait a few blocks for relayer to start and for user accounts to be created | ||
err = testutil.WaitForBlocks(ctx, 5, dymension, rollapp1) | ||
require.NoError(t, err) | ||
|
||
sequencer1, sequencer2, dymensionUser, marketMaker, rollappUser := users[0], users[1], users[2], users[3], users[4] | ||
|
||
dymensionUserAddr := dymensionUser.FormattedAddress() | ||
marketMakerAddr := marketMaker.FormattedAddress() | ||
rollappUserAddr := rollappUser.FormattedAddress() | ||
|
||
command := []string{"dymd", "tx", "sequencer", "create-sequencer", string(pub1), rollapp1.Config().ChainID, rollapp1.GetSequencerKeyDir()+"/metadata_sequencer.json", "1000000000adym", | ||
"--broadcast-mode", "async"} | ||
|
||
_, err = dymension.Validators[1].ExecTx(ctx, sequencer1.KeyName(), command...) | ||
require.NoError(t, err) | ||
|
||
command = []string{"dymd", "tx", "sequencer", "create-sequencer", string(pub2), rollapp1.Config().ChainID, rollapp1.GetSequencerKeyDir()+"/metadata_sequencer.json", "1100000000adym", | ||
"--broadcast-mode", "async"} | ||
|
||
_, err = dymension.Validators[2].ExecTx(ctx, sequencer2.KeyName(), command...) | ||
require.NoError(t, err) | ||
|
||
res, err := dymension.QueryShowSequencerByRollapp(ctx, rollapp1.Config().ChainID) | ||
require.NoError(t, err) | ||
require.Equal(t, len(res.Sequencers), 3, "should have 3 sequences") | ||
|
||
// verify ibc transfer work before unbond sqc1 | ||
CreateChannel(ctx, t, r1, eRep, dymension.CosmosChain, rollapp1.CosmosChain, ibcPath) | ||
|
||
// Assert the accounts were funded | ||
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount) | ||
testutil.AssertBalance(t, ctx, dymension, marketMakerAddr, dymension.Config().Denom, walletAmount) | ||
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount) | ||
|
||
dymChannels, err := r1.GetChannels(ctx, eRep, dymension.Config().ChainID) | ||
require.NoError(t, err) | ||
|
||
channsRollApp1, err := r1.GetChannels(ctx, eRep, rollapp1.GetChainID()) | ||
require.NoError(t, err) | ||
|
||
require.Len(t, channsRollApp1, 1) | ||
require.Len(t, dymChannels, 2) | ||
|
||
channel, err := ibc.GetTransferChannel(ctx, r1, eRep, dymension.Config().ChainID, rollapp1.Config().ChainID) | ||
require.NoError(t, err) | ||
|
||
// Start relayer | ||
err = r1.StartRelayer(ctx, eRep, ibcPath) | ||
require.NoError(t, err) | ||
|
||
// send ibc transfer from rollapp1 to dymension (also act as 'normal' transfer for enabling ibc transfer) | ||
// 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) | ||
|
||
// Wait for finalized | ||
rollapp1Height, err := rollapp1.Height(ctx) | ||
require.NoError(t, err) | ||
isFinalized, err := dymension.WaitUntilRollappHeightIsFinalized(ctx, rollapp1.GetChainID(), rollapp1Height, 300) | ||
require.True(t, isFinalized) | ||
require.NoError(t, err) | ||
|
||
// assert the balances | ||
testutil.AssertBalance(t, ctx, dymension, dymensionUserAddr, dymension.Config().Denom, walletAmount.Add(transferAmount)) | ||
testutil.AssertBalance(t, ctx, rollapp1, rollappUserAddr, rollapp1.Config().Denom, walletAmount.Sub(transferAmount)) | ||
|
||
// Unbond sequencer1 | ||
err = dymension.Unbond(ctx, sequencer1.KeyName(), "") | ||
require.NoError(t, err) | ||
|
||
queryGetSequencerResponse, err := dymension.QueryShowSequencer(ctx, sequencer1.FormattedAddress()) | ||
require.NoError(t, err) | ||
require.Equal(t, queryGetSequencerResponse.Sequencer.Status, "OPERATING_STATUS_UNBONDING") | ||
|
||
// Check ibc transfer works during the sequencer rotation | ||
// send ibc transfer from rollapp1 to dym using eibc | ||
// TODO: add eibc transfer | ||
} |