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:
teor 2023-06-22 01:02:05 +10:00 committed by GitHub
parent 17e14d9349
commit 343a683cea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 6 deletions

View File

@ -162,7 +162,7 @@ where
} }
/// Wrapper to override `Debug`, redirecting it to hex-encode the type. /// 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)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] #[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
#[serde(transparent)] #[serde(transparent)]

View File

@ -1,6 +1,6 @@
//! Sprout funds transfers using [`JoinSplit`]s. //! Sprout funds transfers using [`JoinSplit`]s.
use std::io; use std::{fmt, io};
use serde::{Deserialize, Serialize}; 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]. /// A _JoinSplit Description_, as described in [protocol specification §7.2][ps].
/// ///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#joinsplitencoding /// [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> { pub struct JoinSplit<P: ZkSnarkProof> {
/// A value that the JoinSplit transfer removes from the transparent value /// A value that the JoinSplit transfer removes from the transparent value
/// pool. /// pool.
@ -81,6 +81,23 @@ pub struct JoinSplit<P: ZkSnarkProof> {
pub enc_ciphertexts: [note::EncryptedNote; 2], 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> { impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
self.vpub_old.zcash_serialize(&mut writer)?; self.vpub_old.zcash_serialize(&mut writer)?;

View File

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
amount::{self, Amount, NegativeAllowed}, amount::{self, Amount, NegativeAllowed},
fmt::HexDebug,
primitives::{ed25519, ZkSnarkProof}, primitives::{ed25519, ZkSnarkProof},
sprout::{self, JoinSplit, Nullifier}, sprout::{self, JoinSplit, Nullifier},
}; };
@ -16,7 +17,7 @@ use crate::{
/// description with the required signature data, so that an /// description with the required signature data, so that an
/// `Option<JoinSplitData>` correctly models the presence or absence of any /// `Option<JoinSplitData>` correctly models the presence or absence of any
/// JoinSplit data. /// JoinSplit data.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct JoinSplitData<P: ZkSnarkProof> { pub struct JoinSplitData<P: ZkSnarkProof> {
/// The first JoinSplit description in the transaction, /// The first JoinSplit description in the transaction,
/// using proofs of type `P`. /// using proofs of type `P`.
@ -48,6 +49,17 @@ pub struct JoinSplitData<P: ZkSnarkProof> {
pub sig: ed25519::Signature, 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> { impl<P: ZkSnarkProof> fmt::Display for JoinSplitData<P> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut fmter = let mut fmter =

View File

@ -11,7 +11,7 @@ use tower::{buffer::Buffer, util::BoxService};
use zebra_chain::{ use zebra_chain::{
block::{self, Block}, block::{self, Block},
fmt::DisplayToDebug, fmt::{DisplayToDebug, TypeNameToDebug},
parameters::{Network, NetworkUpgrade}, parameters::{Network, NetworkUpgrade},
serialization::ZcashDeserializeInto, serialization::ZcashDeserializeInto,
transaction::VerifiedUnminedTx, transaction::VerifiedUnminedTx,
@ -103,7 +103,7 @@ proptest! {
network in any::<Network>(), network in any::<Network>(),
mut previous_chain_tip in any::<DisplayToDebug<ChainTipBlock>>(), mut previous_chain_tip in any::<DisplayToDebug<ChainTipBlock>>(),
mut transactions in vec(any::<DisplayToDebug<VerifiedUnminedTx>>(), 0..CHAIN_LENGTH), 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(); let (runtime, _init_guard) = zebra_test::init_async();