27
27
// TestCreateProofSuffix tests the creation of suffix proofs for a given anchor
28
28
// transaction.
29
29
func TestCreateProofSuffix (t * testing.T ) {
30
+ testCases := []struct {
31
+ name string
32
+ stxoProof bool
33
+ expectedErr string
34
+ }{
35
+ {
36
+ name : "Correct inclusion and exclusion proofs" ,
37
+ stxoProof : true ,
38
+ },
39
+ {
40
+ name : "No stxo proof" ,
41
+ stxoProof : false ,
42
+ expectedErr : "error verifying STXO proof: missing " +
43
+ "asset proof" ,
44
+ },
45
+ }
46
+ for _ , tc := range testCases {
47
+ tc := tc
48
+
49
+ t .Run (tc .name , func (tt * testing.T ) {
50
+ createProofSuffix (t , tc .stxoProof , tc .expectedErr )
51
+ })
52
+ }
53
+ }
54
+
55
+ func createProofSuffix (t * testing.T , stxoProof bool , expectedErr string ) {
30
56
testAssets := []* asset.Asset {
31
57
asset .RandAsset (t , asset .RandAssetType (t )),
32
58
asset .RandAsset (t , asset .RandAssetType (t )),
@@ -83,7 +109,10 @@ func TestCreateProofSuffix(t *testing.T) {
83
109
}
84
110
outputCommitments := make (map [uint32 ]* commitment.TapCommitment )
85
111
86
- addOutputCommitment (t , anchorTx , outputCommitments , testPackets ... )
112
+ addOutputCommitment (
113
+ t , anchorTx , outputCommitments , stxoProof ,
114
+ testPackets ... ,
115
+ )
87
116
addBip86Output (t , anchorTx .FundedPsbt .Pkt )
88
117
89
118
// Create a proof suffix for all 4 packets now and validate it.
@@ -106,18 +135,34 @@ func TestCreateProofSuffix(t *testing.T) {
106
135
)
107
136
108
137
// Checking the transfer witness is the very last step
109
- // of the proof verification. Since we didn 't properly
138
+ // of the proof verification. Since we don 't properly
110
139
// sign the transfer, we expect the witness to be
111
140
// invalid. But if we get to that point, we know that
112
- // all inclusion and exclusion proofs are correct (which
113
- // is what this test is testing).
141
+ // all inclusion and exclusion proofs are correct. So
142
+ // for successful cases we still expect an error, namely
143
+ // the invalid witness error.
144
+ errCode := txscript .ErrTaprootSigInvalid
114
145
invalidWitnessErr := vm.Error {
115
146
Kind : vm .ErrInvalidTransferWitness ,
116
147
Inner : txscript.Error {
117
- ErrorCode : txscript . ErrTaprootSigInvalid ,
148
+ ErrorCode : errCode ,
118
149
},
119
150
}
120
- require .ErrorIs (t , err , invalidWitnessErr )
151
+ if expectedErr == "" {
152
+ require .ErrorIs (t , err , invalidWitnessErr )
153
+
154
+ continue
155
+ }
156
+
157
+ if vPkt .Outputs [outIdx ].Asset .IsTransferRoot () {
158
+ require .ErrorContains (
159
+ t , err , expectedErr ,
160
+ )
161
+ } else {
162
+ require .ErrorIs (
163
+ t , err , invalidWitnessErr ,
164
+ )
165
+ }
121
166
}
122
167
}
123
168
}
@@ -206,7 +251,7 @@ func createPacket(t *testing.T, a *asset.Asset, split bool,
206
251
207
252
func addOutputCommitment (t * testing.T , anchorTx * AnchorTransaction ,
208
253
outputCommitments map [uint32 ]* commitment.TapCommitment ,
209
- vPackets ... * tappsbt.VPacket ) {
254
+ stxoProof bool , vPackets ... * tappsbt.VPacket ) {
210
255
211
256
packet := anchorTx .FundedPsbt .Pkt
212
257
@@ -245,8 +290,10 @@ func addOutputCommitment(t *testing.T, anchorTx *AnchorTransaction,
245
290
246
291
c , err := commitment .FromAssets (nil , assets ... )
247
292
require .NoError (t , err )
248
- err = c .MergeAltLeaves (stxoAssetsByOutput [idx1 ])
249
- require .NoError (t , err )
293
+ if stxoProof {
294
+ err = c .MergeAltLeaves (stxoAssetsByOutput [idx1 ])
295
+ require .NoError (t , err )
296
+ }
250
297
251
298
internalKey := keyByOutput [idx1 ]
252
299
script , err := tapscript .PayToAddrScript (* internalKey , nil , * c )
0 commit comments