Extend testcase timeout to prevent panic, seperate anvil feature for testcase. (#28)

* chore: update unit test timeout to avoid panic, seperate anvil feature for testcase use foundry's anvil

* chore: add constant for the timeout number
This commit is contained in:
Vinh Trịnh
2025-08-18 16:09:19 +07:00
committed by GitHub
parent 11b06a440d
commit 1d44d60df2
6 changed files with 24 additions and 11 deletions

4
Cargo.lock generated
View File

@@ -247,9 +247,9 @@ dependencies = [
[[package]]
name = "alloy-hardforks"
version = "0.2.12"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819a3620fe125e0fff365363315ee5e24c23169173b19747dfd6deba33db8990"
checksum = "3165210652f71dfc094b051602bafd691f506c54050a174b1cba18fb5ef706a3"
dependencies = [
"alloy-chains",
"alloy-eip2124",

View File

@@ -32,6 +32,9 @@ mod proof_service_tests {
const TX_HASH_1: [u8; 32] = [0x011; 32];
const TX_HASH_1_2: [u8; 32] = [0x12; 32];
// Set to 10 seconds as 5 seconds can cause failures on Mac M1 machines.
const PROOF_VERIFY_TEST_TIMEOUT: u64 = 10;
#[derive(thiserror::Error, Debug)]
enum AppErrorExt {
#[error("AppError: {0}")]
@@ -87,10 +90,12 @@ mod proof_service_tests {
debug!("Starting broadcast receiver...");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
let res =
tokio::time::timeout(std::time::Duration::from_secs(5), broadcast_receiver.recv())
.await
.map_err(|_e| AppErrorExt::Elapsed)?;
let res = tokio::time::timeout(
std::time::Duration::from_secs(PROOF_VERIFY_TEST_TIMEOUT),
broadcast_receiver.recv(),
)
.await
.map_err(|_e| AppErrorExt::Elapsed)?;
debug!("res: {:?}", res);
let res = res.unwrap();
@@ -190,10 +195,12 @@ mod proof_service_tests {
let mut proof_values_store = vec![];
loop {
let res =
tokio::time::timeout(std::time::Duration::from_secs(5), broadcast_receiver.recv())
.await
.map_err(|_e| AppErrorExt::Elapsed)?;
let res = tokio::time::timeout(
std::time::Duration::from_secs(PROOF_VERIFY_TEST_TIMEOUT),
broadcast_receiver.recv(),
)
.await
.map_err(|_e| AppErrorExt::Elapsed)?;
let res = res.unwrap();
let res = res?;
@@ -337,7 +344,7 @@ mod proof_service_tests {
assert_eq!(secret_hash, user_addr_1.secret_hash);
}
_ => {
panic!("Unexpected result");
panic!("Expected to RecoveredSecret, got: {res:?}");
}
}
}

View File

@@ -28,3 +28,6 @@ zeroize.workspace = true
[dev-dependencies]
claims = "0.8"
[features]
anvil = ["alloy/provider-anvil-node"]

View File

@@ -92,6 +92,7 @@ impl<T: Provider> KarmaAmountExt for KarmaSC::KarmaSCInstance<T> {
}
}
#[cfg(feature = "anvil")]
#[cfg(test)]
pub(crate) mod tests {
use super::*;

View File

@@ -347,6 +347,7 @@ impl std::fmt::Debug for KarmaTiers::Tier {
}
}
#[cfg(feature = "anvil")]
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -113,6 +113,7 @@ impl<T: Provider> RLNRegister for KarmaRLNSC::KarmaRLNSCInstance<T> {
}
}
#[cfg(feature = "anvil")]
#[cfg(test)]
mod tests {
use super::*;