Skip to content

Commit 4e3e4c8

Browse files
committed
tappsbt: update BIP test vectors
1 parent ab2c272 commit 4e3e4c8

File tree

2 files changed

+447
-107
lines changed

2 files changed

+447
-107
lines changed

tappsbt/mock.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,28 @@ func NewTestFromVInput(t testing.TB, i *VInput) *TestVInput {
337337
ti.Proof = proof.NewTestFromProof(t, i.Proof)
338338
}
339339

340+
if len(i.AltLeaves) > 0 {
341+
// Assert that the concrete type of AltLeaf is supported.
342+
require.IsTypef(
343+
t, &asset.Asset{}, i.AltLeaves[0],
344+
"AltLeaves must be of type *asset.Asset",
345+
)
346+
347+
ti.AltLeaves = make([]*asset.TestAsset, 0, len(i.AltLeaves))
348+
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+
355+
ti.AltLeaves = append(
356+
ti.AltLeaves,
357+
asset.NewTestFromAsset(t, leaf),
358+
)
359+
}
360+
}
361+
340362
return ti
341363
}
342364

@@ -349,6 +371,7 @@ type TestVInput struct {
349371
Anchor *TestAnchor `json:"anchor"`
350372
Asset *asset.TestAsset `json:"asset"`
351373
Proof *proof.TestProof `json:"proof"`
374+
AltLeaves []*asset.TestAsset `json:"alt_leaves"`
352375
}
353376

354377
func (ti *TestVInput) ToVInput(t testing.TB) *VInput {
@@ -391,6 +414,13 @@ func (ti *TestVInput) ToVInput(t testing.TB) *VInput {
391414
vi.Proof = ti.Proof.ToProof(t)
392415
}
393416

417+
if len(ti.AltLeaves) > 0 {
418+
vi.AltLeaves = make([]AltLeafAsset, len(ti.AltLeaves))
419+
for idx, leaf := range ti.AltLeaves {
420+
vi.AltLeaves[idx] = leaf.ToAsset(t)
421+
}
422+
}
423+
394424
return vi
395425
}
396426

@@ -629,6 +659,28 @@ func NewTestFromVOutput(t testing.TB, v *VOutput,
629659
vo.SplitAsset = asset.NewTestFromAsset(t, v.SplitAsset)
630660
}
631661

662+
if len(v.AltLeaves) > 0 {
663+
// Assert that the concrete type of AltLeaf is supported.
664+
switch v.AltLeaves[0].(type) {
665+
case *asset.Asset:
666+
default:
667+
t.Errorf("AltLeaves must be of type *asset.Asset")
668+
}
669+
670+
vo.AltLeaves = make([]*asset.TestAsset, 0, len(vo.AltLeaves))
671+
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+
678+
vo.AltLeaves = append(
679+
vo.AltLeaves,
680+
asset.NewTestFromAsset(t, leaf),
681+
)
682+
}
683+
}
632684
return vo
633685
}
634686

@@ -654,6 +706,7 @@ type TestVOutput struct {
654706
ProofSuffix *proof.TestProof `json:"proof_suffix"`
655707
RelativeLockTime uint64 `json:"relative_lock_time"`
656708
LockTime uint64 `json:"lock_time"`
709+
AltLeaves []*asset.TestAsset `json:"alt_leaves"`
657710
}
658711

659712
func (to *TestVOutput) ToVOutput(t testing.TB) *VOutput {
@@ -746,5 +799,12 @@ func (to *TestVOutput) ToVOutput(t testing.TB) *VOutput {
746799
)
747800
}
748801

802+
if len(to.AltLeaves) > 0 {
803+
v.AltLeaves = make([]AltLeafAsset, len(to.AltLeaves))
804+
for idx, leaf := range to.AltLeaves {
805+
v.AltLeaves[idx] = leaf.ToAsset(t)
806+
}
807+
}
808+
749809
return v
750810
}

0 commit comments

Comments
 (0)