Add a random number of transactions to generated blocks, rather than always 2 (#2567)

* Add 1 to 3 transactions to generated blocks, rather than always 2

This change improves test coverage.

As a side-effect, it reduces the average number of generated
transactions, which should improve performance.

* Add 1 to max_size generated transparent inputs, rather than always max_size

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
This commit is contained in:
teor 2021-08-05 06:48:15 +10:00 committed by GitHub
parent 8747d6682e
commit 1a18f841f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -16,6 +16,7 @@ use crate::{
GENESIS_PREVIOUS_BLOCK_HASH,
},
serialization,
transaction::arbitrary::MAX_ARBITRARY_ITEMS,
transparent::{new_transaction_ordered_outputs, CoinbaseSpendRestriction},
work::{difficulty::CompactDifficulty, equihash},
};
@ -321,7 +322,14 @@ impl Arbitrary for Block {
type Parameters = LedgerState;
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
let transactions_strategy = Transaction::vec_strategy(ledger_state, 2);
let transactions_strategy =
(1..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
Transaction::vec_strategy(ledger_state, transaction_count)
});
// TODO: if needed, fixup:
// - history and authorizing data commitments
// - the transaction merkle root
(Header::arbitrary_with(ledger_state), transactions_strategy)
.prop_map(move |(header, transactions)| Self {

View File

@ -12,7 +12,7 @@ impl Input {
.prop_map(|input| vec![input])
.boxed()
} else {
vec(Self::arbitrary_with(None), max_size).boxed()
vec(Self::arbitrary_with(None), 1..=max_size).boxed()
}
}
}