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

Integration test and tx mapping with send2 api call #77

Open
wants to merge 26 commits into
base: telos-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
656 changes: 41 additions & 615 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ 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", rev = "d701cd9ca2e87e8e0fd99746f9c672cb3536e5ec" }
# antelope-client = { path = "../antelope-rs/crates/antelope" }


[patch.crates-io]
#alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "8c499409"}
Expand Down
15 changes: 8 additions & 7 deletions crates/telos/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ telos = [
]

[dev-dependencies]
alloy-consensus.workspace = true
# Translator and reth versions doesn't match, causing missing implementation of a TelosTxDecodable trait
alloy-consensus = "0.3.6"

alloy-contract = "0.4.2"
alloy-primitives.workspace = true
alloy-provider.workspace = true
Expand All @@ -75,17 +77,16 @@ alloy-sol-types.workspace = true
alloy-transport-http.workspace = true
reqwest.workspace = true

reth.workspace = true
reth-chainspec.workspace = true
reth-e2e-test-utils.workspace = true
eyre.workspace = true

telos-consensus-client = { git = "https://github.com/telosnetwork/telos-consensus-client", rev = "f8ecbe1aeea57911c9fbefdddf49efa92d8472ce" }
telos-translator-rs = { git = "https://github.com/telosnetwork/telos-consensus-client", rev = "f8ecbe1aeea57911c9fbefdddf49efa92d8472ce" }
#telos-consensus-client = { path = "../../../../telos-consensus-client/client" }
#telos-translator-rs = { path = "../../../../telos-consensus-client/translator" }
telos-consensus-client = { git = "https://github.com/telosnetwork/telos-consensus-client", rev = "9fadee1fd565e3a7ad51c1142e2673df52bd9028" }
telos-translator-rs = { git = "https://github.com/telosnetwork/telos-consensus-client", rev = "9fadee1fd565e3a7ad51c1142e2673df52bd9028" }
# telos-consensus-client = { path = "../../../../telos-consensus-client/client" }
# telos-translator-rs = { path = "../../../../telos-consensus-client/translator" }

env_logger = "0.11.5"
testcontainers = "0.21.1"
derive_more.workspace = true
num-bigint = "0.4.5"

47 changes: 45 additions & 2 deletions crates/telos/node/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_provider::{Provider, ProviderBuilder};
use alloy_primitives::Address;
use alloy_provider::{Provider, ProviderBuilder, ReqwestProvider};
use antelope::api::client::{APIClient, DefaultProvider};
use reqwest::Url;
use reth::{
Expand All @@ -10,19 +11,22 @@ 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::str::FromStr;
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::types::evm_types::{AccountRow, EvmContractConfigRow};
use telos_translator_rs::{
block::TelosEVMBlock, translator::Translator, types::translator_types::ChainId,
};
use testcontainers::{
core::ContainerPort::Tcp, runners::AsyncRunner, ContainerAsync, GenericImage,
};
use tokio::sync::mpsc;
use tracing::info;

pub mod live_test_runner;

Expand All @@ -37,6 +41,10 @@ const CONTAINER_TAG: &str =
// 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;

// evmuser address from the container
const EVM_USER_ADDRESS: &str = "0x4c641f9b61809fadeef2ec64f54ea2bcb398e4f3";
const EVM_USER: &str = "evmuser";

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
Expand Down Expand Up @@ -112,12 +120,13 @@ async fn build_consensus_and_translator(
jwt_secret: reth_handle.jwt_secret,
ship_endpoint: format!("ws://localhost:{ship_port}"),
chain_endpoint: format!("http://localhost:{chain_port}"),
batch_size: 1,
batch_size: 100,
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,
evm_deploy_block: None,
data_path: "temp/db".to_string(),
block_checkpoint_interval: 1000,
maximum_sync_range: 100000,
Expand Down Expand Up @@ -201,6 +210,14 @@ async fn testing_chain_sync() {
let rpc_url = Url::from(format!("http://localhost:{}", rpc_port).parse().unwrap());
let provider = ProviderBuilder::new().on_http(rpc_url.clone());

info!("Client URL {:?}", format!("http://localhost:{chain_port}"));

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

loop {
tokio::time::sleep(Duration::from_secs(1)).await;
let latest_block = provider.get_block_number().await.unwrap();
Expand All @@ -210,6 +227,10 @@ async fn testing_chain_sync() {
break;
}
if latest_block > CONTAINER_LAST_EVM_BLOCK {
// test account nonce after successful reth sync from the container
test_evm_address_nonce(provider, api_client.clone()).await;
// test current revision from the transactions in the container
test_revision(api_client).await;
break;
}
}
Expand All @@ -228,3 +249,25 @@ async fn testing_chain_sync() {
_ = tokio::join!(client_handle, translator_handle);
println!("Translator shutdown done.");
}

async fn test_evm_address_nonce(provider: ReqwestProvider, api_client: APIClient<DefaultProvider>) {
let params = live_test_runner::account_params(EVM_USER);
let row: &AccountRow = &api_client.v1_chain.get_table_rows(params).await.unwrap().rows[0];

let account = provider.get_account(Address::from_str(EVM_USER_ADDRESS).unwrap()).await.unwrap();
let tx_count =
provider.get_transaction_count(Address::from_str(EVM_USER_ADDRESS).unwrap()).await.unwrap();
// assert nonce of the account that has sent transactions in the container blocks
assert_eq!(account.nonce, 2);
assert_eq!(account.nonce, tx_count);
assert_eq!(account.nonce, row.nonce);
}

async fn test_revision(api_client: APIClient<DefaultProvider>) {
// revision in the container transaction is set to 1
let expected_revision = 1u32;
let params = live_test_runner::config_params();
let row: &EvmContractConfigRow = &api_client.v1_chain.get_table_rows(params).await.unwrap().rows[0];

assert_eq!(*row.revision.value().unwrap(), expected_revision);
}
Loading
Loading