@@ -6740,6 +6740,71 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
67406740 }
67416741}
67426742
6743+ #[ cfg( test) ]
6744+ pub ( super ) fn dummy_monitor < S : EcdsaChannelSigner + ' static > (
6745+ channel_id : ChannelId , wrap_signer : impl FnOnce ( crate :: sign:: InMemorySigner ) -> S ,
6746+ ) -> ChannelMonitor < S > {
6747+ use crate :: ln:: chan_utils:: { ChannelPublicKeys , CounterpartyChannelTransactionParameters } ;
6748+ use crate :: sign:: { ChannelSigner , InMemorySigner } ;
6749+ use bitcoin:: network:: Network ;
6750+
6751+ let secp_ctx = Secp256k1 :: new ( ) ;
6752+ let dummy_key =
6753+ PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
6754+ let keys = InMemorySigner :: new (
6755+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6756+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6757+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6758+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6759+ true ,
6760+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6761+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6762+ [ 41 ; 32 ] ,
6763+ [ 0 ; 32 ] ,
6764+ [ 0 ; 32 ] ,
6765+ ) ;
6766+ let counterparty_pubkeys = ChannelPublicKeys {
6767+ funding_pubkey : dummy_key,
6768+ revocation_basepoint : RevocationBasepoint :: from ( dummy_key) ,
6769+ payment_point : dummy_key,
6770+ delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( dummy_key) ,
6771+ htlc_basepoint : HtlcBasepoint :: from ( dummy_key) ,
6772+ } ;
6773+ let funding_outpoint =
6774+ crate :: chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
6775+ let channel_parameters = ChannelTransactionParameters {
6776+ holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
6777+ holder_selected_contest_delay : 66 ,
6778+ is_outbound_from_holder : true ,
6779+ counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
6780+ pubkeys : counterparty_pubkeys,
6781+ selected_contest_delay : 67 ,
6782+ } ) ,
6783+ funding_outpoint : Some ( funding_outpoint) ,
6784+ splice_parent_funding_txid : None ,
6785+ channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
6786+ channel_value_satoshis : 0 ,
6787+ } ;
6788+ let shutdown_script = crate :: ln:: script:: ShutdownScript :: new_p2wpkh_from_pubkey ( dummy_key) ;
6789+ let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
6790+ let signer = wrap_signer ( keys) ;
6791+ ChannelMonitor :: new (
6792+ secp_ctx,
6793+ signer,
6794+ Some ( shutdown_script. into_inner ( ) ) ,
6795+ 0 ,
6796+ & ScriptBuf :: new ( ) ,
6797+ & channel_parameters,
6798+ true ,
6799+ 0 ,
6800+ HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
6801+ best_block,
6802+ dummy_key,
6803+ channel_id,
6804+ false ,
6805+ )
6806+ }
6807+
67436808#[ cfg( test) ]
67446809mod tests {
67456810 use bitcoin:: amount:: Amount ;
@@ -6769,23 +6834,16 @@ mod tests {
67696834 weight_revoked_received_htlc, WEIGHT_REVOKED_OUTPUT ,
67706835 } ;
67716836 use crate :: chain:: transaction:: OutPoint ;
6772- use crate :: chain:: { BestBlock , Confirm } ;
6837+ use crate :: chain:: Confirm ;
67736838 use crate :: io;
6774- use crate :: ln:: chan_utils:: {
6775- self , ChannelPublicKeys , ChannelTransactionParameters ,
6776- CounterpartyChannelTransactionParameters , HTLCOutputInCommitment ,
6777- HolderCommitmentTransaction ,
6778- } ;
6839+ use crate :: ln:: chan_utils:: { self , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
67796840 use crate :: ln:: channel_keys:: {
6780- DelayedPaymentBasepoint , DelayedPaymentKey , HtlcBasepoint , RevocationBasepoint ,
6781- RevocationKey ,
6841+ DelayedPaymentBasepoint , DelayedPaymentKey , RevocationBasepoint , RevocationKey ,
67826842 } ;
67836843 use crate :: ln:: channelmanager:: { HTLCSource , PaymentId } ;
67846844 use crate :: ln:: functional_test_utils:: * ;
67856845 use crate :: ln:: outbound_payment:: RecipientOnionFields ;
6786- use crate :: ln:: script:: ShutdownScript ;
67876846 use crate :: ln:: types:: ChannelId ;
6788- use crate :: sign:: { ChannelSigner , InMemorySigner } ;
67896847 use crate :: sync:: Arc ;
67906848 use crate :: types:: features:: ChannelTypeFeatures ;
67916849 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
@@ -6955,51 +7013,11 @@ mod tests {
69557013 }
69567014 }
69577015
6958- let keys = InMemorySigner :: new (
6959- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6960- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6961- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6962- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6963- true ,
6964- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6965- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6966- [ 41 ; 32 ] ,
6967- [ 0 ; 32 ] ,
6968- [ 0 ; 32 ] ,
6969- ) ;
6970-
6971- let counterparty_pubkeys = ChannelPublicKeys {
6972- funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
6973- revocation_basepoint : RevocationBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ) ,
6974- payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
6975- delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ) ,
6976- htlc_basepoint : HtlcBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) ) )
6977- } ;
69787016 let funding_outpoint = OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
69797017 let channel_id = ChannelId :: v1_from_funding_outpoint ( funding_outpoint) ;
6980- let channel_parameters = ChannelTransactionParameters {
6981- holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
6982- holder_selected_contest_delay : 66 ,
6983- is_outbound_from_holder : true ,
6984- counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
6985- pubkeys : counterparty_pubkeys,
6986- selected_contest_delay : 67 ,
6987- } ) ,
6988- funding_outpoint : Some ( funding_outpoint) ,
6989- splice_parent_funding_txid : None ,
6990- channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
6991- channel_value_satoshis : 0 ,
6992- } ;
69937018 // Prune with one old state and a holder commitment tx holding a few overlaps with the
69947019 // old state.
6995- let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
6996- let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
6997- let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
6998- let monitor = ChannelMonitor :: new (
6999- Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
7000- & channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
7001- best_block, dummy_key, channel_id, false ,
7002- ) ;
7020+ let monitor = super :: dummy_monitor ( channel_id, |keys| keys) ;
70037021
70047022 let nondust_htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
70057023 let dummy_commitment_tx = HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, nondust_htlcs) ;
@@ -7218,49 +7236,9 @@ mod tests {
72187236
72197237 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
72207238
7221- let keys = InMemorySigner :: new (
7222- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7223- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7224- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7225- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7226- true ,
7227- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7228- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7229- [ 41 ; 32 ] ,
7230- [ 0 ; 32 ] ,
7231- [ 0 ; 32 ] ,
7232- ) ;
7233-
7234- let counterparty_pubkeys = ChannelPublicKeys {
7235- funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
7236- revocation_basepoint : RevocationBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ) ,
7237- payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
7238- delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ) ,
7239- htlc_basepoint : HtlcBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) ) ) ,
7240- } ;
72417239 let funding_outpoint = OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
72427240 let channel_id = ChannelId :: v1_from_funding_outpoint ( funding_outpoint) ;
7243- let channel_parameters = ChannelTransactionParameters {
7244- holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
7245- holder_selected_contest_delay : 66 ,
7246- is_outbound_from_holder : true ,
7247- counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
7248- pubkeys : counterparty_pubkeys,
7249- selected_contest_delay : 67 ,
7250- } ) ,
7251- funding_outpoint : Some ( funding_outpoint) ,
7252- splice_parent_funding_txid : None ,
7253- channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
7254- channel_value_satoshis : 0 ,
7255- } ;
7256- let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
7257- let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
7258- let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
7259- let monitor = ChannelMonitor :: new (
7260- Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
7261- & channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
7262- best_block, dummy_key, channel_id, false ,
7263- ) ;
7241+ let monitor = super :: dummy_monitor ( channel_id, |keys| keys) ;
72647242
72657243 let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
72667244 let payment_hash = PaymentHash ( [ 1 ; 32 ] ) ;
0 commit comments