|
37 | 37 | ) |
38 | 38 | ) |
39 | 39 |
|
40 | | -// RandAltLeaf generates a random Asset that is a valid AltLeaf. |
41 | | -func RandAltLeaf(t testing.TB) *asset.Asset { |
42 | | - randWitness := []asset.Witness{ |
43 | | - {TxWitness: test.RandTxWitnesses(t)}, |
44 | | - } |
45 | | - randKey := asset.RandScriptKey(t) |
46 | | - randVersion := asset.ScriptVersion(test.RandInt[uint16]()) |
47 | | - randLeaf, err := asset.NewAltLeaf(randKey, randVersion, randWitness) |
48 | | - require.NoError(t, err) |
49 | | - |
50 | | - require.NoError(t, randLeaf.ValidateAltLeaf()) |
51 | | - |
52 | | - return randLeaf |
53 | | -} |
54 | | - |
55 | | -// RandAltLeaves generates a set of random number of random alt leaves. |
56 | | -func RandAltLeaves(t testing.TB) []AltLeafAsset { |
57 | | - // Limit the number of leaves to keep the test vectors small. |
58 | | - maxLeaves := int32(4) |
59 | | - numLeaves := test.RandInt31n(maxLeaves) |
60 | | - if numLeaves == 0 { |
61 | | - return nil |
62 | | - } |
63 | | - |
64 | | - altLeaves := make([]AltLeafAsset, 0, numLeaves) |
65 | | - for range numLeaves { |
66 | | - altLeaves = append(altLeaves, AltLeafAsset(RandAltLeaf(t))) |
67 | | - } |
68 | | - |
69 | | - return altLeaves |
70 | | -} |
71 | | - |
72 | 40 | func RandAssetForPacket(t testing.TB, assetType asset.Type, |
73 | 41 | desc keychain.KeyDescriptor) *asset.Asset { |
74 | 42 |
|
@@ -205,9 +173,12 @@ func RandPacket(t testing.TB, setVersion, altLeaves bool) *VPacket { |
205 | 173 | } |
206 | 174 |
|
207 | 175 | if altLeaves { |
208 | | - randVInput.AltLeaves = RandAltLeaves(t) |
209 | | - randVOutput1.AltLeaves = RandAltLeaves(t) |
210 | | - randVOutput2.AltLeaves = RandAltLeaves(t) |
| 176 | + inputLeaves := asset.RandAltLeaves(t, true) |
| 177 | + output1Leaves := asset.RandAltLeaves(t, true) |
| 178 | + output2Leaves := asset.RandAltLeaves(t, true) |
| 179 | + randVInput.AltLeaves = asset.ToAltLeaves(inputLeaves) |
| 180 | + randVOutput1.AltLeaves = asset.ToAltLeaves(output1Leaves) |
| 181 | + randVOutput2.AltLeaves = asset.ToAltLeaves(output2Leaves) |
211 | 182 | } |
212 | 183 |
|
213 | 184 | vPacket := &VPacket{ |
@@ -346,15 +317,9 @@ func NewTestFromVInput(t testing.TB, i *VInput) *TestVInput { |
346 | 317 |
|
347 | 318 | ti.AltLeaves = make([]*asset.TestAsset, 0, len(i.AltLeaves)) |
348 | 319 | for idx := range i.AltLeaves { |
349 | | - // We also need a type assertion on each leaf. |
350 | | - leaf, ok := i.AltLeaves[idx].(*asset.Asset) |
351 | | - if !ok { |
352 | | - t.Errorf("AltLeaf must be of type *asset.Asset") |
353 | | - } |
354 | | - |
| 320 | + leaf := asset.InnerAltLeaf(i.AltLeaves[idx]) |
355 | 321 | ti.AltLeaves = append( |
356 | | - ti.AltLeaves, |
357 | | - asset.NewTestFromAsset(t, leaf), |
| 322 | + ti.AltLeaves, asset.NewTestFromAsset(t, leaf), |
358 | 323 | ) |
359 | 324 | } |
360 | 325 | } |
@@ -415,7 +380,7 @@ func (ti *TestVInput) ToVInput(t testing.TB) *VInput { |
415 | 380 | } |
416 | 381 |
|
417 | 382 | if len(ti.AltLeaves) > 0 { |
418 | | - vi.AltLeaves = make([]AltLeafAsset, len(ti.AltLeaves)) |
| 383 | + vi.AltLeaves = make([]asset.AltLeafAsset, len(ti.AltLeaves)) |
419 | 384 | for idx, leaf := range ti.AltLeaves { |
420 | 385 | vi.AltLeaves[idx] = leaf.ToAsset(t) |
421 | 386 | } |
@@ -669,15 +634,9 @@ func NewTestFromVOutput(t testing.TB, v *VOutput, |
669 | 634 |
|
670 | 635 | vo.AltLeaves = make([]*asset.TestAsset, 0, len(vo.AltLeaves)) |
671 | 636 | for idx := range v.AltLeaves { |
672 | | - // We also need a type assertion on each leaf. |
673 | | - leaf, ok := v.AltLeaves[idx].(*asset.Asset) |
674 | | - if !ok { |
675 | | - t.Errorf("AltLeaf must be of type *asset.Asset") |
676 | | - } |
677 | | - |
| 637 | + leaf := asset.InnerAltLeaf(v.AltLeaves[idx]) |
678 | 638 | vo.AltLeaves = append( |
679 | | - vo.AltLeaves, |
680 | | - asset.NewTestFromAsset(t, leaf), |
| 639 | + vo.AltLeaves, asset.NewTestFromAsset(t, leaf), |
681 | 640 | ) |
682 | 641 | } |
683 | 642 | } |
@@ -800,7 +759,7 @@ func (to *TestVOutput) ToVOutput(t testing.TB) *VOutput { |
800 | 759 | } |
801 | 760 |
|
802 | 761 | if len(to.AltLeaves) > 0 { |
803 | | - v.AltLeaves = make([]AltLeafAsset, len(to.AltLeaves)) |
| 762 | + v.AltLeaves = make([]asset.AltLeafAsset, len(to.AltLeaves)) |
804 | 763 | for idx, leaf := range to.AltLeaves { |
805 | 764 | v.AltLeaves[idx] = leaf.ToAsset(t) |
806 | 765 | } |
|
0 commit comments