Skip to content

Commit

Permalink
Avoid excessive Orchard dummies in `TestState::generate_next_block_sp…
Browse files Browse the repository at this point in the history
…ending`
  • Loading branch information
str4d committed Mar 8, 2024
1 parent ea4151c commit 495cae8
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 deletions zcash_client_sqlite/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,29 @@ pub(crate) trait TestFvk {
initial_sapling_tree_size: u32,
rng: &mut R,
) -> Self::Nullifier;

Check failure on line 793 in zcash_client_sqlite/src/testing.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

this function has too many arguments (8/7)

error: this function has too many arguments (8/7) --> zcash_client_sqlite/src/testing.rs:784:5 | 784 | / fn add_compact_output<P: consensus::Parameters, R: RngCore + CryptoRng>( 785 | | &self, 786 | | ctx: &mut CompactTx, 787 | | params: &P, ... | 792 | | rng: &mut R, 793 | | ) -> Self::Nullifier; | |________________________^ | = note: `-D clippy::too-many-arguments` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments

fn add_compact_action<P: consensus::Parameters, R: RngCore + CryptoRng>(
&self,
ctx: &mut CompactTx,
params: &P,
height: BlockHeight,
nf: Self::Nullifier,
req: AddressType,
value: NonNegativeAmount,
initial_sapling_tree_size: u32,
rng: &mut R,
) -> Self::Nullifier {

Check failure on line 805 in zcash_client_sqlite/src/testing.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

this function has too many arguments (9/7)

error: this function has too many arguments (9/7) --> zcash_client_sqlite/src/testing.rs:795:5 | 795 | / fn add_compact_action<P: consensus::Parameters, R: RngCore + CryptoRng>( 796 | | &self, 797 | | ctx: &mut CompactTx, 798 | | params: &P, ... | 804 | | rng: &mut R, 805 | | ) -> Self::Nullifier { | |________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
self.add_compact_spend(ctx, nf, rng);
self.add_compact_output(
ctx,
params,
height,
req,
value,
initial_sapling_tree_size,
rng,
)
}
}

impl TestFvk for DiversifiableFullViewingKey {
Expand Down Expand Up @@ -912,6 +935,36 @@ impl TestFvk for orchard::keys::FullViewingKey {

note.nullifier(self)
}

// Override so we can merge the spend and output into a single action.
fn add_compact_action<P: consensus::Parameters, R: RngCore + CryptoRng>(
&self,
ctx: &mut CompactTx,
_: &P,
_: BlockHeight,
nf: Self::Nullifier,
req: AddressType,
value: NonNegativeAmount,
_: u32,
rng: &mut R,
) -> Self::Nullifier {
let (j, scope) = match req {
AddressType::DefaultExternal => (0u32.into(), zip32::Scope::External),
AddressType::DiversifiedExternal(idx) => (idx, zip32::Scope::External),
AddressType::Internal => (0u32.into(), zip32::Scope::Internal),
};

let (cact, note) = compact_orchard_action(
nf,
self.address_at(j, scope),
value,
self.orchard_ovk(scope),
rng,
);
ctx.actions.push(cact);

note.nullifier(self)
}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -1099,24 +1152,22 @@ fn fake_compact_block_spending<P: consensus::Parameters, Fvk: TestFvk>(
let mut rng = OsRng;
let mut ctx = fake_compact_tx(&mut rng);

// Create a fake spend
fvk.add_compact_spend(&mut ctx, nf, &mut rng);

// Create a fake Note for the payment
ctx.outputs
.push(compact_sapling_output(params, height, to, value, fvk.sapling_ovk(), &mut rng).0);

// Create a fake Note for the change
fvk.add_compact_output(
// Create a fake spend and a fake Note for the change
fvk.add_compact_action(
&mut ctx,
params,
height,
nf,
AddressType::Internal,
(in_value - value).unwrap(),
initial_sapling_tree_size,
&mut rng,
);

// Create a fake Note for the payment
ctx.outputs
.push(compact_sapling_output(params, height, to, value, fvk.sapling_ovk(), &mut rng).0);

fake_compact_block_from_compact_tx(ctx, height, prev_hash, initial_sapling_tree_size, 0)
}

Expand Down

0 comments on commit 495cae8

Please sign in to comment.