Skip to content

Commit 78efaa5

Browse files
committed
fix: address comments
1 parent 4cda8ac commit 78efaa5

6 files changed

Lines changed: 47 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/foreign-chain-config-tester/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ foreign-chain-rpc-interfaces = { workspace = true }
1717
hex = { workspace = true }
1818
http = { workspace = true }
1919
mpc-node-config = { workspace = true }
20+
serde = { workspace = true }
2021
serde_yaml = { workspace = true }
2122
tokio = { workspace = true }
2223
toml = { workspace = true }

crates/foreign-chain-config-tester/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,22 @@ cargo run -p foreign-chain-config-tester -- --config user-config.toml --network
3535

3636
## Output
3737

38-
A row per provider, plus a summary line. The process exits non-zero if any
39-
provider failed.
38+
A row per provider, a summary line, and the reason for each failure listed
39+
below the table. The process exits non-zero if any provider failed.
4040

4141
```
4242
CHAIN PROVIDER RESULT
4343
abstract public ✓ ok
4444
bitcoin public ✓ ok
45-
starknet public ✗ inner network client failed to fetch: Transaction hash not found
45+
starknet public ✗ failed
4646
aptos public – skipped (no testnet reference transaction for this chain)
4747
4848
3 passed, 1 failed, 1 skipped
49+
50+
Failures:
51+
starknet / public: inner network client failed to fetch: Transaction hash not found
4952
```
53+
54+
> **Note:** for providers that carry the API key in the URL (`path` / `query`
55+
> auth), a failure message may include that URL, and therefore the key. Scrub any
56+
> secrets from the output before sharing it.

crates/foreign-chain-config-tester/src/config.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
use std::path::Path;
88

99
use anyhow::{Context, bail};
10-
use mpc_node_config::ForeignChainsConfig;
10+
use mpc_node_config::{ChainId, ForeignChainsConfig};
11+
use serde::Deserialize;
12+
use serde::de::IntoDeserializer;
13+
use serde::de::value::{Error as ValueError, StrDeserializer};
1114

1215
use crate::golden::Network;
1316

@@ -31,9 +34,13 @@ const CONTRACT_ID_PATHS: &[&[&str]] = &[
3134
];
3235

3336
fn classify_network(chain_id: Option<&str>, contract_id: Option<&str>) -> Option<Network> {
34-
match chain_id {
35-
Some("mainnet") => return Some(Network::Mainnet),
36-
Some("testnet") => return Some(Network::Testnet),
37+
let parsed = chain_id.and_then(|id| {
38+
let de: StrDeserializer<'_, ValueError> = id.into_deserializer();
39+
ChainId::deserialize(de).ok()
40+
});
41+
match parsed {
42+
Some(ChainId::Mainnet) => return Some(Network::Mainnet),
43+
Some(ChainId::Testnet) => return Some(Network::Testnet),
3744
_ => {}
3845
}
3946
match contract_id {

crates/foreign-chain-config-tester/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod config;
66
mod golden;
77
mod report;
88

9+
use std::fs;
910
use std::future::Future;
1011
use std::path::PathBuf;
1112
use std::process::ExitCode;
@@ -24,6 +25,7 @@ use foreign_chain_inspector::polygon::inspector::Polygon;
2425
use foreign_chain_inspector::{RpcAuthentication, build_http_client};
2526
use foreign_chain_rpc_auth::auth_config_to_rpc_auth;
2627
use http::{HeaderName, HeaderValue};
28+
use mpc_node_config::foreign_chains::RpcProviderName;
2729
use mpc_node_config::{ForeignChainConfig, ForeignChainProviderConfig, ForeignChainsConfig};
2830

2931
use crate::golden::{AptosVector, BlockHashVector, Network};
@@ -48,7 +50,7 @@ struct Args {
4850
#[tokio::main]
4951
async fn main() -> anyhow::Result<ExitCode> {
5052
let args = Args::parse();
51-
let contents = std::fs::read_to_string(&args.config)
53+
let contents = fs::read_to_string(&args.config)
5254
.with_context(|| format!("failed to read {}", args.config.display()))?;
5355
let foreign_chains = config::parse_foreign_chains(&contents, &args.config)?;
5456
let network = match args.network {
@@ -125,7 +127,7 @@ fn timeout_of(cfg: &ForeignChainConfig) -> Duration {
125127
Duration::from_secs(cfg.timeout_sec.get())
126128
}
127129

128-
fn provider_name(name: &mpc_node_config::foreign_chains::RpcProviderName) -> String {
130+
fn provider_name(name: &RpcProviderName) -> String {
129131
name.as_str().to_owned()
130132
}
131133

crates/foreign-chain-config-tester/src/report.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub fn any_failed(results: &[ProviderResult]) -> bool {
3333
.any(|r| matches!(r.status, Status::Failed(_)))
3434
}
3535

36-
/// Render the results as an aligned table plus a summary line.
36+
/// Render an aligned table and summary. Failure reasons are listed below the
37+
/// table (not in the `RESULT` column) so a long or multi-line error can't break
38+
/// the alignment.
3739
pub fn render(results: &[ProviderResult]) -> String {
3840
if results.is_empty() {
3941
return "No foreign chains configured — nothing to check.\n".to_string();
@@ -42,15 +44,15 @@ pub fn render(results: &[ProviderResult]) -> String {
4244
let chain_w = results
4345
.iter()
4446
.map(|r| r.chain.len())
45-
.chain(std::iter::once("CHAIN".len()))
4647
.max()
47-
.unwrap_or(0);
48+
.unwrap_or(0)
49+
.max("CHAIN".len());
4850
let provider_w = results
4951
.iter()
5052
.map(|r| r.provider.len())
51-
.chain(std::iter::once("PROVIDER".len()))
5253
.max()
53-
.unwrap_or(0);
54+
.unwrap_or(0)
55+
.max("PROVIDER".len());
5456

5557
let mut out = String::new();
5658
let _ = writeln!(
@@ -66,9 +68,9 @@ pub fn render(results: &[ProviderResult]) -> String {
6668
passed += 1;
6769
"✓ ok".to_string()
6870
}
69-
Status::Failed(reason) => {
71+
Status::Failed(_) => {
7072
failed += 1;
71-
format!("✗ {reason}")
73+
"✗ failed".to_string()
7274
}
7375
Status::Skipped(reason) => {
7476
skipped += 1;
@@ -82,7 +84,17 @@ pub fn render(results: &[ProviderResult]) -> String {
8284
);
8385
}
8486

85-
let _ = writeln!(out, "\n{passed} passed, {failed} failed, {skipped} skipped",);
87+
let _ = writeln!(out, "\n{passed} passed, {failed} failed, {skipped} skipped");
88+
89+
if failed > 0 {
90+
let _ = writeln!(out, "\nFailures:");
91+
for r in results {
92+
if let Status::Failed(reason) = &r.status {
93+
let _ = writeln!(out, " {} / {}: {reason}", r.chain, r.provider);
94+
}
95+
}
96+
}
97+
8698
out
8799
}
88100

0 commit comments

Comments
 (0)