@@ -909,6 +909,91 @@ func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
909909 }
910910}
911911
912+ // A compile time check to ensure DynCommit implements the lnwire.TestMessage
913+ // interface.
914+ var _ TestMessage = (* DynCommit )(nil )
915+
916+ // RandTestMessage populates the message with random data suitable for testing.
917+ // It uses the rapid testing framework to generate random values.
918+ //
919+ // This is part of the TestMessage interface.
920+ func (dc * DynCommit ) RandTestMessage (t * rapid.T ) Message {
921+ chanID := RandChannelID (t )
922+
923+ da := & DynAck {
924+ ChanID : chanID ,
925+ }
926+
927+ dp := & DynPropose {
928+ ChanID : chanID ,
929+ }
930+
931+ // Randomly decide which optional fields to include
932+ includeDustLimit := rapid .Bool ().Draw (t , "includeDustLimit" )
933+ includeMaxValueInFlight := rapid .Bool ().Draw (
934+ t , "includeMaxValueInFlight" ,
935+ )
936+ includeChannelReserve := rapid .Bool ().Draw (t , "includeChannelReserve" )
937+ includeCsvDelay := rapid .Bool ().Draw (t , "includeCsvDelay" )
938+ includeMaxAcceptedHTLCs := rapid .Bool ().Draw (
939+ t , "includeMaxAcceptedHTLCs" ,
940+ )
941+ includeChannelType := rapid .Bool ().Draw (t , "includeChannelType" )
942+
943+ // Generate random values for each included field
944+ if includeDustLimit {
945+ var rec tlv.RecordT [tlv.TlvType0 , btcutil.Amount ]
946+ val := btcutil .Amount (rapid .Uint32 ().Draw (t , "dustLimit" ))
947+ rec .Val = val
948+ dp .DustLimit = tlv .SomeRecordT (rec )
949+ }
950+
951+ if includeMaxValueInFlight {
952+ var rec tlv.RecordT [tlv.TlvType2 , MilliSatoshi ]
953+ val := MilliSatoshi (rapid .Uint64 ().Draw (t , "maxValueInFlight" ))
954+ rec .Val = val
955+ dp .MaxValueInFlight = tlv .SomeRecordT (rec )
956+ }
957+
958+ if includeChannelReserve {
959+ var rec tlv.RecordT [tlv.TlvType6 , btcutil.Amount ]
960+ val := btcutil .Amount (rapid .Uint32 ().Draw (t , "channelReserve" ))
961+ rec .Val = val
962+ dp .ChannelReserve = tlv .SomeRecordT (rec )
963+ }
964+
965+ if includeCsvDelay {
966+ csvDelay := dp .CsvDelay .Zero ()
967+ val := rapid .Uint16 ().Draw (t , "csvDelay" )
968+ csvDelay .Val = val
969+ dp .CsvDelay = tlv .SomeRecordT (csvDelay )
970+ }
971+
972+ if includeMaxAcceptedHTLCs {
973+ maxHtlcs := dp .MaxAcceptedHTLCs .Zero ()
974+ maxHtlcs .Val = rapid .Uint16 ().Draw (t , "maxAcceptedHTLCs" )
975+ dp .MaxAcceptedHTLCs = tlv .SomeRecordT (maxHtlcs )
976+ }
977+
978+ if includeChannelType {
979+ chanType := dp .ChannelType .Zero ()
980+ chanType .Val = * RandChannelType (t )
981+ dp .ChannelType = tlv .SomeRecordT (chanType )
982+ }
983+
984+ var extraData ExtraOpaqueData
985+ randData := RandExtraOpaqueData (t , nil )
986+ if len (randData ) > 0 {
987+ extraData = randData
988+ }
989+
990+ return & DynCommit {
991+ DynPropose : * dp ,
992+ DynAck : * da ,
993+ ExtraData : extraData ,
994+ }
995+ }
996+
912997// A compile time check to ensure FundingCreated implements the TestMessage
913998// interface.
914999var _ TestMessage = (* FundingCreated )(nil )
0 commit comments