change(test): Refactor the tests of non-finalized state (#7262)

* Allow generating blocks with only coinbase tx

* Fix the `forked_equals_pushed_genesis` test
This commit is contained in:
Marek 2023-07-19 23:20:37 +02:00 committed by GitHub
parent 1fa9d61c7c
commit 9ebd56092b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -349,7 +349,9 @@ impl Arbitrary for Block {
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
let transactions_strategy =
(1..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
// Generate a random number transactions. A coinbase tx is always generated, so if
// `transaction_count` is zero, the block will contain only the coinbase tx.
(0..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
Transaction::vec_strategy(ledger_state, transaction_count)
});

View File

@ -170,14 +170,12 @@ fn forked_equals_pushed_genesis() -> Result<()> {
empty_tree,
ValueBalance::zero(),
);
for block in chain.iter().skip(1).cloned() {
for block in chain.iter().cloned() {
let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, full_chain.unspent_utxos())?;
full_chain = full_chain
.push(block.clone())
.expect("full chain push is valid");
// Check some other properties of generated chains.
// Check some properties of the genesis block and don't push it to the chain.
if block.height == block::Height(0) {
prop_assert_eq!(
block
@ -188,11 +186,13 @@ fn forked_equals_pushed_genesis() -> Result<()> {
.filter_map(|i| i.outpoint())
.count(),
0,
"unexpected transparent prevout input at height {:?}: \
genesis transparent outputs must be ignored, \
so there can not be any spends in the genesis block",
block.height,
"Unexpected transparent prevout input at height 0. Genesis transparent outputs \
must be ignored, so there can not be any spends in the genesis block.",
);
} else {
full_chain = full_chain
.push(block)
.expect("full chain push is valid");
}
}