feat: return errors instead of doing asserts
This commit is contained in:
@@ -36,7 +36,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct TestRunner {
|
pub struct TestRunner {
|
||||||
package: String,
|
|
||||||
tycho_logs: bool,
|
tycho_logs: bool,
|
||||||
db_url: String,
|
db_url: String,
|
||||||
vm_traces: bool,
|
vm_traces: bool,
|
||||||
@@ -46,7 +45,7 @@ pub struct TestRunner {
|
|||||||
impl TestRunner {
|
impl TestRunner {
|
||||||
pub fn new(package: String, tycho_logs: bool, db_url: String, vm_traces: bool) -> Self {
|
pub fn new(package: String, tycho_logs: bool, db_url: String, vm_traces: bool) -> Self {
|
||||||
let substreams_path = PathBuf::from("../substreams").join(&package);
|
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<()> {
|
pub fn run_tests(&self) -> miette::Result<()> {
|
||||||
@@ -232,15 +231,9 @@ fn validate_state(
|
|||||||
for expected_component in expected_components {
|
for expected_component in expected_components {
|
||||||
let component_id = expected_component.base.id.clone();
|
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
|
let component = components_by_id
|
||||||
.get(&component_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
|
let diff = expected_component
|
||||||
.base
|
.base
|
||||||
@@ -296,11 +289,13 @@ fn validate_state(
|
|||||||
component_address,
|
component_address,
|
||||||
start_block,
|
start_block,
|
||||||
));
|
));
|
||||||
assert_eq!(
|
if balance != node_balance {
|
||||||
balance, node_balance,
|
return Err(miette!(
|
||||||
"Token balance mismatch for component {} and token {}",
|
"Token balance mismatch for component {} and token {}",
|
||||||
component.id, token
|
component.id,
|
||||||
);
|
token
|
||||||
|
))
|
||||||
|
}
|
||||||
info!(
|
info!(
|
||||||
"Token balance for component {} and token {} matches the expected value",
|
"Token balance for component {} and token {} matches the expected value",
|
||||||
component.id, token
|
component.id, token
|
||||||
|
|||||||
@@ -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
|
// 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 {
|
impl TychoRunner {
|
||||||
pub fn new(db_url: String, initialized_accounts: Vec<String>, with_binary_logs: bool) -> Self {
|
pub fn new(db_url: String, initialized_accounts: Vec<String>, with_binary_logs: bool) -> Self {
|
||||||
Self { db_url, initialized_accounts, with_binary_logs }
|
Self { db_url, initialized_accounts, with_binary_logs }
|
||||||
|
|||||||
Reference in New Issue
Block a user