Skip to content
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

cleanup(test): Make test debugging output more readable #7027

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zebra-chain/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
21 changes: 19 additions & 2 deletions zebra-chain/src/sprout/joinsplit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Sprout funds transfers using [`JoinSplit`]s.

use std::io;
use std::{fmt, io};

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)?;
Expand Down
14 changes: 13 additions & 1 deletion zebra-chain/src/transaction/joinsplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::{
amount::{self, Amount, NegativeAllowed},
fmt::HexDebug,
primitives::{ed25519, ZkSnarkProof},
sprout::{self, JoinSplit, Nullifier},
};
Expand All @@ -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`.
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions zebrad/src/components/mempool/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down