Clean up proptest generation for unified containers.
This commit is contained in:
parent
e3c67ffee6
commit
8d34e62114
|
@ -136,21 +136,20 @@ mod tests {
|
||||||
|
|
||||||
/// A strategy to generate an arbitrary valid set of typecodes without
|
/// A strategy to generate an arbitrary valid set of typecodes without
|
||||||
/// duplication and containing only one of P2sh and P2pkh transparent
|
/// duplication and containing only one of P2sh and P2pkh transparent
|
||||||
/// typecodes.
|
/// typecodes. The resulting vector will be sorted in encoding order.
|
||||||
fn arb_typecodes() -> impl Strategy<Value = Vec<Typecode>> {
|
fn arb_typecodes() -> impl Strategy<Value = Vec<Typecode>> {
|
||||||
prop::option::of(arb_transparent_typecode())
|
prop::option::of(arb_transparent_typecode()).prop_flat_map(|transparent| {
|
||||||
.prop_flat_map(|transparent| {
|
prop::collection::hash_set(arb_shielded_typecode(), 1..4).prop_map(move |xs| {
|
||||||
prop::collection::hash_set(arb_shielded_typecode(), 1..4)
|
let mut typecodes: Vec<_> = xs.into_iter().chain(transparent).collect();
|
||||||
.prop_map(move |xs| xs.into_iter().chain(transparent).collect())
|
typecodes.sort_unstable_by(Typecode::encoding_order);
|
||||||
.boxed()
|
typecodes
|
||||||
})
|
})
|
||||||
.prop_shuffle()
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arb_unified_address_for_typecodes(
|
fn arb_unified_address_for_typecodes(
|
||||||
mut typecodes: Vec<Typecode>,
|
typecodes: Vec<Typecode>,
|
||||||
) -> impl Strategy<Value = Vec<Receiver>> {
|
) -> impl Strategy<Value = Vec<Receiver>> {
|
||||||
typecodes.sort_unstable_by(Typecode::encoding_order);
|
|
||||||
typecodes
|
typecodes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tc| match tc {
|
.map(|tc| match tc {
|
||||||
|
|
|
@ -171,16 +171,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arb_shielded_fvk() -> impl Strategy<Value = Vec<Fvk>> {
|
fn arb_shielded_fvk() -> impl Strategy<Value = Vec<Fvk>> {
|
||||||
let p = prop_oneof![
|
prop_oneof![
|
||||||
vec![arb_sapling_fvk().boxed()],
|
vec![arb_sapling_fvk().boxed()],
|
||||||
vec![arb_orchard_fvk().boxed()],
|
vec![arb_orchard_fvk().boxed()],
|
||||||
vec![arb_orchard_fvk().boxed(), arb_sapling_fvk().boxed()],
|
vec![arb_sapling_fvk().boxed(), arb_orchard_fvk().boxed()],
|
||||||
];
|
]
|
||||||
|
|
||||||
p.prop_map(|mut items| {
|
|
||||||
items.sort_unstable_by(Fvk::encoding_order);
|
|
||||||
items
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arb_transparent_fvk() -> BoxedStrategy<Fvk> {
|
fn arb_transparent_fvk() -> BoxedStrategy<Fvk> {
|
||||||
|
@ -192,7 +187,7 @@ mod tests {
|
||||||
shielded in arb_shielded_fvk(),
|
shielded in arb_shielded_fvk(),
|
||||||
transparent in prop::option::of(arb_transparent_fvk()),
|
transparent in prop::option::of(arb_transparent_fvk()),
|
||||||
) -> Ufvk {
|
) -> Ufvk {
|
||||||
let mut items: Vec<_> = shielded.into_iter().chain(transparent).collect();
|
let mut items: Vec<_> = transparent.into_iter().chain(shielded).collect();
|
||||||
items.sort_unstable_by(Fvk::encoding_order);
|
items.sort_unstable_by(Fvk::encoding_order);
|
||||||
Ufvk(items)
|
Ufvk(items)
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,19 +161,14 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arb_shielded_ivk() -> impl Strategy<Value = Vec<Ivk>> {
|
fn arb_shielded_ivk() -> impl Strategy<Value = Vec<Ivk>> {
|
||||||
let p = prop_oneof![
|
prop_oneof![
|
||||||
vec![uniform64().prop_map(Ivk::Sapling)],
|
vec![uniform64().prop_map(Ivk::Sapling)],
|
||||||
vec![uniform64().prop_map(Ivk::Orchard)],
|
vec![uniform64().prop_map(Ivk::Orchard)],
|
||||||
vec![
|
vec![
|
||||||
uniform64().prop_map(Ivk::Orchard as fn([u8; 64]) -> Ivk),
|
uniform64().prop_map(Ivk::Sapling as fn([u8; 64]) -> Ivk),
|
||||||
uniform64().prop_map(Ivk::Sapling)
|
uniform64().prop_map(Ivk::Orchard)
|
||||||
],
|
],
|
||||||
];
|
]
|
||||||
|
|
||||||
p.prop_map(|mut items| {
|
|
||||||
items.sort_unstable_by(Ivk::encoding_order);
|
|
||||||
items
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arb_transparent_ivk() -> impl Strategy<Value = Ivk> {
|
fn arb_transparent_ivk() -> impl Strategy<Value = Ivk> {
|
||||||
|
@ -185,7 +180,7 @@ mod tests {
|
||||||
shielded in arb_shielded_ivk(),
|
shielded in arb_shielded_ivk(),
|
||||||
transparent in prop::option::of(arb_transparent_ivk()),
|
transparent in prop::option::of(arb_transparent_ivk()),
|
||||||
) -> Uivk {
|
) -> Uivk {
|
||||||
let mut items: Vec<_> = shielded.into_iter().chain(transparent).collect();
|
let mut items: Vec<_> = transparent.into_iter().chain(shielded).collect();
|
||||||
items.sort_unstable_by(Ivk::encoding_order);
|
items.sort_unstable_by(Ivk::encoding_order);
|
||||||
Uivk(items)
|
Uivk(items)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue