Skip to content

Commit 2d3d1e1

Browse files
committed
multi: update test handling of tapscript preimages
1 parent f6dd14a commit 2d3d1e1

File tree

8 files changed

+48
-40
lines changed

8 files changed

+48
-40
lines changed

address/address_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ func randAddress(t *testing.T, net *ChainParams, v Version, groupPubKey,
4848
amount = test.RandInt[uint64]()
4949
}
5050

51-
var tapscriptSibling *commitment.TapscriptPreimage
51+
var (
52+
tapscriptSibling *commitment.TapscriptPreimage
53+
err error
54+
)
5255
if sibling {
53-
tapscriptSibling = commitment.NewPreimageFromLeaf(
56+
tapscriptSibling, err = commitment.NewPreimageFromLeaf(
5457
txscript.NewBaseTapLeaf([]byte("not a valid script")),
5558
)
59+
require.NoError(t, err)
5660
}
5761

5862
scriptKey := *pubKey

address/mock.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ func RandAddr(t testing.TB, params *ChainParams,
7070
groupPubKey = &groupInfo.GroupPubKey
7171
groupWitness = groupInfo.Witness
7272

73-
tapscriptSibling = commitment.NewPreimageFromLeaf(
73+
var err error
74+
tapscriptSibling, err = commitment.NewPreimageFromLeaf(
7475
txscript.NewBaseTapLeaf([]byte("not a valid script")),
7576
)
77+
require.NoError(t, err)
7678
}
7779

7880
tapAddr, err := New(

itest/psbt_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,9 @@ func testPsbtInteractiveTapscriptSibling(t *harnessTest) {
744744
preImage := []byte("hash locks are cool")
745745
siblingLeaf := test.ScriptHashLock(t.t, preImage)
746746

747-
preimage := commitment.NewPreimageFromLeaf(siblingLeaf)
748-
vPkt.Outputs[0].AnchorOutputTapscriptSibling = preimage
747+
siblingPreimage, err := commitment.NewPreimageFromLeaf(siblingLeaf)
748+
require.NoError(t.t, err)
749+
vPkt.Outputs[0].AnchorOutputTapscriptSibling = siblingPreimage
749750

750751
// Next, we'll attempt to complete a transfer with PSBTs from alice to
751752
// bob, using the partial amount.

itest/round_trip_send_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func testRoundTripSend(t *harnessTest) {
5454

5555
hashLockPreimage := []byte("hash locks are cool")
5656
scriptLeaf := test.ScriptHashLock(t.t, hashLockPreimage)
57-
sibling := commitment.NewPreimageFromLeaf(scriptLeaf)
57+
sibling, err := commitment.NewPreimageFromLeaf(scriptLeaf)
58+
require.NoError(t.t, err)
5859
siblingBytes, _, err := commitment.MaybeEncodeTapscriptPreimage(sibling)
5960
require.NoError(t.t, err)
6061

proof/mock.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ func RandProof(t testing.TB, genesis asset.Genesis,
7676

7777
leaf1 := txscript.NewBaseTapLeaf([]byte{1})
7878
leaf2 := txscript.NewBaseTapLeaf([]byte{2})
79-
testLeafPreimage := commitment.NewPreimageFromLeaf(leaf1)
80-
testLeafPreimage2 := commitment.NewPreimageFromLeaf(leaf2)
79+
testLeafPreimage, err := commitment.NewPreimageFromLeaf(leaf1)
80+
require.NoError(t, err)
81+
testLeafPreimage2, err := commitment.NewPreimageFromLeaf(leaf2)
82+
require.NoError(t, err)
8183
testBranchPreimage := commitment.NewPreimageFromBranch(
8284
txscript.NewTapBranch(leaf1, leaf2),
8385
)
@@ -112,7 +114,7 @@ func RandProof(t testing.TB, genesis asset.Genesis,
112114
InternalKey: test.RandPubKey(t),
113115
CommitmentProof: nil,
114116
TapscriptProof: &TapscriptProof{
115-
TapPreimage1: testBranchPreimage,
117+
TapPreimage1: &testBranchPreimage,
116118
TapPreimage2: testLeafPreimage2,
117119
Bip86: true,
118120
},

proof/proof_test.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,12 @@ func TestGenesisProofVerification(t *testing.T) {
371371
scriptInternalKey := test.RandPrivKey(t).PubKey()
372372
leaf1 := test.ScriptHashLock(t, []byte("foobar"))
373373
leaf2 := test.ScriptSchnorrSig(t, scriptInternalKey)
374+
testLeafPreimage, err := commitment.NewPreimageFromLeaf(leaf1)
375+
require.NoError(t, err)
374376

375377
// The order doesn't matter here as they are sorted before hashing.
376378
branch := txscript.NewTapBranch(leaf1, leaf2)
379+
testBranchPreimage := commitment.NewPreimageFromBranch(branch)
377380
amount := uint64(5000)
378381

379382
testCases := []struct {
@@ -402,20 +405,16 @@ func TestGenesisProofVerification(t *testing.T) {
402405
assetVersion: asset.V1,
403406
},
404407
{
405-
name: "collectible with leaf preimage",
406-
assetType: asset.Collectible,
407-
tapscriptPreimage: commitment.NewPreimageFromLeaf(
408-
leaf1,
409-
),
410-
noMetaHash: true,
408+
name: "collectible with leaf preimage",
409+
assetType: asset.Collectible,
410+
tapscriptPreimage: testLeafPreimage,
411+
noMetaHash: true,
411412
},
412413
{
413-
name: "collectible with branch preimage",
414-
assetType: asset.Collectible,
415-
tapscriptPreimage: commitment.NewPreimageFromBranch(
416-
branch,
417-
),
418-
noMetaHash: true,
414+
name: "collectible with branch preimage",
415+
assetType: asset.Collectible,
416+
tapscriptPreimage: &testBranchPreimage,
417+
noMetaHash: true,
419418
},
420419
{
421420
name: "normal genesis",
@@ -431,22 +430,18 @@ func TestGenesisProofVerification(t *testing.T) {
431430
assetVersion: asset.V1,
432431
},
433432
{
434-
name: "normal with leaf preimage",
435-
assetType: asset.Normal,
436-
amount: &amount,
437-
tapscriptPreimage: commitment.NewPreimageFromLeaf(
438-
leaf1,
439-
),
440-
noMetaHash: true,
433+
name: "normal with leaf preimage",
434+
assetType: asset.Normal,
435+
amount: &amount,
436+
tapscriptPreimage: testLeafPreimage,
437+
noMetaHash: true,
441438
},
442439
{
443-
name: "normal with branch preimage",
444-
assetType: asset.Normal,
445-
amount: &amount,
446-
tapscriptPreimage: commitment.NewPreimageFromBranch(
447-
branch,
448-
),
449-
noMetaHash: true,
440+
name: "normal with branch preimage",
441+
assetType: asset.Normal,
442+
amount: &amount,
443+
tapscriptPreimage: &testBranchPreimage,
444+
noMetaHash: true,
450445
},
451446
{
452447
name: "normal asset with a meta reveal",

tappsbt/mock.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ func RandPacket(t testing.TB) *VPacket {
8080
LeafVersion: txscript.BaseLeafVersion,
8181
Script: []byte("not a valid script"),
8282
}
83-
testPreimage1 := commitment.NewPreimageFromLeaf(leaf1)
83+
testPreimage1, err := commitment.NewPreimageFromLeaf(leaf1)
84+
require.NoError(t, err)
8485
testPreimage2 := commitment.NewPreimageFromBranch(
8586
txscript.NewTapBranch(leaf1, leaf1),
8687
)
@@ -155,7 +156,7 @@ func RandPacket(t testing.TB) *VPacket {
155156
AnchorOutputTaprootBip32Derivation: trBip32Derivations,
156157
Asset: testOutputAsset,
157158
ScriptKey: testOutputAsset.ScriptKey,
158-
AnchorOutputTapscriptSibling: testPreimage2,
159+
AnchorOutputTapscriptSibling: &testPreimage2,
159160
}},
160161
ChainParams: testParams,
161162
}

tapsend/send_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,18 +1070,19 @@ var createOutputCommitmentsTestCases = []testCase{{
10701070
)
10711071
tpl := pkt.Outputs[1]
10721072

1073-
testPreimage := commitment.NewPreimageFromLeaf(
1073+
testPreimage, err := commitment.NewPreimageFromLeaf(
10741074
txscript.TapLeaf{
10751075
LeafVersion: txscript.BaseLeafVersion,
10761076
Script: []byte("not a valid script"),
10771077
},
10781078
)
1079+
require.NoError(t, err)
10791080
pkt.Outputs = append(pkt.Outputs, &tappsbt.VOutput{
10801081
AnchorOutputIndex: tpl.AnchorOutputIndex,
10811082
AnchorOutputTapscriptSibling: testPreimage,
10821083
})
10831084

1084-
_, err := tapsend.CreateOutputCommitments(nil, pkt, nil)
1085+
_, err = tapsend.CreateOutputCommitments(nil, pkt, nil)
10851086
return err
10861087
},
10871088
err: tapsend.ErrInvalidAnchorInfo,
@@ -2171,9 +2172,10 @@ func TestPayToAddrScript(t *testing.T) {
21712172
)
21722173

21732174
// And now the same with an address that has a tapscript sibling.
2174-
sibling := commitment.NewPreimageFromLeaf(txscript.NewBaseTapLeaf(
2175+
sibling, err := commitment.NewPreimageFromLeaf(txscript.NewBaseTapLeaf(
21752176
[]byte("not a valid script"),
21762177
))
2178+
require.NoError(t, err)
21772179
addr2, err := address.New(
21782180
address.V0, gen, nil, nil, *recipientScriptKey.PubKey,
21792181
*internalKey, sendAmt, sibling, &address.RegressionNetTap,

0 commit comments

Comments
 (0)