From ae6f5e0a12ddc8a0e4a7e5c5f14c23783e8d1f8e Mon Sep 17 00:00:00 2001 From: adrian Date: Wed, 3 Sep 2025 12:14:04 +0200 Subject: [PATCH] feat: return errors instead of doing asserts --- protocol-testing/src/test_runner.rs | 23 +++++++++-------------- protocol-testing/src/tycho_runner.rs | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/protocol-testing/src/test_runner.rs b/protocol-testing/src/test_runner.rs index 2027ba0..07f1c5a 100644 --- a/protocol-testing/src/test_runner.rs +++ b/protocol-testing/src/test_runner.rs @@ -36,7 +36,6 @@ use crate::{ }; pub struct TestRunner { - package: String, tycho_logs: bool, db_url: String, vm_traces: bool, @@ -46,7 +45,7 @@ pub struct TestRunner { impl TestRunner { pub fn new(package: String, tycho_logs: bool, db_url: String, vm_traces: bool) -> Self { let substreams_path = PathBuf::from("../substreams").join(&package); - Self { package, tycho_logs, db_url, vm_traces, substreams_path } + Self { tycho_logs, db_url, vm_traces, substreams_path } } pub fn run_tests(&self) -> miette::Result<()> { @@ -232,15 +231,9 @@ fn validate_state( for expected_component in expected_components { let component_id = expected_component.base.id.clone(); - assert!( - components_by_id.contains_key(&component_id), - "Component {:?} was not found on Tycho", - component_id - ); - let component = components_by_id .get(&component_id) - .expect("Failed to get component from Tycho"); + .ok_or_else(|| miette!("Component {:?} was not found on Tycho", component_id))?; let diff = expected_component .base @@ -296,11 +289,13 @@ fn validate_state( component_address, start_block, )); - assert_eq!( - balance, node_balance, - "Token balance mismatch for component {} and token {}", - component.id, token - ); + if balance != node_balance { + return Err(miette!( + "Token balance mismatch for component {} and token {}", + component.id, + token + )) + } info!( "Token balance for component {} and token {} matches the expected value", component.id, token diff --git a/protocol-testing/src/tycho_runner.rs b/protocol-testing/src/tycho_runner.rs index 0bf5bc4..b59136e 100644 --- a/protocol-testing/src/tycho_runner.rs +++ b/protocol-testing/src/tycho_runner.rs @@ -19,7 +19,7 @@ pub struct TychoRunner { } // TODO: Currently Tycho-Indexer cannot be run as a lib. We need to expose the entrypoints to allow -// running it as a lib +// running it as a lib impl TychoRunner { pub fn new(db_url: String, initialized_accounts: Vec, with_binary_logs: bool) -> Self { Self { db_url, initialized_accounts, with_binary_logs }