@@ -6749,6 +6749,71 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
67496749 }
67506750}
67516751
6752+ #[ cfg( test) ]
6753+ pub ( super ) fn dummy_monitor < S : EcdsaChannelSigner + ' static > (
6754+ channel_id : ChannelId , wrap_signer : impl FnOnce ( crate :: sign:: InMemorySigner ) -> S ,
6755+ ) -> ChannelMonitor < S > {
6756+ use crate :: ln:: chan_utils:: { ChannelPublicKeys , CounterpartyChannelTransactionParameters } ;
6757+ use crate :: sign:: { ChannelSigner , InMemorySigner } ;
6758+ use bitcoin:: network:: Network ;
6759+
6760+ let secp_ctx = Secp256k1 :: new ( ) ;
6761+ let dummy_key =
6762+ PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
6763+ let keys = InMemorySigner :: new (
6764+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6765+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6766+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6767+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6768+ true ,
6769+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6770+ SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6771+ [ 41 ; 32 ] ,
6772+ [ 0 ; 32 ] ,
6773+ [ 0 ; 32 ] ,
6774+ ) ;
6775+ let counterparty_pubkeys = ChannelPublicKeys {
6776+ funding_pubkey : dummy_key,
6777+ revocation_basepoint : RevocationBasepoint :: from ( dummy_key) ,
6778+ payment_point : dummy_key,
6779+ delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( dummy_key) ,
6780+ htlc_basepoint : HtlcBasepoint :: from ( dummy_key) ,
6781+ } ;
6782+ let funding_outpoint =
6783+ crate :: chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
6784+ let channel_parameters = ChannelTransactionParameters {
6785+ holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
6786+ holder_selected_contest_delay : 66 ,
6787+ is_outbound_from_holder : true ,
6788+ counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
6789+ pubkeys : counterparty_pubkeys,
6790+ selected_contest_delay : 67 ,
6791+ } ) ,
6792+ funding_outpoint : Some ( funding_outpoint) ,
6793+ splice_parent_funding_txid : None ,
6794+ channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
6795+ channel_value_satoshis : 0 ,
6796+ } ;
6797+ let shutdown_script = crate :: ln:: script:: ShutdownScript :: new_p2wpkh_from_pubkey ( dummy_key) ;
6798+ let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
6799+ let signer = wrap_signer ( keys) ;
6800+ ChannelMonitor :: new (
6801+ secp_ctx,
6802+ signer,
6803+ Some ( shutdown_script. into_inner ( ) ) ,
6804+ 0 ,
6805+ & ScriptBuf :: new ( ) ,
6806+ & channel_parameters,
6807+ true ,
6808+ 0 ,
6809+ HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
6810+ best_block,
6811+ dummy_key,
6812+ channel_id,
6813+ false ,
6814+ )
6815+ }
6816+
67526817#[ cfg( test) ]
67536818mod tests {
67546819 use bitcoin:: amount:: Amount ;
@@ -6778,23 +6843,16 @@ mod tests {
67786843 weight_revoked_received_htlc, WEIGHT_REVOKED_OUTPUT ,
67796844 } ;
67806845 use crate :: chain:: transaction:: OutPoint ;
6781- use crate :: chain:: { BestBlock , Confirm } ;
6846+ use crate :: chain:: Confirm ;
67826847 use crate :: io;
6783- use crate :: ln:: chan_utils:: {
6784- self , ChannelPublicKeys , ChannelTransactionParameters ,
6785- CounterpartyChannelTransactionParameters , HTLCOutputInCommitment ,
6786- HolderCommitmentTransaction ,
6787- } ;
6848+ use crate :: ln:: chan_utils:: { self , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
67886849 use crate :: ln:: channel_keys:: {
6789- DelayedPaymentBasepoint , DelayedPaymentKey , HtlcBasepoint , RevocationBasepoint ,
6790- RevocationKey ,
6850+ DelayedPaymentBasepoint , DelayedPaymentKey , RevocationBasepoint , RevocationKey ,
67916851 } ;
67926852 use crate :: ln:: channelmanager:: { HTLCSource , PaymentId } ;
67936853 use crate :: ln:: functional_test_utils:: * ;
67946854 use crate :: ln:: outbound_payment:: RecipientOnionFields ;
6795- use crate :: ln:: script:: ShutdownScript ;
67966855 use crate :: ln:: types:: ChannelId ;
6797- use crate :: sign:: { ChannelSigner , InMemorySigner } ;
67986856 use crate :: sync:: Arc ;
67996857 use crate :: types:: features:: ChannelTypeFeatures ;
68006858 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
@@ -6964,51 +7022,11 @@ mod tests {
69647022 }
69657023 }
69667024
6967- let keys = InMemorySigner :: new (
6968- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6969- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6970- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6971- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6972- true ,
6973- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6974- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
6975- [ 41 ; 32 ] ,
6976- [ 0 ; 32 ] ,
6977- [ 0 ; 32 ] ,
6978- ) ;
6979-
6980- let counterparty_pubkeys = ChannelPublicKeys {
6981- funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
6982- revocation_basepoint : RevocationBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ) ,
6983- payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
6984- delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ) ,
6985- htlc_basepoint : HtlcBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) ) )
6986- } ;
69877025 let funding_outpoint = OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
69887026 let channel_id = ChannelId :: v1_from_funding_outpoint ( funding_outpoint) ;
6989- let channel_parameters = ChannelTransactionParameters {
6990- holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
6991- holder_selected_contest_delay : 66 ,
6992- is_outbound_from_holder : true ,
6993- counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
6994- pubkeys : counterparty_pubkeys,
6995- selected_contest_delay : 67 ,
6996- } ) ,
6997- funding_outpoint : Some ( funding_outpoint) ,
6998- splice_parent_funding_txid : None ,
6999- channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
7000- channel_value_satoshis : 0 ,
7001- } ;
70027027 // Prune with one old state and a holder commitment tx holding a few overlaps with the
70037028 // old state.
7004- let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
7005- let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
7006- let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
7007- let monitor = ChannelMonitor :: new (
7008- Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
7009- & channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
7010- best_block, dummy_key, channel_id, false ,
7011- ) ;
7029+ let monitor = super :: dummy_monitor ( channel_id, |keys| keys) ;
70127030
70137031 let nondust_htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
70147032 let dummy_commitment_tx = HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, nondust_htlcs) ;
@@ -7227,49 +7245,9 @@ mod tests {
72277245
72287246 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
72297247
7230- let keys = InMemorySigner :: new (
7231- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7232- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7233- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7234- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7235- true ,
7236- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7237- SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ,
7238- [ 41 ; 32 ] ,
7239- [ 0 ; 32 ] ,
7240- [ 0 ; 32 ] ,
7241- ) ;
7242-
7243- let counterparty_pubkeys = ChannelPublicKeys {
7244- funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
7245- revocation_basepoint : RevocationBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ) ,
7246- payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
7247- delayed_payment_basepoint : DelayedPaymentBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ) ,
7248- htlc_basepoint : HtlcBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) ) ) ,
7249- } ;
72507248 let funding_outpoint = OutPoint { txid : Txid :: all_zeros ( ) , index : u16:: MAX } ;
72517249 let channel_id = ChannelId :: v1_from_funding_outpoint ( funding_outpoint) ;
7252- let channel_parameters = ChannelTransactionParameters {
7253- holder_pubkeys : keys. pubkeys ( & secp_ctx) ,
7254- holder_selected_contest_delay : 66 ,
7255- is_outbound_from_holder : true ,
7256- counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
7257- pubkeys : counterparty_pubkeys,
7258- selected_contest_delay : 67 ,
7259- } ) ,
7260- funding_outpoint : Some ( funding_outpoint) ,
7261- splice_parent_funding_txid : None ,
7262- channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
7263- channel_value_satoshis : 0 ,
7264- } ;
7265- let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
7266- let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
7267- let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
7268- let monitor = ChannelMonitor :: new (
7269- Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
7270- & channel_parameters, true , 0 , HolderCommitmentTransaction :: dummy ( 0 , funding_outpoint, Vec :: new ( ) ) ,
7271- best_block, dummy_key, channel_id, false ,
7272- ) ;
7250+ let monitor = super :: dummy_monitor ( channel_id, |keys| keys) ;
72737251
72747252 let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
72757253 let payment_hash = PaymentHash ( [ 1 ; 32 ] ) ;
0 commit comments