Skip to content

Commit

Permalink
test: Fix test block_template_is_valid
Browse files Browse the repository at this point in the history
Configuration `tx_proving_capability` defaults to estimating using heuristics.
On some machines, this heuristic resolves to `ProofCollection`, in which case
transactions are produced that cannot be merged.

The fix is to override this setting using the function with more fine-grained
arguments, `create_transaction_with_prover_capability` and feed it
`TxProvingCapability::SingleProof`. This results in transactions whose validity
is supported by `SingleProof`s rather than `ProofCollection`s, which the miner
*can* merge.

When the test is run on a machine not capable of producing a `SingleProof`, it
must rely on a proof server.
  • Loading branch information
aszepieniec committed Oct 12, 2024
1 parent a61d499 commit a12ecdf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/mine_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ mod mine_loop_tests {

#[traced_test]
#[tokio::test]
async fn block_template_is_valid_test() -> Result<()> {
async fn block_template_is_valid_test() {
// Verify that a block template made with transaction from the mempool is a valid block
let network = Network::Main;
let mut alice = mock_genesis_global_state(network, 2, WalletSecret::devnet_wallet()).await;
Expand Down Expand Up @@ -611,20 +611,24 @@ mod mine_loop_tests {
.wallet_state
.wallet_secret
.nth_generation_spending_key_for_tests(0);
let output_to_alice = TxOutput::offchain_native_currency(
NeptuneCoins::new(4),
rng.gen(),
alice_key.to_address().into(),
);
// About ProveCapability::SingleProof:
// The thing being tested is that the block template *for the _miner_*
// is valid. The miner is assumed capable of producing `SingleProof`s.
let (tx_by_preminer, _maybe_change_output) = alice
.lock_guard()
.await
.create_transaction(
vec![TxOutput::offchain_native_currency(
NeptuneCoins::new(4),
rng.gen(),
alice_key.to_address().into(),
)]
.into(),
.create_transaction_with_prover_capability(
vec![output_to_alice].into(),
alice_key.into(),
UtxoNotificationMedium::OffChain,
NeptuneCoins::new(1),
in_seven_months,
TxProvingCapability::SingleProof,
)
.await
.unwrap();
Expand Down Expand Up @@ -663,8 +667,6 @@ mod mine_loop_tests {
.is_valid(&genesis_block, in_seven_months + Timestamp::seconds(2)),
"Block template created by miner with non-empty mempool must be valid"
);

Ok(())
}

/// This test mines a single block at height 1 on the regtest network
Expand Down

2 comments on commit a12ecdf

@Sword-Smith
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix! I'd like to avoid the Result return type on tests though. Can we just unwrap/expect and get a nice, beautiful stack trace instead of having a test return an error?

@aszepieniec
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

Please sign in to comment.