Skip to content

Commit

Permalink
construct ChainConfig from NetworkChain
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 committed Jan 10, 2025
1 parent f20cb1d commit 8ccbdd3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl ApiCommands {
let mut db = vec![];
tracking_db.export_forest_car(&mut db).await?;
RpcTestSnapshot {
chain: chain.clone(),
name: test_dump.request.method_name.to_string(),
params: test_dump.request.params,
response: test_dump.forest_response,
Expand Down
2 changes: 1 addition & 1 deletion src/tool/subcommands/api_cmd/generate_test_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn run_test_with_dump(
CurrentNetwork::set_global(Network::Testnet);
}
let mut run = false;
let chain_config = Arc::new(ChainConfig::calibnet());
let chain_config = Arc::new(ChainConfig::from_chain(chain));
let (ctx, _, _) = ctx(db, chain_config).await?;
let params_raw = Some(serde_json::to_string(&test_dump.request.params)?);
macro_rules! run_test {
Expand Down
10 changes: 7 additions & 3 deletions src/tool/subcommands/api_cmd/test_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
libp2p::{NetworkMessage, PeerManager},
lotus_json::HasLotusJson,
message_pool::{MessagePool, MpoolRpcProvider},
networks::ChainConfig,
networks::{ChainConfig, NetworkChain},
rpc::{eth::filter::EthEventHandler, RPCState, RpcMethod as _, RpcMethodExt as _},
shim::address::{CurrentNetwork, Network},
state_manager::StateManager,
Expand All @@ -26,6 +26,7 @@ use tokio::{sync::mpsc, task::JoinSet};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RpcTestSnapshot {
pub chain: NetworkChain,
pub name: String,
pub params: serde_json::Value,
pub response: Result<serde_json::Value, String>,
Expand All @@ -34,7 +35,6 @@ pub struct RpcTestSnapshot {
}

pub async fn run_test_from_snapshot(path: &Path) -> anyhow::Result<()> {
CurrentNetwork::set_global(Network::Testnet);
let mut run = false;
let snapshot_bytes = std::fs::read(path)?;
let snapshot_bytes = if let Ok(bytes) = zstd::decode_all(snapshot_bytes.as_slice()) {
Expand All @@ -43,13 +43,17 @@ pub async fn run_test_from_snapshot(path: &Path) -> anyhow::Result<()> {
snapshot_bytes
};
let RpcTestSnapshot {
chain,
name: method_name,
params,
db: db_bytes,
response: expected_response,
} = serde_json::from_slice(snapshot_bytes.as_slice())?;
if chain.is_testnet() {
CurrentNetwork::set_global(Network::Testnet);
}
let db = Arc::new(ManyCar::new(MemoryDB::default()).with_read_only(AnyCar::new(db_bytes)?)?);
let chain_config = Arc::new(ChainConfig::calibnet());
let chain_config = Arc::new(ChainConfig::from_chain(&chain));
let (ctx, _, _) = ctx(db, chain_config).await?;
let params_raw = match serde_json::to_string(&params)? {
s if s.is_empty() => None,
Expand Down

0 comments on commit 8ccbdd3

Please sign in to comment.