|
| 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