Skip to content

Commit

Permalink
add realtime fullnode sync test celes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdv2429 committed Aug 5, 2024
1 parent c877bbf commit 3025828
Showing 1 changed file with 253 additions and 0 deletions.
253 changes: 253 additions & 0 deletions tests/fullnode_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,256 @@ func TestFullnodeSync_Celestia_EVM(t *testing.T) {
)
require.NoError(t, err)
}

// TestFullnodeSync_Celestia_Realtime_Gossip_EVM tests the synchronization of a fullnode using Celestia as DA.
func TestFullnodeSync_Celestia_Realtime_Gossip_EVM(t *testing.T) {
if testing.Short() {
t.Skip()
}

ctx := context.Background()

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"] = "200ms"
dymintTomlOverrides["max_proof_time"] = "150ms"
dymintTomlOverrides["batch_submit_max_time"] = "80s"

configFileOverrides1 := make(map[string]any)
configTomlOverrides1 := make(testutil.Toml)
configTomlOverrides1["timeout_commit"] = "2s"
configTomlOverrides1["timeout_propose"] = "2s"
configTomlOverrides1["index_all_keys"] = "true"
configTomlOverrides1["mode"] = "validator"

configFileOverrides1["config/config.toml"] = configTomlOverrides1

numHubVals := 1
numHubFullNodes := 1
numRollAppFn := 1
numRollAppVals := 1
nodeStore := "/home/celestia/light"
p2pNetwork := "mocha-4"
coreIp := "celestia-testnet-consensus.itrocket.net"
trustedHash := "\"A62DD37EDF3DFF5A7383C6B5AA2AC619D1F8C8FEB7BA07730E50BBAAC8F2FF0C\""
sampleFrom := 2395649

cf := test.NewBuiltinChainFactory(zaptest.NewLogger(t), []*test.ChainSpec{
{
Name: "celes-hub",
ChainConfig: ibc.ChainConfig{
Name: "celestia",
Denom: "utia",
Type: "hub-celes",
GasPrices: "0.002utia",
TrustingPeriod: "112h",
ChainID: "test",
Bin: "celestia-appd",
Images: []ibc.DockerImage{
{
Repository: "ghcr.io/decentrio/light",
Version: "debug",
UidGid: "1025:1025",
},
},
Bech32Prefix: "celestia",
CoinType: "118",
GasAdjustment: 1.5,
ConfigFileOverrides: configFileOverrides1,
},
NumValidators: &numHubVals,
NumFullNodes: &numRollAppFn,
},
})

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

celestia := chains[0].(*celes_hub.CelesHub)

// Relayer Factory
client, network := test.DockerSetup(t)

ic := test.NewSetup().
AddChain(celestia)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

err = ic.Build(ctx, eRep, test.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}, nil, "", nil)
require.NoError(t, err)

validator, err := celestia.GetNode().AccountKeyBech32(ctx, "validator")
require.NoError(t, err)

// Get fund for submit blob
for i := 0; i < 13; i++ {
GetFaucet("http://18.184.170.181:3000/api/get-tia", validator)
err = testutil.WaitForBlocks(ctx, 8, celestia)
require.NoError(t, err)
}

err = celestia.GetNode().InitCelestiaDaLightNode(ctx, nodeStore, p2pNetwork, nil)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 3, celestia)
require.NoError(t, err)

file, err := os.Open("/tmp/celestia/light/config.toml")
require.NoError(t, err)
defer file.Close()

var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}

for i, line := range lines {
if strings.HasPrefix(line, " TrustedHash =") {
lines[i] = fmt.Sprintf(" TrustedHash = %s", trustedHash)
} else if strings.HasPrefix(line, " SampleFrom =") {
lines[i] = fmt.Sprintf(" SampleFrom = %d", sampleFrom)
} else if strings.HasPrefix(line, " Address =") {
lines[i] = fmt.Sprintf(" Address = \"0.0.0.0\"")
}
}

output := strings.Join(lines, "\n")
file, err = os.Create("/tmp/celestia/light/config.toml")
require.NoError(t, err)
defer file.Close()

_, err = file.Write([]byte(output))
require.NoError(t, err)

containerID := fmt.Sprintf("test-val-0-%s", t.Name())

// Create an exec instance
execConfig := types.ExecConfig{
Cmd: strslice.StrSlice([]string{"celestia", "light", "start", "--node.store", nodeStore, "--gateway", "--core.ip", coreIp, "--p2p.network", p2pNetwork, "--keyring.accname", "validator"}),
}

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

execID := execIDResp.ID

// Start the exec instance
execStartCheck := types.ExecStartCheck{
Tty: false,
}

if err := client.ContainerExecStart(ctx, execID, execStartCheck); err != nil {
panic(err)
}

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

celestia_token, err := celestia.GetNode().GetAuthTokenCelestiaDaLight(ctx, p2pNetwork, nodeStore)
require.NoError(t, err)
println("check token: ", celestia_token)
celestia_namespace_id, err := RandomHex(10)
require.NoError(t, err)
println("check namespace: ", celestia_namespace_id)
da_config := fmt.Sprintf("{\"base_url\": \"http://test-val-0-%s:26658\", \"timeout\": 60000000000, \"gas_prices\":1.0, \"gas_adjustment\": 1.3, \"namespace_id\": \"%s\", \"auth_token\":\"%s\"}", t.Name(), celestia_namespace_id, celestia_token)

configFileOverrides := make(map[string]any)
dymintTomlOverrides["da_layer"] = "celestia"
dymintTomlOverrides["namespace_id"] = celestia_namespace_id
dymintTomlOverrides["da_config"] = da_config
configFileOverrides["config/dymint.toml"] = dymintTomlOverrides

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)

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

err = ic.Build(ctx, eRep, test.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}, nil, "", nil)
require.NoError(t, err)

// Poll until full node is sync
err = testutil.WaitForCondition(
time.Minute*50,
time.Second*5, // each epoch is 5 seconds
func() (bool, error) {
valHeight, err := rollapp1.Validators[0].Height(ctx)
require.NoError(t, err)

fullnodeHeight, err := rollapp1.FullNodes[0].Height(ctx)
require.NoError(t, err)

fmt.Println("valHeight", valHeight, " || fullnodeHeight", fullnodeHeight)
if valHeight > fullnodeHeight {
return false, nil
}

return true, nil
},
)
require.NoError(t, err)
}

0 comments on commit 3025828

Please sign in to comment.