pub struct TestBuilder<Cache, DataStoreFactory> { /* private fields */ }test-dependencies only.Expand description
A TestState builder, that configures the environment for a test.
Implementations§
Source§impl TestBuilder<(), ()>
impl TestBuilder<(), ()>
Sourcepub const DEFAULT_NETWORK: LocalNetwork
pub const DEFAULT_NETWORK: LocalNetwork
The default network used by TestBuilder::new.
This is a fake network where Sapling through NU5 activate at the same height. We pick height 100,000 to be large enough to handle any hard-coded test offsets.
Source§impl<A> TestBuilder<(), A>
impl<A> TestBuilder<(), A>
Sourcepub fn with_block_cache<C>(self, cache: C) -> TestBuilder<C, A>
pub fn with_block_cache<C>(self, cache: C) -> TestBuilder<C, A>
Adds a block cache to the test environment.
Source§impl<A> TestBuilder<A, ()>
impl<A> TestBuilder<A, ()>
Sourcepub fn with_data_store_factory<DsFactory>(
self,
ds_factory: DsFactory,
) -> TestBuilder<A, DsFactory>
pub fn with_data_store_factory<DsFactory>( self, ds_factory: DsFactory, ) -> TestBuilder<A, DsFactory>
Adds a wallet data store to the test environment.
Source§impl<A, B> TestBuilder<A, B>
impl<A, B> TestBuilder<A, B>
Sourcepub fn with_network(self, network: LocalNetwork) -> Self
pub fn with_network(self, network: LocalNetwork) -> Self
Overrides the network parameters used by the test (the default is
TestBuilder::DEFAULT_NETWORK). This must be called before the account birthday is
established (i.e. before with_account_from_sapling_activation /
with_account_having_current_birthday), because the birthday is derived from the network’s
activation heights.
Sourcepub fn with_anchor_retention_interval(
self,
interval: AnchorRetentionInterval,
) -> Self
pub fn with_anchor_retention_interval( self, interval: AnchorRetentionInterval, ) -> Self
Overrides the interval on which the wallet retains durable anchor checkpoints (the default
is AnchorRetentionInterval::ZIP_318).
A test that must scan past a retained anchor otherwise has to generate 144 blocks per boundary; a short interval makes the same coverage cheap.
pub fn with_gap_limits(self, gap_limits: GapLimits) -> TestBuilder<A, B>
transparent-inputs only.Source§impl<Cache, DsFactory> TestBuilder<Cache, DsFactory>
impl<Cache, DsFactory> TestBuilder<Cache, DsFactory>
Sourcepub fn with_initial_chain_state(
self,
chain_state: impl FnOnce(&mut ChaChaRng, &LocalNetwork) -> InitialChainState,
) -> Self
pub fn with_initial_chain_state( self, chain_state: impl FnOnce(&mut ChaChaRng, &LocalNetwork) -> InitialChainState, ) -> Self
Configures the test to start with the given initial chain state.
§Panics
- Must not be called twice.
- Must be called before
Self::with_account_from_sapling_activationorSelf::with_account_having_current_birthday.
§Examples
use std::num::NonZeroU8;
use incrementalmerkletree::frontier::Frontier;
use zcash_primitives::block::BlockHash;
use zcash_protocol::consensus::{NetworkUpgrade, Parameters};
use zcash_client_backend::data_api::{
chain::{ChainState, CommitmentTreeRoot},
testing::{InitialChainState, TestBuilder},
};
// For this test, we'll start inserting leaf notes 5 notes after the end of the
// third subtree, with a gap of 10 blocks. After `scan_cached_blocks`, the scan
// queue should have a requested scan range of 300..310 with `FoundNote` priority,
// 310..320 with `Scanned` priority. We set both Sapling and Orchard to the same
// initial tree size for simplicity.
let prior_block_hash = BlockHash([0; 32]);
let initial_sapling_tree_size: u32 = (0x1 << 16) * 3 + 5;
let initial_orchard_tree_size: u32 = (0x1 << 16) * 3 + 5;
let initial_height_offset = 310;
let mut st = TestBuilder::new()
.with_initial_chain_state(|rng, network| {
// For simplicity, assume Sapling and NU5 activated at the same height.
let sapling_activation_height =
network.activation_height(NetworkUpgrade::Sapling).unwrap();
// Construct a fake chain state for the end of block 300
let (prior_sapling_roots, sapling_initial_tree) =
Frontier::random_with_prior_subtree_roots(
rng,
initial_sapling_tree_size.into(),
NonZeroU8::new(16).unwrap(),
);
let prior_sapling_roots = prior_sapling_roots
.into_iter()
.zip(1u32..)
.map(|(root, i)| {
CommitmentTreeRoot::from_parts(sapling_activation_height + (100 * i), root)
})
.collect::<Vec<_>>();
#[cfg(feature = "orchard")]
let (prior_orchard_roots, orchard_initial_tree) =
Frontier::random_with_prior_subtree_roots(
rng,
initial_orchard_tree_size.into(),
NonZeroU8::new(16).unwrap(),
);
#[cfg(feature = "orchard")]
let prior_orchard_roots = prior_orchard_roots
.into_iter()
.zip(1u32..)
.map(|(root, i)| {
CommitmentTreeRoot::from_parts(sapling_activation_height + (100 * i), root)
})
.collect::<Vec<_>>();
InitialChainState {
chain_state: ChainState::new(
sapling_activation_height + initial_height_offset - 1,
prior_block_hash,
sapling_initial_tree,
#[cfg(feature = "orchard")]
orchard_initial_tree,
#[cfg(feature = "orchard")]
Frontier::empty(),
),
prior_sapling_roots,
#[cfg(feature = "orchard")]
prior_orchard_roots,
}
});Sourcepub fn with_account_from_sapling_activation(self, prev_hash: BlockHash) -> Self
pub fn with_account_from_sapling_activation(self, prev_hash: BlockHash) -> Self
Configures the environment with a TestAccount that has a birthday at Sapling
activation.
§Panics
- Must not be called twice.
- Do not call both
Self::with_account_having_current_birthdayand this method.
Sourcepub fn with_account_having_current_birthday(self) -> Self
pub fn with_account_having_current_birthday(self) -> Self
Configures the environment with a TestAccount that has a birthday one block
after the initial chain state.
§Panics
- Must not be called twice.
- Must call
Self::with_initial_chain_statebefore calling this method. - Do not call both
Self::with_account_from_sapling_activationand this method.
Sourcepub fn set_account_index(self, index: AccountId) -> Self
pub fn set_account_index(self, index: AccountId) -> Self
Sets the account index for the test account.
Does nothing unless either Self::with_account_from_sapling_activation or
Self::with_account_having_current_birthday is also called.
§Panics
- Must not be called twice.
Source§impl<Cache, DsFactory: DataStoreFactory> TestBuilder<Cache, DsFactory>
impl<Cache, DsFactory: DataStoreFactory> TestBuilder<Cache, DsFactory>
Trait Implementations§
Auto Trait Implementations§
impl<Cache, DataStoreFactory> Freeze for TestBuilder<Cache, DataStoreFactory>
impl<Cache, DataStoreFactory> RefUnwindSafe for TestBuilder<Cache, DataStoreFactory>where
Cache: RefUnwindSafe,
DataStoreFactory: RefUnwindSafe,
impl<Cache, DataStoreFactory> Send for TestBuilder<Cache, DataStoreFactory>
impl<Cache, DataStoreFactory> Sync for TestBuilder<Cache, DataStoreFactory>
impl<Cache, DataStoreFactory> Unpin for TestBuilder<Cache, DataStoreFactory>
impl<Cache, DataStoreFactory> UnsafeUnpin for TestBuilder<Cache, DataStoreFactory>where
Cache: UnsafeUnpin,
DataStoreFactory: UnsafeUnpin,
impl<Cache, DataStoreFactory> UnwindSafe for TestBuilder<Cache, DataStoreFactory>where
Cache: UnwindSafe,
DataStoreFactory: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.