Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting in proptest macros #8252

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading