Skip to content

Commit

Permalink
fix: address test data race (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Jan 17, 2025
1 parent cec6940 commit 9ced379
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ wasm-bindgen = "0.2"
worker = { version = "0.5", features = ['http', 'axum'], optional = true }
worker-macros = { version = "0.5", features = ['http'], optional = true }

[dev-dependencies]
rusty-fork = "0.3.0"

[features]
hydrate = ["leptos/hydrate"]
ssr = [
Expand Down
9 changes: 9 additions & 0 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ pub fn parse_address(raw: &str, n: Network) -> anyhow::Result<Address> {
#[cfg(test)]
mod tests {
use super::*;
// Whenever we change the network in tests, we need to fork the test to avoid
// changing the network for other tests. This is because the network is a global
// variable. This is not a problem when run with `cargo nextest` because each test
// is run separately.
use fvm_shared::address::set_current_network;
use rusty_fork::rusty_fork_test;

#[test]
fn test_check_address_prefix() {
Expand All @@ -67,6 +72,7 @@ mod tests {
assert!(!is_valid_prefix("456...", Network::Testnet));
}

rusty_fork_test! {
#[test]
fn test_parse_mainnet_address() {
let addr_str = "f1alg2sxw32ns3ech2w7r3dmp2gl2fputkl7x7jta";
Expand All @@ -75,7 +81,9 @@ mod tests {
set_current_network(Network::Mainnet); // Required to correctly stringify address
assert_eq!(addr.to_string(), addr_str);
}
}

rusty_fork_test! {
#[test]
fn test_parse_testnet_address() {
let addr_str = "t410f2oekwcmo2pueydmaq53eic2i62crtbeyuzx2gmy";
Expand All @@ -84,6 +92,7 @@ mod tests {
set_current_network(Network::Testnet); // Required to correctly stringify address
assert_eq!(addr.to_string(), addr_str);
}
}

#[test]
fn test_parse_wrong_network() {
Expand Down

0 comments on commit 9ced379

Please sign in to comment.