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:
parent
8747d6682e
commit
1a18f841f7
|
@ -16,6 +16,7 @@ use crate::{
|
||||||
GENESIS_PREVIOUS_BLOCK_HASH,
|
GENESIS_PREVIOUS_BLOCK_HASH,
|
||||||
},
|
},
|
||||||
serialization,
|
serialization,
|
||||||
|
transaction::arbitrary::MAX_ARBITRARY_ITEMS,
|
||||||
transparent::{new_transaction_ordered_outputs, CoinbaseSpendRestriction},
|
transparent::{new_transaction_ordered_outputs, CoinbaseSpendRestriction},
|
||||||
work::{difficulty::CompactDifficulty, equihash},
|
work::{difficulty::CompactDifficulty, equihash},
|
||||||
};
|
};
|
||||||
|
@ -321,7 +322,14 @@ impl Arbitrary for Block {
|
||||||
type Parameters = LedgerState;
|
type Parameters = LedgerState;
|
||||||
|
|
||||||
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
|
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)
|
(Header::arbitrary_with(ledger_state), transactions_strategy)
|
||||||
.prop_map(move |(header, transactions)| Self {
|
.prop_map(move |(header, transactions)| Self {
|
||||||
|
|
|
@ -12,7 +12,7 @@ impl Input {
|
||||||
.prop_map(|input| vec![input])
|
.prop_map(|input| vec![input])
|
||||||
.boxed()
|
.boxed()
|
||||||
} else {
|
} else {
|
||||||
vec(Self::arbitrary_with(None), max_size).boxed()
|
vec(Self::arbitrary_with(None), 1..=max_size).boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue