1515
1616use std:: { collections:: BTreeMap , sync:: Arc } ;
1717
18- use chainstate_storage:: {
19- BlockchainStorageRead , BlockchainStorageWrite , TransactionRw , Transactional ,
20- } ;
2118use rstest:: rstest;
2219
23- use crate :: {
24- framework_builder:: TestFrameworkBuilderValue ,
25- get_output_value,
26- key_manager:: KeyManager ,
27- pos_block_builder:: PoSBlockBuilder ,
28- random_tx_maker:: StakingPoolsObserver ,
29- staking_pools:: StakingPools ,
30- utils:: {
31- assert_block_index_opt_identical_to, assert_gen_block_index_identical_to,
32- assert_gen_block_index_opt_identical_to, find_create_pool_tx_in_genesis,
33- outputs_from_block, outputs_from_genesis, SighashInputCommitmentInfoProvider ,
34- } ,
35- BlockBuilder , TestChainstate , TestFrameworkBuilder , TestStore , TxVerificationStrategy ,
36- } ;
3720use chainstate:: { chainstate_interface:: ChainstateInterface , BlockSource , ChainstateError } ;
21+ use chainstate_storage:: {
22+ BlockchainStorageRead , BlockchainStorageWrite , TransactionRw , Transactional ,
23+ } ;
3824use chainstate_types:: {
3925 pos_randomness:: PoSRandomness , BlockIndex , BlockStatus , EpochStorageRead as _, GenBlockIndex ,
26+ TipStorageTag ,
4027} ;
4128use common:: {
4229 chain:: {
@@ -48,10 +35,27 @@ use common::{
4835 time_getter:: TimeGetter ,
4936} ;
5037use crypto:: { key:: PrivateKey , vrf:: VRFPrivateKey } ;
38+ use orders_accounting:: OrdersAccountingDB ;
39+ use pos_accounting:: { PoSAccountingDB , PoSAccountingData } ;
5140use randomness:: { CryptoRng , Rng } ;
5241use utils:: atomics:: SeqCstAtomicU64 ;
5342use utxo:: { Utxo , UtxosDB } ;
5443
44+ use crate :: {
45+ framework_builder:: TestFrameworkBuilderValue ,
46+ get_output_value,
47+ key_manager:: KeyManager ,
48+ pos_block_builder:: PoSBlockBuilder ,
49+ random_tx_maker:: StakingPoolsObserver ,
50+ staking_pools:: StakingPools ,
51+ utils:: {
52+ assert_block_index_opt_identical_to, assert_gen_block_index_identical_to,
53+ assert_gen_block_index_opt_identical_to, find_create_pool_tx_in_genesis,
54+ outputs_from_block, outputs_from_genesis, SighashInputCommitmentInfoProvider ,
55+ } ,
56+ BlockBuilder , TestChainstate , TestFrameworkBuilder , TestStore , TxVerificationStrategy ,
57+ } ;
58+
5559/// The `Chainstate` wrapper that simplifies operations and checks in the tests.
5660#[ must_use]
5761pub struct TestFramework {
@@ -587,13 +591,20 @@ impl TestFramework {
587591 pub fn make_sighash_input_commitments_for_transaction_inputs (
588592 & self ,
589593 inputs : & [ TxInput ] ,
594+ block_height : BlockHeight ,
590595 ) -> Vec < SighashInputCommitment < ' static > > {
591596 let storage_tx = self . storage . transaction_ro ( ) . unwrap ( ) ;
592597 let utxo_db = UtxosDB :: new ( & storage_tx) ;
598+ let pos_db = PoSAccountingDB :: < _ , TipStorageTag > :: new ( & storage_tx) ;
599+ let orders_db = OrdersAccountingDB :: new ( & storage_tx) ;
593600
594- sighash:: input_commitments:: make_sighash_input_commitments_for_transaction_inputs (
601+ sighash:: input_commitments:: make_sighash_input_commitments_for_transaction_inputs_at_height (
595602 inputs,
596603 & SighashInputCommitmentInfoProvider ( & utxo_db) ,
604+ & SighashInputCommitmentInfoProvider ( & pos_db) ,
605+ & SighashInputCommitmentInfoProvider ( & orders_db) ,
606+ self . chain_config ( ) ,
607+ block_height,
597608 )
598609 . unwrap ( )
599610 }
@@ -613,6 +624,38 @@ impl TestFramework {
613624 pub fn coin_amount_from_utxo ( & self , outpoint : & UtxoOutPoint ) -> Amount {
614625 get_output_value ( self . utxo ( outpoint) . output ( ) ) . unwrap ( ) . coin_amount ( ) . unwrap ( )
615626 }
627+
628+ pub fn pos_accounting_data_at_tip ( & self ) -> PoSAccountingData {
629+ self . storage . transaction_ro ( ) . unwrap ( ) . read_pos_accounting_data_tip ( ) . unwrap ( )
630+ }
631+
632+ pub fn find_kernel_outpoint_for_pool ( & self , pool_id : & PoolId ) -> Option < UtxoOutPoint > {
633+ let utxos = self . storage . transaction_ro ( ) . unwrap ( ) . read_utxo_set ( ) . unwrap ( ) ;
634+
635+ let mut outpoints_iter =
636+ utxos. into_iter ( ) . filter_map ( |( outpoint, utxo) | match utxo. output ( ) {
637+ TxOutput :: ProduceBlockFromStake ( _, used_pool_id)
638+ | TxOutput :: CreateStakePool ( used_pool_id, _) => {
639+ ( used_pool_id == pool_id) . then_some ( outpoint)
640+ }
641+
642+ TxOutput :: Transfer ( _, _)
643+ | TxOutput :: LockThenTransfer ( _, _, _)
644+ | TxOutput :: Burn ( _)
645+ | TxOutput :: CreateDelegationId ( _, _)
646+ | TxOutput :: DelegateStaking ( _, _)
647+ | TxOutput :: IssueFungibleToken ( _)
648+ | TxOutput :: IssueNft ( _, _, _)
649+ | TxOutput :: DataDeposit ( _)
650+ | TxOutput :: Htlc ( _, _)
651+ | TxOutput :: CreateOrder ( _) => None ,
652+ } ) ;
653+
654+ let result = outpoints_iter. next ( ) ;
655+ assert ! ( outpoints_iter. next( ) . is_none( ) ) ;
656+
657+ result
658+ }
616659}
617660
618661#[ rstest]
0 commit comments