Skip to content

Commit

Permalink
Fix formatting in proptest macros
Browse files Browse the repository at this point in the history
  • Loading branch information
upbqdn committed Feb 8, 2024
1 parent 20bd156 commit 7c4ed30
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
26 changes: 13 additions & 13 deletions zebra-chain/src/work/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ fn equihash_solution_roundtrip() {
let _init_guard = zebra_test::init();

proptest!(|(solution in any::<equihash::Solution>())| {
let data = solution
.zcash_serialize_to_vec()
.expect("randomized EquihashSolution should serialize");
let solution2 = data
.zcash_deserialize_into()
.expect("randomized EquihashSolution should deserialize");

prop_assert_eq![solution, solution2];
});
let data = solution
.zcash_serialize_to_vec()
.expect("randomized EquihashSolution should serialize");
let solution2 = data
.zcash_deserialize_into()
.expect("randomized EquihashSolution should deserialize");

prop_assert_eq![solution, solution2];
});
}

prop_compose! {
Expand Down Expand Up @@ -94,10 +94,10 @@ fn equihash_prop_test_nonce() -> color_eyre::eyre::Result<()> {
block.header.solution.check(&block.header)?;

proptest!(|(fake_header in randomized_nonce(*block.header.as_ref()))| {
fake_header.solution
.check(&fake_header)
.expect_err("block header should not validate on randomized nonce");
});
fake_header.solution
.check(&fake_header)
.expect_err("block header should not validate on randomized nonce");
});
}

Ok(())
Expand Down
66 changes: 33 additions & 33 deletions zebra-state/src/service/non_finalized_state/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,40 @@ fn push_genesis_chain() -> Result<()> {
let _init_guard = zebra_test::init();

proptest!(
ProptestConfig::with_cases(env::var("PROPTEST_CASES")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)),
|((chain, count, network, empty_tree) in PreparedChain::default())| {
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());
// contains the block value pool changes and chain value pool balances for each height
let mut chain_values = BTreeMap::new();

chain_values.insert(None, (None, only_chain.chain_value_pools.into()));

for block in chain.iter().take(count).skip(1).cloned() {
let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block,
only_chain.unspent_utxos(),
)
.map_err(|e| (e, chain_values.clone()))
.expect("invalid block value pool change");

chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), None));

only_chain = only_chain
.push(block.clone())
.map_err(|e| (e, chain_values.clone()))
.expect("invalid chain value pools");

chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), only_chain.chain_value_pools.into()));
}
ProptestConfig::with_cases(env::var("PROPTEST_CASES")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)),
|((chain, count, network, empty_tree) in PreparedChain::default())| {
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());
// contains the block value pool changes and chain value pool balances for each height
let mut chain_values = BTreeMap::new();

chain_values.insert(None, (None, only_chain.chain_value_pools.into()));

prop_assert_eq!(only_chain.blocks.len(), count - 1);
});
for block in chain.iter().take(count).skip(1).cloned() {
let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block,
only_chain.unspent_utxos(),
)
.map_err(|e| (e, chain_values.clone()))
.expect("invalid block value pool change");

chain_values.insert(block.height.into(), (block.chain_value_pool_change.into(), None));

only_chain = only_chain
.push(block.clone())
.map_err(|e| (e, chain_values.clone()))
.expect("invalid chain value pools");

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);
});

Ok(())
}
Expand Down

0 comments on commit 7c4ed30

Please sign in to comment.