@@ -1257,6 +1257,7 @@ func TestReconstructScript(t *testing.T) {
1257
1257
pkScript string
1258
1258
witness []string
1259
1259
class ScriptClass
1260
+ expectErr bool
1260
1261
}{
1261
1262
{
1262
1263
// 8ea059a12212dd6d2ca3a87b9550bbaa290211679a6be990e9ed8152094c987d:0 on testnet3
@@ -1271,7 +1272,8 @@ func TestReconstructScript(t *testing.T) {
1271
1272
"DATA_33 0x037b80492279732766f5960bd3" +
1272
1273
"8b18a2ae7089a1efdaf188d2a536bffd3430c574 " +
1273
1274
"OP_DUP OP_DROP" ,
1274
- class : PubKeyHashTy ,
1275
+ class : PubKeyHashTy ,
1276
+ expectErr : false ,
1275
1277
},
1276
1278
{
1277
1279
// 37096812a90af1a8a3267d3f9d75111a25e2a8c5411770998e0ee5f75599c9cc:1 on mainnet
@@ -1287,7 +1289,8 @@ func TestReconstructScript(t *testing.T) {
1287
1289
"03f7fda7194f762c315362487d2f65f3807d0cd34e" +
1288
1290
"285bab7c2a5db2155911ece3" ,
1289
1291
},
1290
- class : ScriptHashTy ,
1292
+ class : ScriptHashTy ,
1293
+ expectErr : false ,
1291
1294
},
1292
1295
{
1293
1296
// 8127acdb257b70c74857be882e869e80f081f460f70dc8b6490cd32ecc14c55f:1 on mainnet
@@ -1301,7 +1304,8 @@ func TestReconstructScript(t *testing.T) {
1301
1304
"c1aed639fdfd818ac7028259" },
1302
1305
pkScript : "0 DATA_20 " +
1303
1306
"0x8d6046312c5c9d4bf42dc53e1b5a668a23d573eb" ,
1304
- class : WitnessV0PubKeyHashTy ,
1307
+ class : WitnessV0PubKeyHashTy ,
1308
+ expectErr : false ,
1305
1309
},
1306
1310
{
1307
1311
// b714a52258e3034e532a188433a4506ca806cf1885d21034fb26906cc4a1c3c3:1 on mainnet
@@ -1324,7 +1328,18 @@ func TestReconstructScript(t *testing.T) {
1324
1328
"6d495bfdd5ba4145e3e046fee45e84a8a4" +
1325
1329
"8ad05bd8dbb395c011a32cf9f88053ae" ,
1326
1330
},
1327
- class : WitnessV0ScriptHashTy ,
1331
+ class : WitnessV0ScriptHashTy ,
1332
+ expectErr : false ,
1333
+ },
1334
+ {
1335
+ // b714a52258e3034e532a188433a4506ca806cf1885d21034fb26906cc4a1c3c3:1 on mainnet
1336
+ // but missing witness.
1337
+ name : "p2wsh" ,
1338
+ pkScript : "0 DATA_32 0x701a8d401c84fb13e6baf169d5968" +
1339
+ "4e17abd9fa216c8cc5b9fc63d622ff8c58d" ,
1340
+ witness : []string {},
1341
+ class : WitnessV0ScriptHashTy ,
1342
+ expectErr : true ,
1328
1343
},
1329
1344
{
1330
1345
// 4cd658ba8b5f10f2544becf4f1756d5e929d72f0a7372a120cc2affc16679e8d:0 on mainnet
@@ -1337,7 +1352,8 @@ func TestReconstructScript(t *testing.T) {
1337
1352
"f28ed45df7fb4d9f71764c9aaad3e46f4c36921934" +
1338
1353
"cc6022100ef76bcd57a871129836d7fe3b898e97bf" +
1339
1354
"6a241e7d81c2ae3b026567b9246c4dc01" ,
1340
- class : PubKeyTy ,
1355
+ class : PubKeyTy ,
1356
+ expectErr : false ,
1341
1357
},
1342
1358
}
1343
1359
@@ -1347,20 +1363,25 @@ func TestReconstructScript(t *testing.T) {
1347
1363
1348
1364
var witness wire.TxWitness
1349
1365
1350
- for _ , witElement := range test .witness {
1351
- wit , err := hex .DecodeString (witElement )
1352
- if err != nil {
1353
- t .Fatalf ("%s: unable to decode witness " +
1354
- "element: %v" , test .name , err )
1355
- }
1366
+ if ! test .expectErr {
1367
+ for _ , witElement := range test .witness {
1368
+ wit , err := hex .DecodeString (witElement )
1369
+ if err != nil {
1370
+ t .Fatalf ("%s: unable to decode witness " +
1371
+ "element: %v" , test .name , err )
1372
+ }
1356
1373
1357
- witness = append (witness , wit )
1374
+ witness = append (witness , wit )
1375
+ }
1358
1376
}
1359
1377
1360
1378
reconScript , err := ReconstructScript (sigScript , witness , test .class )
1361
1379
if err != nil {
1362
- t .Errorf ("%s: got unexpected error - %v" ,
1363
- test .name , err )
1380
+ if ! test .expectErr {
1381
+ t .Errorf ("%s: got unexpected error - %v" ,
1382
+ test .name , err )
1383
+ }
1384
+ return
1364
1385
}
1365
1386
1366
1387
if (test .class == PubKeyHashTy ) ||
0 commit comments