cleanup(test): Make test debugging output more readable (#7027)
* Fix some debug impls to use hex rather than u8 arrays * Hide extremely long debug data in proptests
This commit is contained in:
parent
17e14d9349
commit
343a683cea
|
@ -162,7 +162,7 @@ where
|
|||
}
|
||||
|
||||
/// Wrapper to override `Debug`, redirecting it to hex-encode the type.
|
||||
/// The type must be hex-encodable.
|
||||
/// The type must implement `AsRef<[u8]>`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
|
||||
#[serde(transparent)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Sprout funds transfers using [`JoinSplit`]s.
|
||||
|
||||
use std::io;
|
||||
use std::{fmt, io};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -49,7 +49,7 @@ impl From<&RandomSeed> for [u8; 32] {
|
|||
/// A _JoinSplit Description_, as described in [protocol specification §7.2][ps].
|
||||
///
|
||||
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#joinsplitencoding
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize)]
|
||||
pub struct JoinSplit<P: ZkSnarkProof> {
|
||||
/// A value that the JoinSplit transfer removes from the transparent value
|
||||
/// pool.
|
||||
|
@ -81,6 +81,23 @@ pub struct JoinSplit<P: ZkSnarkProof> {
|
|||
pub enc_ciphertexts: [note::EncryptedNote; 2],
|
||||
}
|
||||
|
||||
impl<P: ZkSnarkProof> fmt::Debug for JoinSplit<P> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("JoinSplit")
|
||||
.field("vpub_old", &self.vpub_old)
|
||||
.field("vpub_new", &self.vpub_new)
|
||||
.field("anchor", &self.anchor)
|
||||
.field("nullifiers", &self.nullifiers)
|
||||
.field("commitments", &self.commitments)
|
||||
.field("ephemeral_key", &HexDebug(self.ephemeral_key.as_bytes()))
|
||||
.field("random_seed", &self.random_seed)
|
||||
.field("vmacs", &self.vmacs)
|
||||
.field("zkproof", &self.zkproof)
|
||||
.field("enc_ciphertexts", &self.enc_ciphertexts)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
self.vpub_old.zcash_serialize(&mut writer)?;
|
||||
|
|
|
@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::{
|
||||
amount::{self, Amount, NegativeAllowed},
|
||||
fmt::HexDebug,
|
||||
primitives::{ed25519, ZkSnarkProof},
|
||||
sprout::{self, JoinSplit, Nullifier},
|
||||
};
|
||||
|
@ -16,7 +17,7 @@ use crate::{
|
|||
/// description with the required signature data, so that an
|
||||
/// `Option<JoinSplitData>` correctly models the presence or absence of any
|
||||
/// JoinSplit data.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct JoinSplitData<P: ZkSnarkProof> {
|
||||
/// The first JoinSplit description in the transaction,
|
||||
/// using proofs of type `P`.
|
||||
|
@ -48,6 +49,17 @@ pub struct JoinSplitData<P: ZkSnarkProof> {
|
|||
pub sig: ed25519::Signature,
|
||||
}
|
||||
|
||||
impl<P: ZkSnarkProof> fmt::Debug for JoinSplitData<P> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("JoinSplitData")
|
||||
.field("first", &self.first)
|
||||
.field("rest", &self.rest)
|
||||
.field("pub_key", &self.pub_key)
|
||||
.field("sig", &HexDebug(&self.sig.to_bytes()))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ZkSnarkProof> fmt::Display for JoinSplitData<P> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut fmter =
|
||||
|
|
|
@ -11,7 +11,7 @@ use tower::{buffer::Buffer, util::BoxService};
|
|||
|
||||
use zebra_chain::{
|
||||
block::{self, Block},
|
||||
fmt::DisplayToDebug,
|
||||
fmt::{DisplayToDebug, TypeNameToDebug},
|
||||
parameters::{Network, NetworkUpgrade},
|
||||
serialization::ZcashDeserializeInto,
|
||||
transaction::VerifiedUnminedTx,
|
||||
|
@ -103,7 +103,7 @@ proptest! {
|
|||
network in any::<Network>(),
|
||||
mut previous_chain_tip in any::<DisplayToDebug<ChainTipBlock>>(),
|
||||
mut transactions in vec(any::<DisplayToDebug<VerifiedUnminedTx>>(), 0..CHAIN_LENGTH),
|
||||
fake_chain_tips in vec(any::<DisplayToDebug<FakeChainTip>>(), 0..CHAIN_LENGTH),
|
||||
fake_chain_tips in vec(any::<TypeNameToDebug<FakeChainTip>>(), 0..CHAIN_LENGTH),
|
||||
) {
|
||||
let (runtime, _init_guard) = zebra_test::init_async();
|
||||
|
||||
|
|
Loading…
Reference in New Issue