Skip to content

Commit

Permalink
feat: First async proptest, for Gateway::run
Browse files Browse the repository at this point in the history
  • Loading branch information
vvp committed Jul 6, 2023
1 parent bca259f commit ff67ccb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
18 changes: 8 additions & 10 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions node/narwhal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,5 @@ version = "0.3"
features = [ "env-filter" ]

[dev-dependencies]
test-strategy = "0.3.0"
proptest = "1.0.0"
rand_xorshift = "0.3.0"
test-strategy = { git = "https://github.com/frozenlib/test-strategy/", branch = "master"}
proptest = "1.0.0"
25 changes: 24 additions & 1 deletion node/narwhal/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,12 @@ mod tests {
MAX_COMMITTEE_SIZE,
MEMORY_POOL_PORT,
};
use indexmap::IndexMap;
use parking_lot::RwLock;
use snarkos_node_tcp::P2P;
use snarkvm::prelude::Testnet3;
use std::{
net::{IpAddr, Ipv4Addr},
net::{IpAddr, Ipv4Addr, SocketAddr},
sync::Arc,
};
use test_strategy::{proptest, Arbitrary};
Expand Down Expand Up @@ -858,4 +859,26 @@ mod tests {
assert_eq!(tcp_config.max_connections, MAX_COMMITTEE_SIZE);
assert_eq!(gateway.account().address(), address);
}

#[proptest(async = "tokio")]
async fn gateway_start(#[filter(|x| x.dev.is_some())] input: GatewayInput) {
let Some(dev) = input.dev else { unreachable!() };
let mut gateway = input.to_gateway();
let tcp_config = gateway.tcp().config();
assert_eq!(tcp_config.listener_ip, Some(IpAddr::V4(Ipv4Addr::LOCALHOST)));
assert_eq!(tcp_config.desired_listening_port, Some(MEMORY_POOL_PORT + (dev as u16)));

match gateway.run(IndexMap::new()).await {
Ok(_) => {
assert_eq!(
gateway.local_ip(),
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), MEMORY_POOL_PORT + (dev as u16))
);
assert_eq!(gateway.num_workers(), 0);
}
Err(err) => {
panic!("Shouldn't fail because of {err}");
}
}
}
}

0 comments on commit ff67ccb

Please sign in to comment.