Skip to content

Commit

Permalink
Create lite container version of integration test and work in unifing…
Browse files Browse the repository at this point in the history
… all live run tests under one test bed, still working on chain_block test
  • Loading branch information
guilledk committed Nov 29, 2024
1 parent 214b7e8 commit dcd77fb
Show file tree
Hide file tree
Showing 10 changed files with 767 additions and 395 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ reth-node-telos = { path = "crates/telos/node" }
reth-telos-rpc = { path = "crates/telos/rpc" }
reth-telos-primitives-traits = { path = "crates/telos/primitives-traits" }
reth-telos-rpc-engine-api = { path = "crates/telos/rpc-engine-api" }
antelope-client = { git = "https://github.com/telosnetwork/antelope-rs", branch = "master" }
# antelope-client = { git = "https://github.com/telosnetwork/antelope-rs", branch = "master" }
antelope-client = { git = "https://github.com/telosnetwork/antelope-rs", rev = "c485ff3e0a3e247c85c204b41144765accefbbc3" }

[patch.crates-io]
#alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "8c499409"}
Expand Down
1 change: 1 addition & 0 deletions crates/telos/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ serde_json = "1.0.122"
tokio = "1.39.2"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
lazy_static = "1.5.0"

[features]
telos = [
Expand Down
22 changes: 11 additions & 11 deletions crates/telos/node/src/two_way_storage_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ use reth::providers::StateProviderBox;
use reth_db::{PlainAccountState, PlainStorageState};

#[derive(Debug, Clone, Default, Serialize, Deserialize, StructPacker)]
struct AccountRow {
index: u64,
address: Checksum160,
account: Name,
nonce: u64,
code: Vec<u8>,
balance: Checksum256,
pub struct AccountRow {
pub index: u64,
pub address: Checksum160,
pub account: Name,
pub nonce: u64,
pub code: Vec<u8>,
pub balance: Checksum256,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize, StructPacker)]
struct AccountStateRow {
index: u64,
key: Checksum256,
value: Checksum256,
pub struct AccountStateRow {
pub index: u64,
pub key: Checksum256,
pub value: Checksum256,
}

/// This struct holds matching statistics
Expand Down
131 changes: 7 additions & 124 deletions crates/telos/node/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,145 +1,28 @@
use alloy_provider::{Provider, ProviderBuilder};
use antelope::api::client::{APIClient, DefaultProvider};
use reqwest::Url;
use reth::{
args::RpcServerArgs,
builder::{NodeBuilder, NodeConfig},
builder::NodeBuilder,
tasks::TaskManager,
};
use reth_chainspec::{ChainSpec, ChainSpecBuilder, TEVMTESTNET};
use reth_e2e_test_utils::node::NodeTestContext;
use reth_node_telos::{TelosArgs, TelosNode};
use reth_telos_rpc::TelosClient;
use std::{fs, path::PathBuf, sync::Arc, time::Duration};
use telos_consensus_client::{
client::ConsensusClient,
config::{AppConfig, CliArgs},
main_utils::build_consensus_client,
};
use telos_translator_rs::{
block::TelosEVMBlock, translator::Translator, types::translator_types::ChainId,
};
use testcontainers::{
core::ContainerPort::Tcp, runners::AsyncRunner, ContainerAsync, GenericImage,
};
use std::time::Duration;
use telos_translator_rs::block::TelosEVMBlock;
use testcontainers::runners::AsyncRunner;
use tokio::sync::mpsc;
use crate::utils::runners::{build_consensus_and_translator, CONTAINER_LAST_EVM_BLOCK, CONTAINER_NAME, CONTAINER_TAG, init_reth, start_ship, TelosRethNodeHandle};

pub mod live_test_runner;
pub mod utils;

struct TelosRethNodeHandle {
execution_port: u16,
jwt_secret: String,
}

const CONTAINER_TAG: &str =
"v0.1.11@sha256:d138f2e08db108d5d420b4db99a57fb9d45a3ee3e0f0faa7d4c4a065f7f018ce";

// This is the last block in the container, after this block the node is done syncing and is running live
const CONTAINER_LAST_EVM_BLOCK: u64 = 1010;

async fn start_ship() -> ContainerAsync<GenericImage> {
// Change this container to a local image if using new ship data,
// then make sure to update the ship data in the testcontainer-nodeos-evm repo and build a new version

// The tag for this image needs to come from the Github packages UI, under the "OS/Arch" tab
// and should be the tag for linux/amd64
let container: ContainerAsync<GenericImage> =
GenericImage::new("ghcr.io/telosnetwork/testcontainer-nodeos-evm", CONTAINER_TAG)
.with_exposed_port(Tcp(8888))
.with_exposed_port(Tcp(18999))
.start()
.await
.unwrap();

let port_8888 = container.get_host_port_ipv4(8888).await.unwrap();

let api_base_url = format!("http://localhost:{port_8888}");
let api_client = APIClient::<DefaultProvider>::default_provider(api_base_url, Some(1)).unwrap();

let mut last_block = 0;

loop {
let Ok(info) = api_client.v1_chain.get_info().await else {
println!("Waiting for telos node to produce blocks...");
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
continue;
};
if last_block != 0 && info.head_block_num > last_block {
break;
}
last_block = info.head_block_num;
}

container
}

fn init_reth() -> eyre::Result<(NodeConfig<ChainSpec>, String)> {
let chain_spec = Arc::new(
ChainSpecBuilder::default()
.chain(TEVMTESTNET.chain)
.genesis(TEVMTESTNET.genesis.clone())
.frontier_activated()
.homestead_activated()
.tangerine_whistle_activated()
.spurious_dragon_activated()
.byzantium_activated()
.constantinople_activated()
.petersburg_activated()
.istanbul_activated()
.berlin_activated()
.build(),
);

let mut rpc_config = RpcServerArgs::default().with_unused_ports().with_http();
rpc_config.auth_jwtsecret = Some(PathBuf::from("tests/assets/jwt.hex"));

// Node setup
let node_config = NodeConfig::test().with_chain(chain_spec).with_rpc(rpc_config.clone());

let jwt = fs::read_to_string(node_config.rpc.auth_jwtsecret.clone().unwrap())?;
Ok((node_config, jwt))
}

async fn build_consensus_and_translator(
reth_handle: TelosRethNodeHandle,
ship_port: u16,
chain_port: u16,
) -> (ConsensusClient, Translator) {
let config = AppConfig {
log_level: "debug".to_string(),
chain_id: ChainId(41),
execution_endpoint: format!("http://localhost:{}", reth_handle.execution_port),
jwt_secret: reth_handle.jwt_secret,
ship_endpoint: format!("ws://localhost:{ship_port}"),
chain_endpoint: format!("http://localhost:{chain_port}"),
batch_size: 1,
prev_hash: "b25034033c9ca7a40e879ddcc29cf69071a22df06688b5fe8cc2d68b4e0528f9".to_string(),
validate_hash: None,
evm_start_block: 1,
// TODO: Determine a good stop block and test it here
evm_stop_block: None,
data_path: "temp/db".to_string(),
block_checkpoint_interval: 1000,
maximum_sync_range: 100000,
latest_blocks_in_db_num: 100,
max_retry: None,
retry_interval: None,
};

let cli_args = CliArgs { config: "".to_string(), clean: true };

let c = build_consensus_client(&cli_args, config).await.unwrap();
let translator = Translator::new((&c.config).into());

(c, translator)
}

#[tokio::test]
async fn testing_chain_sync() {
tracing_subscriber::fmt::init();

println!("Starting test node");
let container = start_ship().await;
let container = start_ship(CONTAINER_NAME, CONTAINER_TAG).await;
let chain_port = container.get_host_port_ipv4(8888).await.unwrap();
let ship_port = container.get_host_port_ipv4(18999).await.unwrap();

Expand Down
Loading

0 comments on commit dcd77fb

Please sign in to comment.