@@ -16,6 +16,7 @@ import (
1616 "github.com/lightninglabs/taproot-assets/fn"
1717 "github.com/lightninglabs/taproot-assets/internal/test"
1818 "github.com/lightninglabs/taproot-assets/mssmt"
19+ "github.com/lightningnetwork/lnd/tlv"
1920 "github.com/stretchr/testify/require"
2021)
2122
@@ -168,6 +169,51 @@ func TestEncodingDecoding(t *testing.T) {
168169 return pkt
169170 },
170171 decodeErr : ErrInvalidVPacketVersion ,
172+ }, {
173+ name : "random packet with colliding alt leaves" ,
174+ pkg : func (t * testing.T ) * VPacket {
175+ pkt := RandPacket (t , true , true )
176+ firstLeaf := RandAltLeaf (t )
177+ secondLeaf := RandAltLeaf (t )
178+
179+ firstLeafKey := asset .ToSerialized (
180+ firstLeaf .ScriptKey .PubKey ,
181+ )
182+ leafKeyCopy , err := firstLeafKey .ToPubKey ()
183+ require .NoError (t , err )
184+
185+ secondLeaf .ScriptKey = asset .NewScriptKey (leafKeyCopy )
186+ altLeaves := []AltLeafAsset {firstLeaf , secondLeaf }
187+
188+ pkt .Inputs [0 ].AltLeaves = asset .CopyAltLeaves (altLeaves )
189+ pkt .Outputs [0 ].AltLeaves = asset .CopyAltLeaves (
190+ altLeaves ,
191+ )
192+ pkt .Outputs [1 ].AltLeaves = asset .CopyAltLeaves (
193+ altLeaves ,
194+ )
195+
196+ return pkt
197+ },
198+ encodeErr : asset .ErrDuplicateScriptKeys ,
199+ }, {
200+ name : "random packet with excessive alt leaves" ,
201+ pkg : func (t * testing.T ) * VPacket {
202+ pkt := RandPacket (t , true , true )
203+
204+ numLeaves := 2000
205+ altLeaves := make ([]AltLeafAsset , 0 , numLeaves )
206+ for range numLeaves {
207+ altLeaves = append (altLeaves , RandAltLeaf (t ))
208+ }
209+
210+ pkt .Inputs [0 ].AltLeaves = altLeaves
211+ pkt .Outputs [0 ].AltLeaves = altLeaves
212+ pkt .Outputs [1 ].AltLeaves = altLeaves
213+
214+ return pkt
215+ },
216+ decodeErr : tlv .ErrRecordTooLarge ,
171217 }}
172218
173219 for _ , testCase := range testCases {
0 commit comments