Skip to content

Commit 43ea314

Browse files
committed
Copy tests from zsa-issued-assets-tests here and fix compilation errors
1 parent d301946 commit 43ea314

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

zebra-consensus/src/orchard_zsa/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: Consider moving thesr tests to `zebra-consensus/src/router/tests.rs`, or creating a
2+
// `zebra-consensus/src/router/tests` directory and placing this module with a name
3+
// 'orchard_zsa` there.
4+
15
//! Simulates a full Zebra node’s block‐processing pipeline on a predefined Orchard/ZSA workflow.
26
//!
37
//! This integration test reads a sequence of serialized regtest blocks (including Orchard burns

zebra-consensus/src/router/tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,50 @@ async fn verify_fail_add_block_checkpoint() -> Result<(), Report> {
270270

271271
Ok(())
272272
}
273+
274+
// FIXME: Remove this test. The more comprehensive `check_orchard_zsa_workflow` in
275+
// `zebra-consensus/src/orchard_zsa/tests.rs` already verifies everything this test
276+
// covers (and more).
277+
#[tokio::test(flavor = "multi_thread")]
278+
async fn verify_issuance_blocks_test() -> Result<(), Report> {
279+
use block::genesis::regtest_genesis_block;
280+
281+
use zebra_test::vectors::{OrchardWorkflowBlock, ORCHARD_WORKFLOW_BLOCKS_ZSA};
282+
283+
let _init_guard = zebra_test::init();
284+
285+
let network = Network::new_regtest(Some(1), None, Some(1));
286+
let (block_verifier_router, _state_service) = verifiers_from_network(network.clone()).await;
287+
288+
let block_verifier_router =
289+
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(block_verifier_router);
290+
291+
let commit_genesis = [(
292+
Request::Commit(regtest_genesis_block()),
293+
Ok(network.genesis_hash()),
294+
)];
295+
296+
let commit_issuance_blocks =
297+
ORCHARD_WORKFLOW_BLOCKS_ZSA
298+
.iter()
299+
.map(|OrchardWorkflowBlock { bytes, is_valid }| {
300+
let block = Arc::new(
301+
Block::zcash_deserialize(&bytes[..]).expect("block should deserialize"),
302+
);
303+
(
304+
Request::Commit(block.clone()),
305+
if *is_valid {
306+
Ok(block.hash())
307+
} else {
308+
Err(ExpectedTranscriptError::Any)
309+
},
310+
)
311+
});
312+
313+
Transcript::from(commit_genesis.into_iter().chain(commit_issuance_blocks))
314+
.check(block_verifier_router.clone())
315+
.await
316+
.unwrap();
317+
318+
Ok(())
319+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for state contextual validation checks.
22
33
mod anchors;
4+
mod issuance;
45
mod nullifier;
56
mod utxo;
67
mod vectors;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use std::sync::Arc;
2+
3+
use zebra_chain::{
4+
block::{self, genesis::regtest_genesis_block, Block},
5+
orchard_zsa::IssuedAssets,
6+
parameters::Network,
7+
serialization::ZcashDeserialize,
8+
};
9+
10+
use zebra_test::vectors::{OrchardWorkflowBlock, ORCHARD_WORKFLOW_BLOCKS_ZSA};
11+
12+
use crate::{
13+
check::{self, Chain},
14+
service::{finalized_state::FinalizedState, write::validate_and_commit_non_finalized},
15+
CheckpointVerifiedBlock, Config, NonFinalizedState,
16+
};
17+
18+
fn valid_issuance_blocks() -> Vec<Arc<Block>> {
19+
ORCHARD_WORKFLOW_BLOCKS_ZSA
20+
.iter()
21+
.map(|OrchardWorkflowBlock { bytes, .. }| {
22+
Arc::new(Block::zcash_deserialize(&bytes[..]).expect("block should deserialize"))
23+
})
24+
.collect()
25+
}
26+
27+
#[test]
28+
fn check_burns_and_issuance() {
29+
let _init_guard = zebra_test::init();
30+
31+
let network = Network::new_regtest(Some(1), None, Some(1));
32+
33+
let mut finalized_state = FinalizedState::new_with_debug(
34+
&Config::ephemeral(),
35+
&network,
36+
true,
37+
#[cfg(feature = "elasticsearch")]
38+
false,
39+
false,
40+
);
41+
42+
let mut non_finalized_state = NonFinalizedState::new(&network);
43+
44+
let regtest_genesis_block = regtest_genesis_block();
45+
let regtest_genesis_hash = regtest_genesis_block.hash();
46+
47+
finalized_state
48+
.commit_finalized_direct(regtest_genesis_block.into(), None, "test")
49+
.expect("unexpected invalid genesis block test vector");
50+
51+
let block = valid_issuance_blocks().first().unwrap().clone();
52+
let mut header = Arc::<block::Header>::unwrap_or_clone(block.header.clone());
53+
header.previous_block_hash = regtest_genesis_hash;
54+
header.commitment_bytes = [0; 32].into();
55+
let block = Arc::new(Block {
56+
header: Arc::new(header),
57+
transactions: block.transactions.clone(),
58+
});
59+
60+
let CheckpointVerifiedBlock(block) = CheckpointVerifiedBlock::new(block, None, None);
61+
62+
let empty_chain = Chain::new(
63+
&network,
64+
finalized_state
65+
.db
66+
.finalized_tip_height()
67+
.unwrap_or(block::Height::MIN),
68+
finalized_state.db.sprout_tree_for_tip(),
69+
finalized_state.db.sapling_tree_for_tip(),
70+
finalized_state.db.orchard_tree_for_tip(),
71+
finalized_state.db.history_tree(),
72+
finalized_state.db.finalized_value_pool(),
73+
);
74+
75+
let block_1_issued_assets = check::issuance::valid_burns_and_issuance(
76+
&finalized_state.db,
77+
&Arc::new(empty_chain),
78+
&block,
79+
)
80+
.expect("test transactions should be valid");
81+
82+
validate_and_commit_non_finalized(&finalized_state.db, &mut non_finalized_state, block)
83+
.expect("validation should succeed");
84+
85+
let best_chain = non_finalized_state
86+
.best_chain()
87+
.expect("should have a non-finalized chain");
88+
89+
assert_eq!(
90+
IssuedAssets::from(best_chain.issued_assets.clone()),
91+
block_1_issued_assets,
92+
"issued assets for chain should match those of block 1"
93+
);
94+
}

0 commit comments

Comments
 (0)