Add a little proptest around Magic's Debug impl
This commit is contained in:
parent
9709b54c57
commit
c2411f4315
|
@ -1,8 +1,12 @@
|
||||||
use hex;
|
use hex;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use proptest_derive::Arbitrary;
|
||||||
|
|
||||||
/// A magic number identifying the network.
|
/// A magic number identifying the network.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(test, derive(Arbitrary))]
|
||||||
pub struct Magic(pub [u8; 4]);
|
pub struct Magic(pub [u8; 4]);
|
||||||
|
|
||||||
impl fmt::Debug for Magic {
|
impl fmt::Debug for Magic {
|
||||||
|
@ -67,3 +71,31 @@ mod tests {
|
||||||
assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")");
|
assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod proptest {
|
||||||
|
|
||||||
|
use hex;
|
||||||
|
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
use super::Magic;
|
||||||
|
|
||||||
|
// impl Arbitrary for Magic {
|
||||||
|
// type Parameters = ();
|
||||||
|
|
||||||
|
// fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
|
||||||
|
// Magic
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type Strategy = BoxedStrategy<Self>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn proptest_magic_from_array(data in any::<[u8; 4]>()) {
|
||||||
|
assert_eq!(format!("{:?}", Magic(data)), format!("Magic({:x?})", hex::encode(data)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,40 +1,20 @@
|
||||||
#[cfg(test)]
|
|
||||||
use proptest_derive::Arbitrary;
|
|
||||||
|
|
||||||
use crate::meta_addr::MetaAddr;
|
use crate::meta_addr::MetaAddr;
|
||||||
|
|
||||||
use super::super::types::Nonce;
|
use super::super::types::Nonce;
|
||||||
|
|
||||||
/// A network request, represented in internal format.
|
/// A network request, represented in internal format.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[cfg_attr(test, derive(Arbitrary))]
|
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
/// Requests additional peers from the server.
|
/// Requests additional peers from the server.
|
||||||
GetPeers,
|
GetPeers,
|
||||||
/// Advertises peers to the remote server.
|
/// Advertises peers to the remote server.
|
||||||
#[cfg_attr(test, proptest(skip))]
|
|
||||||
PushPeers(Vec<MetaAddr>),
|
PushPeers(Vec<MetaAddr>),
|
||||||
/// Heartbeats triggered on peer connection start.
|
/// Heartbeats triggered on peer connection start.
|
||||||
// This is included as a bit of a hack, it should only be used
|
// This is included as a bit of a hack, it should only be used
|
||||||
// internally for connection management. You should not expect to
|
// internally for connection management. You should not expect to
|
||||||
// be firing or handling `Ping` requests or `Pong` responses.
|
// be firing or handling `Ping` requests or `Pong` responses.
|
||||||
#[cfg_attr(test, proptest(skip))]
|
|
||||||
Ping(Nonce),
|
Ping(Nonce),
|
||||||
/// Requests the transactions the remote server has verified but
|
/// Requests the transactions the remote server has verified but
|
||||||
/// not yet confirmed.
|
/// not yet confirmed.
|
||||||
GetMempool,
|
GetMempool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use proptest::prelude::*;
|
|
||||||
|
|
||||||
use super::Request;
|
|
||||||
|
|
||||||
proptest! {
|
|
||||||
#[test]
|
|
||||||
fn proptest_response(res in any::<Request>()) {
|
|
||||||
println!("{:?}", res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use proptest_derive::Arbitrary;
|
|
||||||
|
|
||||||
// XXX clean module layout of zebra_chain
|
// XXX clean module layout of zebra_chain
|
||||||
use zebra_chain::transaction::Transaction;
|
use zebra_chain::transaction::Transaction;
|
||||||
|
|
||||||
|
@ -10,17 +7,14 @@ use crate::meta_addr::MetaAddr;
|
||||||
|
|
||||||
/// A response to a network request, represented in internal format.
|
/// A response to a network request, represented in internal format.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[cfg_attr(test, derive(Arbitrary))]
|
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
/// Generic success.
|
/// Generic success.
|
||||||
Ok,
|
Ok,
|
||||||
/// Generic error.
|
/// Generic error.
|
||||||
Error,
|
Error,
|
||||||
/// A list of peers, used to respond to `GetPeers`.
|
/// A list of peers, used to respond to `GetPeers`.
|
||||||
#[cfg_attr(test, proptest(skip))]
|
|
||||||
Peers(Vec<MetaAddr>),
|
Peers(Vec<MetaAddr>),
|
||||||
/// A list of transactions, such as in response to `GetMempool
|
/// A list of transactions, such as in response to `GetMempool
|
||||||
#[cfg_attr(test, proptest(skip))]
|
|
||||||
Transactions(Vec<Transaction>),
|
Transactions(Vec<Transaction>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,17 +26,3 @@ where
|
||||||
Self::Error
|
Self::Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use proptest::prelude::*;
|
|
||||||
|
|
||||||
use super::Response;
|
|
||||||
|
|
||||||
proptest! {
|
|
||||||
#[test]
|
|
||||||
fn proptest_response(res in any::<Response>()) {
|
|
||||||
println!("{:?}", res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue