-
Notifications
You must be signed in to change notification settings - Fork 122
feat(ethexe/network): use proptest instead of custom mock #5359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1d5d011
14ebd80
facfee9
7f8feb2
aaa02ad
b64c45b
841ce76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -769,6 +769,7 @@ mod tests { | |
| swarm::{SwarmEvent, behaviour::ExternalAddrConfirmed}, | ||
| }; | ||
| use libp2p_swarm_test::SwarmExt; | ||
| use proptest::{prelude::*, test_runner::Config as ProptestConfig}; | ||
| use std::sync::Arc; | ||
| use tokio::time; | ||
|
|
||
|
|
@@ -800,6 +801,32 @@ mod tests { | |
| .expect("failed to sign validator identity") | ||
| } | ||
|
|
||
| fn signed_identity_strategy() -> impl Strategy<Value = SignedValidatorIdentity> { | ||
| (any::<[u8; 32]>(), any::<[u8; 32]>(), any::<u128>()).prop_filter_map( | ||
| "valid secp256k1 validator and network keys", | ||
| |(validator_seed, mut network_seed, creation_time)| { | ||
| let validator_private_key = PrivateKey::from_seed(validator_seed).ok()?; | ||
| let signer = Signer::memory(); | ||
| let validator_key = signer.import(validator_private_key).ok()?; | ||
|
|
||
| let network_secret = | ||
| libp2p::identity::secp256k1::SecretKey::try_from_bytes(&mut network_seed) | ||
| .ok()?; | ||
| let network_keypair = | ||
| Keypair::from(libp2p::identity::secp256k1::Keypair::from(network_secret)); | ||
| let identity = ValidatorIdentity { | ||
| addresses: ValidatorAddresses::new( | ||
| network_keypair.public().to_peer_id(), | ||
| test_addr(), | ||
| ), | ||
| creation_time, | ||
| }; | ||
|
|
||
| identity.sign(&signer, validator_key, &network_keypair).ok() | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn encode_decode_identity() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test can be removed since proptest fully covers it |
||
| let signer = Signer::memory(); | ||
|
|
@@ -816,6 +843,20 @@ mod tests { | |
| assert_eq!(identity, decoded_identity); | ||
| } | ||
|
|
||
| proptest! { | ||
| #![proptest_config(ProptestConfig::with_cases(64))] | ||
|
|
||
| #[test] | ||
| fn proptest_signed_validator_identity_encode_decode( | ||
| identity in signed_identity_strategy(), | ||
| ) { | ||
| let decoded_identity = | ||
| SignedValidatorIdentity::decode(&mut &identity.encode()[..]).unwrap(); | ||
|
|
||
| prop_assert_eq!(identity, decoded_identity); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn different_peer_ids_in_identity() { | ||
| let signer = Signer::memory(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, remove or rewrite proptests. The only property we want to test is relationship between era index in snapshot and message itself |
Uh oh!
There was an error while loading. Please reload this page.