Fix formatting in `proptest` macros (#8252)

This commit is contained in:
Marek 2024-02-09 02:54:54 +01:00 committed by GitHub
parent 20bd156689
commit 130c4e95e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 39 deletions

View File

@ -18,15 +18,15 @@ fn equihash_solution_roundtrip() {
let _init_guard = zebra_test::init(); let _init_guard = zebra_test::init();
proptest!(|(solution in any::<equihash::Solution>())| { proptest!(|(solution in any::<equihash::Solution>())| {
let data = solution let data = solution
.zcash_serialize_to_vec() .zcash_serialize_to_vec()
.expect("randomized EquihashSolution should serialize"); .expect("randomized EquihashSolution should serialize");
let solution2 = data let solution2 = data
.zcash_deserialize_into() .zcash_deserialize_into()
.expect("randomized EquihashSolution should deserialize"); .expect("randomized EquihashSolution should deserialize");
prop_assert_eq![solution, solution2]; prop_assert_eq![solution, solution2];
}); });
} }
prop_compose! { prop_compose! {
@ -94,10 +94,10 @@ fn equihash_prop_test_nonce() -> color_eyre::eyre::Result<()> {
block.header.solution.check(&block.header)?; block.header.solution.check(&block.header)?;
proptest!(|(fake_header in randomized_nonce(*block.header.as_ref()))| { proptest!(|(fake_header in randomized_nonce(*block.header.as_ref()))| {
fake_header.solution fake_header.solution
.check(&fake_header) .check(&fake_header)
.expect_err("block header should not validate on randomized nonce"); .expect_err("block header should not validate on randomized nonce");
}); });
} }
Ok(()) Ok(())

View File

@ -40,40 +40,40 @@ fn push_genesis_chain() -> Result<()> {
let _init_guard = zebra_test::init(); let _init_guard = zebra_test::init();
proptest!( proptest!(
ProptestConfig::with_cases(env::var("PROPTEST_CASES") ProptestConfig::with_cases(env::var("PROPTEST_CASES")
.ok() .ok()
.and_then(|v| v.parse().ok()) .and_then(|v| v.parse().ok())
.unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)), .unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)),
|((chain, count, network, empty_tree) in PreparedChain::default())| { |((chain, count, network, empty_tree) in PreparedChain::default())| {
prop_assert!(empty_tree.is_none()); prop_assert!(empty_tree.is_none());
let mut only_chain = Chain::new(network, Height(0), Default::default(), Default::default(), Default::default(), empty_tree, ValueBalance::zero()); let mut only_chain = Chain::new(network, Height(0), Default::default(), Default::default(), Default::default(), empty_tree, ValueBalance::zero());
// contains the block value pool changes and chain value pool balances for each height // contains the block value pool changes and chain value pool balances for each height
let mut chain_values = BTreeMap::new(); let mut chain_values = BTreeMap::new();
chain_values.insert(None, (None, only_chain.chain_value_pools.into())); chain_values.insert(None, (None, only_chain.chain_value_pools.into()));
for block in chain.iter().take(count).skip(1).cloned() { for block in chain.iter().take(count).skip(1).cloned() {
let block = let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos( ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block, block,
only_chain.unspent_utxos(), only_chain.unspent_utxos(),
) )
.map_err(|e| (e, chain_values.clone())) .map_err(|e| (e, chain_values.clone()))
.expect("invalid block value pool change"); .expect("invalid block value pool change");
chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), None)); chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), None));
only_chain = only_chain only_chain = only_chain
.push(block.clone()) .push(block.clone())
.map_err(|e| (e, chain_values.clone())) .map_err(|e| (e, chain_values.clone()))
.expect("invalid chain value pools"); .expect("invalid chain value pools");
chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), only_chain.chain_value_pools.into())); chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), only_chain.chain_value_pools.into()));
} }
prop_assert_eq!(only_chain.blocks.len(), count - 1); prop_assert_eq!(only_chain.blocks.len(), count - 1);
}); });
Ok(()) Ok(())
} }