@@ -715,3 +715,93 @@ impl_writeable_tlv_based_enum!(ChannelShutdownState,
715715	( 6 ,  NegotiatingClosingFee )  => { } , 
716716	( 8 ,  ShutdownComplete )  => { } , 
717717) ; 
718+ 
719+ #[ cfg( test) ]  
720+ mod  tests { 
721+ 	use  bitcoin:: { hashes:: Hash  as  _,  secp256k1:: PublicKey } ; 
722+ 	use  lightning_types:: features:: Features ; 
723+ 	use  types:: payment:: PaymentHash ; 
724+ 
725+ 	use  crate :: { 
726+ 		chain:: transaction:: OutPoint , 
727+ 		ln:: { 
728+ 			channel_state:: { 
729+ 				InboundHTLCDetails ,  InboundHTLCStateDetails ,  OutboundHTLCDetails , 
730+ 				OutboundHTLCStateDetails , 
731+ 			} , 
732+ 			types:: ChannelId , 
733+ 		} , 
734+ 		util:: { 
735+ 			config:: ChannelConfig , 
736+ 			ser:: { Readable ,  Writeable } , 
737+ 		} , 
738+ 	} ; 
739+ 
740+ 	use  super :: { ChannelCounterparty ,  ChannelDetails ,  ChannelShutdownState } ; 
741+ 
742+ 	#[ test]  
743+ 	fn  test_channel_details_serialization ( )  { 
744+ 		#[ allow( deprecated) ]  
745+ 		let  channel_details = ChannelDetails  { 
746+ 			channel_id :  ChannelId :: new_zero ( ) , 
747+ 			counterparty :  ChannelCounterparty  { 
748+ 				features :  Features :: empty ( ) , 
749+ 				node_id :  PublicKey :: from_slice ( & [ 2 ;  33 ] ) . unwrap ( ) , 
750+ 				unspendable_punishment_reserve :  1983 , 
751+ 				forwarding_info :  None , 
752+ 				outbound_htlc_minimum_msat :  None , 
753+ 				outbound_htlc_maximum_msat :  None , 
754+ 			} , 
755+ 			funding_txo :  Some ( OutPoint  { 
756+ 				txid :  bitcoin:: Txid :: from_slice ( & [ 0 ;  32 ] ) . unwrap ( ) , 
757+ 				index :  1 , 
758+ 			} ) , 
759+ 			channel_type :  None , 
760+ 			short_channel_id :  None , 
761+ 			outbound_scid_alias :  None , 
762+ 			inbound_scid_alias :  None , 
763+ 			channel_value_satoshis :  50_100 , 
764+ 			user_channel_id :  ( u64:: MAX  as  u128 )  + 1 ,  // Gets us into the high bytes 
765+ 			balance_msat :  23_100 , 
766+ 			outbound_capacity_msat :  24_300 , 
767+ 			next_outbound_htlc_limit_msat :  20_000 , 
768+ 			next_outbound_htlc_minimum_msat :  132 , 
769+ 			inbound_capacity_msat :  42 , 
770+ 			unspendable_punishment_reserve :  Some ( 8273 ) , 
771+ 			confirmations_required :  Some ( 5 ) , 
772+ 			confirmations :  Some ( 73 ) , 
773+ 			force_close_spend_delay :  Some ( 10 ) , 
774+ 			is_outbound :  true , 
775+ 			is_channel_ready :  false , 
776+ 			is_usable :  true , 
777+ 			is_public :  false , 
778+ 			inbound_htlc_minimum_msat :  Some ( 98 ) , 
779+ 			inbound_htlc_maximum_msat :  Some ( 983274 ) , 
780+ 			config :  Some ( ChannelConfig :: default ( ) ) , 
781+ 			feerate_sat_per_1000_weight :  Some ( 212 ) , 
782+ 			channel_shutdown_state :  Some ( ChannelShutdownState :: NotShuttingDown ) , 
783+ 			pending_inbound_htlcs :  vec ! [ InboundHTLCDetails  { 
784+ 				htlc_id:  12 , 
785+ 				amount_msat:  333 , 
786+ 				cltv_expiry:  127 , 
787+ 				payment_hash:  PaymentHash ( [ 3 ;  32 ] ) , 
788+ 				state:  Some ( InboundHTLCStateDetails :: AwaitingRemoteRevokeToAdd ) , 
789+ 				is_dust:  true , 
790+ 			} ] , 
791+ 			pending_outbound_htlcs :  vec ! [ OutboundHTLCDetails  { 
792+ 				htlc_id:  Some ( 81 ) , 
793+ 				amount_msat:  5000 , 
794+ 				cltv_expiry:  129 , 
795+ 				payment_hash:  PaymentHash ( [ 4 ;  32 ] ) , 
796+ 				state:  Some ( OutboundHTLCStateDetails :: AwaitingRemoteRevokeToAdd ) , 
797+ 				skimmed_fee_msat:  Some ( 42 ) , 
798+ 				is_dust:  false , 
799+ 			} ] , 
800+ 		} ; 
801+ 		let  mut  buffer = Vec :: new ( ) ; 
802+ 		channel_details. write ( & mut  buffer) . unwrap ( ) ; 
803+ 		let  deser_channel_details = ChannelDetails :: read ( & mut  buffer. as_slice ( ) ) . unwrap ( ) ; 
804+ 
805+ 		assert_eq ! ( deser_channel_details,  channel_details) ; 
806+ 	} 
807+ } 
0 commit comments