1 // Copyright (c) 2013-2017 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 "github.com/btcsuite/btcd/wire"
15 // TestParseOpcode tests for opcode parsing with bad data templates.
16 func TestParseOpcode(t *testing.T) {
17 // Deep copy the array and make one of the opcodes invalid by setting it
18 // to the wrong length.
19 fakeArray := opcodeArray
20 fakeArray[OP_PUSHDATA4] = opcode{value: OP_PUSHDATA4,
21 name: "OP_PUSHDATA4", length: -8, opfunc: opcodePushData}
23 // This script would be fine if -8 was a valid length.
24 _, err := parseScriptTemplate([]byte{OP_PUSHDATA4, 0x1, 0x00, 0x00,
25 0x00, 0x00, 0x00, 0x00, 0x00}, &fakeArray)
27 t.Errorf("no error with dodgy opcode array!")
31 // TestUnparsingInvalidOpcodes tests for errors when unparsing invalid parsed
33 func TestUnparsingInvalidOpcodes(t *testing.T) {
42 opcode: &opcodeArray[OP_FALSE],
48 name: "OP_FALSE long",
50 opcode: &opcodeArray[OP_FALSE],
51 data: make([]byte, 1),
53 expectedErr: scriptError(ErrInternal, ""),
56 name: "OP_DATA_1 short",
58 opcode: &opcodeArray[OP_DATA_1],
61 expectedErr: scriptError(ErrInternal, ""),
66 opcode: &opcodeArray[OP_DATA_1],
67 data: make([]byte, 1),
72 name: "OP_DATA_1 long",
74 opcode: &opcodeArray[OP_DATA_1],
75 data: make([]byte, 2),
77 expectedErr: scriptError(ErrInternal, ""),
80 name: "OP_DATA_2 short",
82 opcode: &opcodeArray[OP_DATA_2],
83 data: make([]byte, 1),
85 expectedErr: scriptError(ErrInternal, ""),
90 opcode: &opcodeArray[OP_DATA_2],
91 data: make([]byte, 2),
96 name: "OP_DATA_2 long",
98 opcode: &opcodeArray[OP_DATA_2],
99 data: make([]byte, 3),
101 expectedErr: scriptError(ErrInternal, ""),
104 name: "OP_DATA_3 short",
106 opcode: &opcodeArray[OP_DATA_3],
107 data: make([]byte, 2),
109 expectedErr: scriptError(ErrInternal, ""),
114 opcode: &opcodeArray[OP_DATA_3],
115 data: make([]byte, 3),
120 name: "OP_DATA_3 long",
122 opcode: &opcodeArray[OP_DATA_3],
123 data: make([]byte, 4),
125 expectedErr: scriptError(ErrInternal, ""),
128 name: "OP_DATA_4 short",
130 opcode: &opcodeArray[OP_DATA_4],
131 data: make([]byte, 3),
133 expectedErr: scriptError(ErrInternal, ""),
138 opcode: &opcodeArray[OP_DATA_4],
139 data: make([]byte, 4),
144 name: "OP_DATA_4 long",
146 opcode: &opcodeArray[OP_DATA_4],
147 data: make([]byte, 5),
149 expectedErr: scriptError(ErrInternal, ""),
152 name: "OP_DATA_5 short",
154 opcode: &opcodeArray[OP_DATA_5],
155 data: make([]byte, 4),
157 expectedErr: scriptError(ErrInternal, ""),
162 opcode: &opcodeArray[OP_DATA_5],
163 data: make([]byte, 5),
168 name: "OP_DATA_5 long",
170 opcode: &opcodeArray[OP_DATA_5],
171 data: make([]byte, 6),
173 expectedErr: scriptError(ErrInternal, ""),
176 name: "OP_DATA_6 short",
178 opcode: &opcodeArray[OP_DATA_6],
179 data: make([]byte, 5),
181 expectedErr: scriptError(ErrInternal, ""),
186 opcode: &opcodeArray[OP_DATA_6],
187 data: make([]byte, 6),
192 name: "OP_DATA_6 long",
194 opcode: &opcodeArray[OP_DATA_6],
195 data: make([]byte, 7),
197 expectedErr: scriptError(ErrInternal, ""),
200 name: "OP_DATA_7 short",
202 opcode: &opcodeArray[OP_DATA_7],
203 data: make([]byte, 6),
205 expectedErr: scriptError(ErrInternal, ""),
210 opcode: &opcodeArray[OP_DATA_7],
211 data: make([]byte, 7),
216 name: "OP_DATA_7 long",
218 opcode: &opcodeArray[OP_DATA_7],
219 data: make([]byte, 8),
221 expectedErr: scriptError(ErrInternal, ""),
224 name: "OP_DATA_8 short",
226 opcode: &opcodeArray[OP_DATA_8],
227 data: make([]byte, 7),
229 expectedErr: scriptError(ErrInternal, ""),
234 opcode: &opcodeArray[OP_DATA_8],
235 data: make([]byte, 8),
240 name: "OP_DATA_8 long",
242 opcode: &opcodeArray[OP_DATA_8],
243 data: make([]byte, 9),
245 expectedErr: scriptError(ErrInternal, ""),
248 name: "OP_DATA_9 short",
250 opcode: &opcodeArray[OP_DATA_9],
251 data: make([]byte, 8),
253 expectedErr: scriptError(ErrInternal, ""),
258 opcode: &opcodeArray[OP_DATA_9],
259 data: make([]byte, 9),
264 name: "OP_DATA_9 long",
266 opcode: &opcodeArray[OP_DATA_9],
267 data: make([]byte, 10),
269 expectedErr: scriptError(ErrInternal, ""),
272 name: "OP_DATA_10 short",
274 opcode: &opcodeArray[OP_DATA_10],
275 data: make([]byte, 9),
277 expectedErr: scriptError(ErrInternal, ""),
282 opcode: &opcodeArray[OP_DATA_10],
283 data: make([]byte, 10),
288 name: "OP_DATA_10 long",
290 opcode: &opcodeArray[OP_DATA_10],
291 data: make([]byte, 11),
293 expectedErr: scriptError(ErrInternal, ""),
296 name: "OP_DATA_11 short",
298 opcode: &opcodeArray[OP_DATA_11],
299 data: make([]byte, 10),
301 expectedErr: scriptError(ErrInternal, ""),
306 opcode: &opcodeArray[OP_DATA_11],
307 data: make([]byte, 11),
312 name: "OP_DATA_11 long",
314 opcode: &opcodeArray[OP_DATA_11],
315 data: make([]byte, 12),
317 expectedErr: scriptError(ErrInternal, ""),
320 name: "OP_DATA_12 short",
322 opcode: &opcodeArray[OP_DATA_12],
323 data: make([]byte, 11),
325 expectedErr: scriptError(ErrInternal, ""),
330 opcode: &opcodeArray[OP_DATA_12],
331 data: make([]byte, 12),
336 name: "OP_DATA_12 long",
338 opcode: &opcodeArray[OP_DATA_12],
339 data: make([]byte, 13),
341 expectedErr: scriptError(ErrInternal, ""),
344 name: "OP_DATA_13 short",
346 opcode: &opcodeArray[OP_DATA_13],
347 data: make([]byte, 12),
349 expectedErr: scriptError(ErrInternal, ""),
354 opcode: &opcodeArray[OP_DATA_13],
355 data: make([]byte, 13),
360 name: "OP_DATA_13 long",
362 opcode: &opcodeArray[OP_DATA_13],
363 data: make([]byte, 14),
365 expectedErr: scriptError(ErrInternal, ""),
368 name: "OP_DATA_14 short",
370 opcode: &opcodeArray[OP_DATA_14],
371 data: make([]byte, 13),
373 expectedErr: scriptError(ErrInternal, ""),
378 opcode: &opcodeArray[OP_DATA_14],
379 data: make([]byte, 14),
384 name: "OP_DATA_14 long",
386 opcode: &opcodeArray[OP_DATA_14],
387 data: make([]byte, 15),
389 expectedErr: scriptError(ErrInternal, ""),
392 name: "OP_DATA_15 short",
394 opcode: &opcodeArray[OP_DATA_15],
395 data: make([]byte, 14),
397 expectedErr: scriptError(ErrInternal, ""),
402 opcode: &opcodeArray[OP_DATA_15],
403 data: make([]byte, 15),
408 name: "OP_DATA_15 long",
410 opcode: &opcodeArray[OP_DATA_15],
411 data: make([]byte, 16),
413 expectedErr: scriptError(ErrInternal, ""),
416 name: "OP_DATA_16 short",
418 opcode: &opcodeArray[OP_DATA_16],
419 data: make([]byte, 15),
421 expectedErr: scriptError(ErrInternal, ""),
426 opcode: &opcodeArray[OP_DATA_16],
427 data: make([]byte, 16),
432 name: "OP_DATA_16 long",
434 opcode: &opcodeArray[OP_DATA_16],
435 data: make([]byte, 17),
437 expectedErr: scriptError(ErrInternal, ""),
440 name: "OP_DATA_17 short",
442 opcode: &opcodeArray[OP_DATA_17],
443 data: make([]byte, 16),
445 expectedErr: scriptError(ErrInternal, ""),
450 opcode: &opcodeArray[OP_DATA_17],
451 data: make([]byte, 17),
456 name: "OP_DATA_17 long",
458 opcode: &opcodeArray[OP_DATA_17],
459 data: make([]byte, 18),
461 expectedErr: scriptError(ErrInternal, ""),
464 name: "OP_DATA_18 short",
466 opcode: &opcodeArray[OP_DATA_18],
467 data: make([]byte, 17),
469 expectedErr: scriptError(ErrInternal, ""),
474 opcode: &opcodeArray[OP_DATA_18],
475 data: make([]byte, 18),
480 name: "OP_DATA_18 long",
482 opcode: &opcodeArray[OP_DATA_18],
483 data: make([]byte, 19),
485 expectedErr: scriptError(ErrInternal, ""),
488 name: "OP_DATA_19 short",
490 opcode: &opcodeArray[OP_DATA_19],
491 data: make([]byte, 18),
493 expectedErr: scriptError(ErrInternal, ""),
498 opcode: &opcodeArray[OP_DATA_19],
499 data: make([]byte, 19),
504 name: "OP_DATA_19 long",
506 opcode: &opcodeArray[OP_DATA_19],
507 data: make([]byte, 20),
509 expectedErr: scriptError(ErrInternal, ""),
512 name: "OP_DATA_20 short",
514 opcode: &opcodeArray[OP_DATA_20],
515 data: make([]byte, 19),
517 expectedErr: scriptError(ErrInternal, ""),
522 opcode: &opcodeArray[OP_DATA_20],
523 data: make([]byte, 20),
528 name: "OP_DATA_20 long",
530 opcode: &opcodeArray[OP_DATA_20],
531 data: make([]byte, 21),
533 expectedErr: scriptError(ErrInternal, ""),
536 name: "OP_DATA_21 short",
538 opcode: &opcodeArray[OP_DATA_21],
539 data: make([]byte, 20),
541 expectedErr: scriptError(ErrInternal, ""),
546 opcode: &opcodeArray[OP_DATA_21],
547 data: make([]byte, 21),
552 name: "OP_DATA_21 long",
554 opcode: &opcodeArray[OP_DATA_21],
555 data: make([]byte, 22),
557 expectedErr: scriptError(ErrInternal, ""),
560 name: "OP_DATA_22 short",
562 opcode: &opcodeArray[OP_DATA_22],
563 data: make([]byte, 21),
565 expectedErr: scriptError(ErrInternal, ""),
570 opcode: &opcodeArray[OP_DATA_22],
571 data: make([]byte, 22),
576 name: "OP_DATA_22 long",
578 opcode: &opcodeArray[OP_DATA_22],
579 data: make([]byte, 23),
581 expectedErr: scriptError(ErrInternal, ""),
584 name: "OP_DATA_23 short",
586 opcode: &opcodeArray[OP_DATA_23],
587 data: make([]byte, 22),
589 expectedErr: scriptError(ErrInternal, ""),
594 opcode: &opcodeArray[OP_DATA_23],
595 data: make([]byte, 23),
600 name: "OP_DATA_23 long",
602 opcode: &opcodeArray[OP_DATA_23],
603 data: make([]byte, 24),
605 expectedErr: scriptError(ErrInternal, ""),
608 name: "OP_DATA_24 short",
610 opcode: &opcodeArray[OP_DATA_24],
611 data: make([]byte, 23),
613 expectedErr: scriptError(ErrInternal, ""),
618 opcode: &opcodeArray[OP_DATA_24],
619 data: make([]byte, 24),
624 name: "OP_DATA_24 long",
626 opcode: &opcodeArray[OP_DATA_24],
627 data: make([]byte, 25),
629 expectedErr: scriptError(ErrInternal, ""),
632 name: "OP_DATA_25 short",
634 opcode: &opcodeArray[OP_DATA_25],
635 data: make([]byte, 24),
637 expectedErr: scriptError(ErrInternal, ""),
642 opcode: &opcodeArray[OP_DATA_25],
643 data: make([]byte, 25),
648 name: "OP_DATA_25 long",
650 opcode: &opcodeArray[OP_DATA_25],
651 data: make([]byte, 26),
653 expectedErr: scriptError(ErrInternal, ""),
656 name: "OP_DATA_26 short",
658 opcode: &opcodeArray[OP_DATA_26],
659 data: make([]byte, 25),
661 expectedErr: scriptError(ErrInternal, ""),
666 opcode: &opcodeArray[OP_DATA_26],
667 data: make([]byte, 26),
672 name: "OP_DATA_26 long",
674 opcode: &opcodeArray[OP_DATA_26],
675 data: make([]byte, 27),
677 expectedErr: scriptError(ErrInternal, ""),
680 name: "OP_DATA_27 short",
682 opcode: &opcodeArray[OP_DATA_27],
683 data: make([]byte, 26),
685 expectedErr: scriptError(ErrInternal, ""),
690 opcode: &opcodeArray[OP_DATA_27],
691 data: make([]byte, 27),
696 name: "OP_DATA_27 long",
698 opcode: &opcodeArray[OP_DATA_27],
699 data: make([]byte, 28),
701 expectedErr: scriptError(ErrInternal, ""),
704 name: "OP_DATA_28 short",
706 opcode: &opcodeArray[OP_DATA_28],
707 data: make([]byte, 27),
709 expectedErr: scriptError(ErrInternal, ""),
714 opcode: &opcodeArray[OP_DATA_28],
715 data: make([]byte, 28),
720 name: "OP_DATA_28 long",
722 opcode: &opcodeArray[OP_DATA_28],
723 data: make([]byte, 29),
725 expectedErr: scriptError(ErrInternal, ""),
728 name: "OP_DATA_29 short",
730 opcode: &opcodeArray[OP_DATA_29],
731 data: make([]byte, 28),
733 expectedErr: scriptError(ErrInternal, ""),
738 opcode: &opcodeArray[OP_DATA_29],
739 data: make([]byte, 29),
744 name: "OP_DATA_29 long",
746 opcode: &opcodeArray[OP_DATA_29],
747 data: make([]byte, 30),
749 expectedErr: scriptError(ErrInternal, ""),
752 name: "OP_DATA_30 short",
754 opcode: &opcodeArray[OP_DATA_30],
755 data: make([]byte, 29),
757 expectedErr: scriptError(ErrInternal, ""),
762 opcode: &opcodeArray[OP_DATA_30],
763 data: make([]byte, 30),
768 name: "OP_DATA_30 long",
770 opcode: &opcodeArray[OP_DATA_30],
771 data: make([]byte, 31),
773 expectedErr: scriptError(ErrInternal, ""),
776 name: "OP_DATA_31 short",
778 opcode: &opcodeArray[OP_DATA_31],
779 data: make([]byte, 30),
781 expectedErr: scriptError(ErrInternal, ""),
786 opcode: &opcodeArray[OP_DATA_31],
787 data: make([]byte, 31),
792 name: "OP_DATA_31 long",
794 opcode: &opcodeArray[OP_DATA_31],
795 data: make([]byte, 32),
797 expectedErr: scriptError(ErrInternal, ""),
800 name: "OP_DATA_32 short",
802 opcode: &opcodeArray[OP_DATA_32],
803 data: make([]byte, 31),
805 expectedErr: scriptError(ErrInternal, ""),
810 opcode: &opcodeArray[OP_DATA_32],
811 data: make([]byte, 32),
816 name: "OP_DATA_32 long",
818 opcode: &opcodeArray[OP_DATA_32],
819 data: make([]byte, 33),
821 expectedErr: scriptError(ErrInternal, ""),
824 name: "OP_DATA_33 short",
826 opcode: &opcodeArray[OP_DATA_33],
827 data: make([]byte, 32),
829 expectedErr: scriptError(ErrInternal, ""),
834 opcode: &opcodeArray[OP_DATA_33],
835 data: make([]byte, 33),
840 name: "OP_DATA_33 long",
842 opcode: &opcodeArray[OP_DATA_33],
843 data: make([]byte, 34),
845 expectedErr: scriptError(ErrInternal, ""),
848 name: "OP_DATA_34 short",
850 opcode: &opcodeArray[OP_DATA_34],
851 data: make([]byte, 33),
853 expectedErr: scriptError(ErrInternal, ""),
858 opcode: &opcodeArray[OP_DATA_34],
859 data: make([]byte, 34),
864 name: "OP_DATA_34 long",
866 opcode: &opcodeArray[OP_DATA_34],
867 data: make([]byte, 35),
869 expectedErr: scriptError(ErrInternal, ""),
872 name: "OP_DATA_35 short",
874 opcode: &opcodeArray[OP_DATA_35],
875 data: make([]byte, 34),
877 expectedErr: scriptError(ErrInternal, ""),
882 opcode: &opcodeArray[OP_DATA_35],
883 data: make([]byte, 35),
888 name: "OP_DATA_35 long",
890 opcode: &opcodeArray[OP_DATA_35],
891 data: make([]byte, 36),
893 expectedErr: scriptError(ErrInternal, ""),
896 name: "OP_DATA_36 short",
898 opcode: &opcodeArray[OP_DATA_36],
899 data: make([]byte, 35),
901 expectedErr: scriptError(ErrInternal, ""),
906 opcode: &opcodeArray[OP_DATA_36],
907 data: make([]byte, 36),
912 name: "OP_DATA_36 long",
914 opcode: &opcodeArray[OP_DATA_36],
915 data: make([]byte, 37),
917 expectedErr: scriptError(ErrInternal, ""),
920 name: "OP_DATA_37 short",
922 opcode: &opcodeArray[OP_DATA_37],
923 data: make([]byte, 36),
925 expectedErr: scriptError(ErrInternal, ""),
930 opcode: &opcodeArray[OP_DATA_37],
931 data: make([]byte, 37),
936 name: "OP_DATA_37 long",
938 opcode: &opcodeArray[OP_DATA_37],
939 data: make([]byte, 38),
941 expectedErr: scriptError(ErrInternal, ""),
944 name: "OP_DATA_38 short",
946 opcode: &opcodeArray[OP_DATA_38],
947 data: make([]byte, 37),
949 expectedErr: scriptError(ErrInternal, ""),
954 opcode: &opcodeArray[OP_DATA_38],
955 data: make([]byte, 38),
960 name: "OP_DATA_38 long",
962 opcode: &opcodeArray[OP_DATA_38],
963 data: make([]byte, 39),
965 expectedErr: scriptError(ErrInternal, ""),
968 name: "OP_DATA_39 short",
970 opcode: &opcodeArray[OP_DATA_39],
971 data: make([]byte, 38),
973 expectedErr: scriptError(ErrInternal, ""),
978 opcode: &opcodeArray[OP_DATA_39],
979 data: make([]byte, 39),
984 name: "OP_DATA_39 long",
986 opcode: &opcodeArray[OP_DATA_39],
987 data: make([]byte, 40),
989 expectedErr: scriptError(ErrInternal, ""),
992 name: "OP_DATA_40 short",
994 opcode: &opcodeArray[OP_DATA_40],
995 data: make([]byte, 39),
997 expectedErr: scriptError(ErrInternal, ""),
1002 opcode: &opcodeArray[OP_DATA_40],
1003 data: make([]byte, 40),
1008 name: "OP_DATA_40 long",
1010 opcode: &opcodeArray[OP_DATA_40],
1011 data: make([]byte, 41),
1013 expectedErr: scriptError(ErrInternal, ""),
1016 name: "OP_DATA_41 short",
1018 opcode: &opcodeArray[OP_DATA_41],
1019 data: make([]byte, 40),
1021 expectedErr: scriptError(ErrInternal, ""),
1026 opcode: &opcodeArray[OP_DATA_41],
1027 data: make([]byte, 41),
1032 name: "OP_DATA_41 long",
1034 opcode: &opcodeArray[OP_DATA_41],
1035 data: make([]byte, 42),
1037 expectedErr: scriptError(ErrInternal, ""),
1040 name: "OP_DATA_42 short",
1042 opcode: &opcodeArray[OP_DATA_42],
1043 data: make([]byte, 41),
1045 expectedErr: scriptError(ErrInternal, ""),
1050 opcode: &opcodeArray[OP_DATA_42],
1051 data: make([]byte, 42),
1056 name: "OP_DATA_42 long",
1058 opcode: &opcodeArray[OP_DATA_42],
1059 data: make([]byte, 43),
1061 expectedErr: scriptError(ErrInternal, ""),
1064 name: "OP_DATA_43 short",
1066 opcode: &opcodeArray[OP_DATA_43],
1067 data: make([]byte, 42),
1069 expectedErr: scriptError(ErrInternal, ""),
1074 opcode: &opcodeArray[OP_DATA_43],
1075 data: make([]byte, 43),
1080 name: "OP_DATA_43 long",
1082 opcode: &opcodeArray[OP_DATA_43],
1083 data: make([]byte, 44),
1085 expectedErr: scriptError(ErrInternal, ""),
1088 name: "OP_DATA_44 short",
1090 opcode: &opcodeArray[OP_DATA_44],
1091 data: make([]byte, 43),
1093 expectedErr: scriptError(ErrInternal, ""),
1098 opcode: &opcodeArray[OP_DATA_44],
1099 data: make([]byte, 44),
1104 name: "OP_DATA_44 long",
1106 opcode: &opcodeArray[OP_DATA_44],
1107 data: make([]byte, 45),
1109 expectedErr: scriptError(ErrInternal, ""),
1112 name: "OP_DATA_45 short",
1114 opcode: &opcodeArray[OP_DATA_45],
1115 data: make([]byte, 44),
1117 expectedErr: scriptError(ErrInternal, ""),
1122 opcode: &opcodeArray[OP_DATA_45],
1123 data: make([]byte, 45),
1128 name: "OP_DATA_45 long",
1130 opcode: &opcodeArray[OP_DATA_45],
1131 data: make([]byte, 46),
1133 expectedErr: scriptError(ErrInternal, ""),
1136 name: "OP_DATA_46 short",
1138 opcode: &opcodeArray[OP_DATA_46],
1139 data: make([]byte, 45),
1141 expectedErr: scriptError(ErrInternal, ""),
1146 opcode: &opcodeArray[OP_DATA_46],
1147 data: make([]byte, 46),
1152 name: "OP_DATA_46 long",
1154 opcode: &opcodeArray[OP_DATA_46],
1155 data: make([]byte, 47),
1157 expectedErr: scriptError(ErrInternal, ""),
1160 name: "OP_DATA_47 short",
1162 opcode: &opcodeArray[OP_DATA_47],
1163 data: make([]byte, 46),
1165 expectedErr: scriptError(ErrInternal, ""),
1170 opcode: &opcodeArray[OP_DATA_47],
1171 data: make([]byte, 47),
1176 name: "OP_DATA_47 long",
1178 opcode: &opcodeArray[OP_DATA_47],
1179 data: make([]byte, 48),
1181 expectedErr: scriptError(ErrInternal, ""),
1184 name: "OP_DATA_48 short",
1186 opcode: &opcodeArray[OP_DATA_48],
1187 data: make([]byte, 47),
1189 expectedErr: scriptError(ErrInternal, ""),
1194 opcode: &opcodeArray[OP_DATA_48],
1195 data: make([]byte, 48),
1200 name: "OP_DATA_48 long",
1202 opcode: &opcodeArray[OP_DATA_48],
1203 data: make([]byte, 49),
1205 expectedErr: scriptError(ErrInternal, ""),
1208 name: "OP_DATA_49 short",
1210 opcode: &opcodeArray[OP_DATA_49],
1211 data: make([]byte, 48),
1213 expectedErr: scriptError(ErrInternal, ""),
1218 opcode: &opcodeArray[OP_DATA_49],
1219 data: make([]byte, 49),
1224 name: "OP_DATA_49 long",
1226 opcode: &opcodeArray[OP_DATA_49],
1227 data: make([]byte, 50),
1229 expectedErr: scriptError(ErrInternal, ""),
1232 name: "OP_DATA_50 short",
1234 opcode: &opcodeArray[OP_DATA_50],
1235 data: make([]byte, 49),
1237 expectedErr: scriptError(ErrInternal, ""),
1242 opcode: &opcodeArray[OP_DATA_50],
1243 data: make([]byte, 50),
1248 name: "OP_DATA_50 long",
1250 opcode: &opcodeArray[OP_DATA_50],
1251 data: make([]byte, 51),
1253 expectedErr: scriptError(ErrInternal, ""),
1256 name: "OP_DATA_51 short",
1258 opcode: &opcodeArray[OP_DATA_51],
1259 data: make([]byte, 50),
1261 expectedErr: scriptError(ErrInternal, ""),
1266 opcode: &opcodeArray[OP_DATA_51],
1267 data: make([]byte, 51),
1272 name: "OP_DATA_51 long",
1274 opcode: &opcodeArray[OP_DATA_51],
1275 data: make([]byte, 52),
1277 expectedErr: scriptError(ErrInternal, ""),
1280 name: "OP_DATA_52 short",
1282 opcode: &opcodeArray[OP_DATA_52],
1283 data: make([]byte, 51),
1285 expectedErr: scriptError(ErrInternal, ""),
1290 opcode: &opcodeArray[OP_DATA_52],
1291 data: make([]byte, 52),
1296 name: "OP_DATA_52 long",
1298 opcode: &opcodeArray[OP_DATA_52],
1299 data: make([]byte, 53),
1301 expectedErr: scriptError(ErrInternal, ""),
1304 name: "OP_DATA_53 short",
1306 opcode: &opcodeArray[OP_DATA_53],
1307 data: make([]byte, 52),
1309 expectedErr: scriptError(ErrInternal, ""),
1314 opcode: &opcodeArray[OP_DATA_53],
1315 data: make([]byte, 53),
1320 name: "OP_DATA_53 long",
1322 opcode: &opcodeArray[OP_DATA_53],
1323 data: make([]byte, 54),
1325 expectedErr: scriptError(ErrInternal, ""),
1328 name: "OP_DATA_54 short",
1330 opcode: &opcodeArray[OP_DATA_54],
1331 data: make([]byte, 53),
1333 expectedErr: scriptError(ErrInternal, ""),
1338 opcode: &opcodeArray[OP_DATA_54],
1339 data: make([]byte, 54),
1344 name: "OP_DATA_54 long",
1346 opcode: &opcodeArray[OP_DATA_54],
1347 data: make([]byte, 55),
1349 expectedErr: scriptError(ErrInternal, ""),
1352 name: "OP_DATA_55 short",
1354 opcode: &opcodeArray[OP_DATA_55],
1355 data: make([]byte, 54),
1357 expectedErr: scriptError(ErrInternal, ""),
1362 opcode: &opcodeArray[OP_DATA_55],
1363 data: make([]byte, 55),
1368 name: "OP_DATA_55 long",
1370 opcode: &opcodeArray[OP_DATA_55],
1371 data: make([]byte, 56),
1373 expectedErr: scriptError(ErrInternal, ""),
1376 name: "OP_DATA_56 short",
1378 opcode: &opcodeArray[OP_DATA_56],
1379 data: make([]byte, 55),
1381 expectedErr: scriptError(ErrInternal, ""),
1386 opcode: &opcodeArray[OP_DATA_56],
1387 data: make([]byte, 56),
1392 name: "OP_DATA_56 long",
1394 opcode: &opcodeArray[OP_DATA_56],
1395 data: make([]byte, 57),
1397 expectedErr: scriptError(ErrInternal, ""),
1400 name: "OP_DATA_57 short",
1402 opcode: &opcodeArray[OP_DATA_57],
1403 data: make([]byte, 56),
1405 expectedErr: scriptError(ErrInternal, ""),
1410 opcode: &opcodeArray[OP_DATA_57],
1411 data: make([]byte, 57),
1416 name: "OP_DATA_57 long",
1418 opcode: &opcodeArray[OP_DATA_57],
1419 data: make([]byte, 58),
1421 expectedErr: scriptError(ErrInternal, ""),
1424 name: "OP_DATA_58 short",
1426 opcode: &opcodeArray[OP_DATA_58],
1427 data: make([]byte, 57),
1429 expectedErr: scriptError(ErrInternal, ""),
1434 opcode: &opcodeArray[OP_DATA_58],
1435 data: make([]byte, 58),
1440 name: "OP_DATA_58 long",
1442 opcode: &opcodeArray[OP_DATA_58],
1443 data: make([]byte, 59),
1445 expectedErr: scriptError(ErrInternal, ""),
1448 name: "OP_DATA_59 short",
1450 opcode: &opcodeArray[OP_DATA_59],
1451 data: make([]byte, 58),
1453 expectedErr: scriptError(ErrInternal, ""),
1458 opcode: &opcodeArray[OP_DATA_59],
1459 data: make([]byte, 59),
1464 name: "OP_DATA_59 long",
1466 opcode: &opcodeArray[OP_DATA_59],
1467 data: make([]byte, 60),
1469 expectedErr: scriptError(ErrInternal, ""),
1472 name: "OP_DATA_60 short",
1474 opcode: &opcodeArray[OP_DATA_60],
1475 data: make([]byte, 59),
1477 expectedErr: scriptError(ErrInternal, ""),
1482 opcode: &opcodeArray[OP_DATA_60],
1483 data: make([]byte, 60),
1488 name: "OP_DATA_60 long",
1490 opcode: &opcodeArray[OP_DATA_60],
1491 data: make([]byte, 61),
1493 expectedErr: scriptError(ErrInternal, ""),
1496 name: "OP_DATA_61 short",
1498 opcode: &opcodeArray[OP_DATA_61],
1499 data: make([]byte, 60),
1501 expectedErr: scriptError(ErrInternal, ""),
1506 opcode: &opcodeArray[OP_DATA_61],
1507 data: make([]byte, 61),
1512 name: "OP_DATA_61 long",
1514 opcode: &opcodeArray[OP_DATA_61],
1515 data: make([]byte, 62),
1517 expectedErr: scriptError(ErrInternal, ""),
1520 name: "OP_DATA_62 short",
1522 opcode: &opcodeArray[OP_DATA_62],
1523 data: make([]byte, 61),
1525 expectedErr: scriptError(ErrInternal, ""),
1530 opcode: &opcodeArray[OP_DATA_62],
1531 data: make([]byte, 62),
1536 name: "OP_DATA_62 long",
1538 opcode: &opcodeArray[OP_DATA_62],
1539 data: make([]byte, 63),
1541 expectedErr: scriptError(ErrInternal, ""),
1544 name: "OP_DATA_63 short",
1546 opcode: &opcodeArray[OP_DATA_63],
1547 data: make([]byte, 62),
1549 expectedErr: scriptError(ErrInternal, ""),
1554 opcode: &opcodeArray[OP_DATA_63],
1555 data: make([]byte, 63),
1560 name: "OP_DATA_63 long",
1562 opcode: &opcodeArray[OP_DATA_63],
1563 data: make([]byte, 64),
1565 expectedErr: scriptError(ErrInternal, ""),
1568 name: "OP_DATA_64 short",
1570 opcode: &opcodeArray[OP_DATA_64],
1571 data: make([]byte, 63),
1573 expectedErr: scriptError(ErrInternal, ""),
1578 opcode: &opcodeArray[OP_DATA_64],
1579 data: make([]byte, 64),
1584 name: "OP_DATA_64 long",
1586 opcode: &opcodeArray[OP_DATA_64],
1587 data: make([]byte, 65),
1589 expectedErr: scriptError(ErrInternal, ""),
1592 name: "OP_DATA_65 short",
1594 opcode: &opcodeArray[OP_DATA_65],
1595 data: make([]byte, 64),
1597 expectedErr: scriptError(ErrInternal, ""),
1602 opcode: &opcodeArray[OP_DATA_65],
1603 data: make([]byte, 65),
1608 name: "OP_DATA_65 long",
1610 opcode: &opcodeArray[OP_DATA_65],
1611 data: make([]byte, 66),
1613 expectedErr: scriptError(ErrInternal, ""),
1616 name: "OP_DATA_66 short",
1618 opcode: &opcodeArray[OP_DATA_66],
1619 data: make([]byte, 65),
1621 expectedErr: scriptError(ErrInternal, ""),
1626 opcode: &opcodeArray[OP_DATA_66],
1627 data: make([]byte, 66),
1632 name: "OP_DATA_66 long",
1634 opcode: &opcodeArray[OP_DATA_66],
1635 data: make([]byte, 67),
1637 expectedErr: scriptError(ErrInternal, ""),
1640 name: "OP_DATA_67 short",
1642 opcode: &opcodeArray[OP_DATA_67],
1643 data: make([]byte, 66),
1645 expectedErr: scriptError(ErrInternal, ""),
1650 opcode: &opcodeArray[OP_DATA_67],
1651 data: make([]byte, 67),
1656 name: "OP_DATA_67 long",
1658 opcode: &opcodeArray[OP_DATA_67],
1659 data: make([]byte, 68),
1661 expectedErr: scriptError(ErrInternal, ""),
1664 name: "OP_DATA_68 short",
1666 opcode: &opcodeArray[OP_DATA_68],
1667 data: make([]byte, 67),
1669 expectedErr: scriptError(ErrInternal, ""),
1674 opcode: &opcodeArray[OP_DATA_68],
1675 data: make([]byte, 68),
1680 name: "OP_DATA_68 long",
1682 opcode: &opcodeArray[OP_DATA_68],
1683 data: make([]byte, 69),
1685 expectedErr: scriptError(ErrInternal, ""),
1688 name: "OP_DATA_69 short",
1690 opcode: &opcodeArray[OP_DATA_69],
1691 data: make([]byte, 68),
1693 expectedErr: scriptError(ErrInternal, ""),
1698 opcode: &opcodeArray[OP_DATA_69],
1699 data: make([]byte, 69),
1704 name: "OP_DATA_69 long",
1706 opcode: &opcodeArray[OP_DATA_69],
1707 data: make([]byte, 70),
1709 expectedErr: scriptError(ErrInternal, ""),
1712 name: "OP_DATA_70 short",
1714 opcode: &opcodeArray[OP_DATA_70],
1715 data: make([]byte, 69),
1717 expectedErr: scriptError(ErrInternal, ""),
1722 opcode: &opcodeArray[OP_DATA_70],
1723 data: make([]byte, 70),
1728 name: "OP_DATA_70 long",
1730 opcode: &opcodeArray[OP_DATA_70],
1731 data: make([]byte, 71),
1733 expectedErr: scriptError(ErrInternal, ""),
1736 name: "OP_DATA_71 short",
1738 opcode: &opcodeArray[OP_DATA_71],
1739 data: make([]byte, 70),
1741 expectedErr: scriptError(ErrInternal, ""),
1746 opcode: &opcodeArray[OP_DATA_71],
1747 data: make([]byte, 71),
1752 name: "OP_DATA_71 long",
1754 opcode: &opcodeArray[OP_DATA_71],
1755 data: make([]byte, 72),
1757 expectedErr: scriptError(ErrInternal, ""),
1760 name: "OP_DATA_72 short",
1762 opcode: &opcodeArray[OP_DATA_72],
1763 data: make([]byte, 71),
1765 expectedErr: scriptError(ErrInternal, ""),
1770 opcode: &opcodeArray[OP_DATA_72],
1771 data: make([]byte, 72),
1776 name: "OP_DATA_72 long",
1778 opcode: &opcodeArray[OP_DATA_72],
1779 data: make([]byte, 73),
1781 expectedErr: scriptError(ErrInternal, ""),
1784 name: "OP_DATA_73 short",
1786 opcode: &opcodeArray[OP_DATA_73],
1787 data: make([]byte, 72),
1789 expectedErr: scriptError(ErrInternal, ""),
1794 opcode: &opcodeArray[OP_DATA_73],
1795 data: make([]byte, 73),
1800 name: "OP_DATA_73 long",
1802 opcode: &opcodeArray[OP_DATA_73],
1803 data: make([]byte, 74),
1805 expectedErr: scriptError(ErrInternal, ""),
1808 name: "OP_DATA_74 short",
1810 opcode: &opcodeArray[OP_DATA_74],
1811 data: make([]byte, 73),
1813 expectedErr: scriptError(ErrInternal, ""),
1818 opcode: &opcodeArray[OP_DATA_74],
1819 data: make([]byte, 74),
1824 name: "OP_DATA_74 long",
1826 opcode: &opcodeArray[OP_DATA_74],
1827 data: make([]byte, 75),
1829 expectedErr: scriptError(ErrInternal, ""),
1832 name: "OP_DATA_75 short",
1834 opcode: &opcodeArray[OP_DATA_75],
1835 data: make([]byte, 74),
1837 expectedErr: scriptError(ErrInternal, ""),
1842 opcode: &opcodeArray[OP_DATA_75],
1843 data: make([]byte, 75),
1848 name: "OP_DATA_75 long",
1850 opcode: &opcodeArray[OP_DATA_75],
1851 data: make([]byte, 76),
1853 expectedErr: scriptError(ErrInternal, ""),
1856 name: "OP_PUSHDATA1",
1858 opcode: &opcodeArray[OP_PUSHDATA1],
1859 data: []byte{0, 1, 2, 3, 4},
1864 name: "OP_PUSHDATA2",
1866 opcode: &opcodeArray[OP_PUSHDATA2],
1867 data: []byte{0, 1, 2, 3, 4},
1872 name: "OP_PUSHDATA4",
1874 opcode: &opcodeArray[OP_PUSHDATA1],
1875 data: []byte{0, 1, 2, 3, 4},
1882 opcode: &opcodeArray[OP_1NEGATE],
1888 name: "OP_1NEGATE long",
1890 opcode: &opcodeArray[OP_1NEGATE],
1891 data: make([]byte, 1),
1893 expectedErr: scriptError(ErrInternal, ""),
1896 name: "OP_RESERVED",
1898 opcode: &opcodeArray[OP_RESERVED],
1904 name: "OP_RESERVED long",
1906 opcode: &opcodeArray[OP_RESERVED],
1907 data: make([]byte, 1),
1909 expectedErr: scriptError(ErrInternal, ""),
1914 opcode: &opcodeArray[OP_TRUE],
1920 name: "OP_TRUE long",
1922 opcode: &opcodeArray[OP_TRUE],
1923 data: make([]byte, 1),
1925 expectedErr: scriptError(ErrInternal, ""),
1930 opcode: &opcodeArray[OP_2],
1938 opcode: &opcodeArray[OP_2],
1939 data: make([]byte, 1),
1941 expectedErr: scriptError(ErrInternal, ""),
1946 opcode: &opcodeArray[OP_2],
1954 opcode: &opcodeArray[OP_2],
1955 data: make([]byte, 1),
1957 expectedErr: scriptError(ErrInternal, ""),
1962 opcode: &opcodeArray[OP_3],
1970 opcode: &opcodeArray[OP_3],
1971 data: make([]byte, 1),
1973 expectedErr: scriptError(ErrInternal, ""),
1978 opcode: &opcodeArray[OP_4],
1986 opcode: &opcodeArray[OP_4],
1987 data: make([]byte, 1),
1989 expectedErr: scriptError(ErrInternal, ""),
1994 opcode: &opcodeArray[OP_5],
2002 opcode: &opcodeArray[OP_5],
2003 data: make([]byte, 1),
2005 expectedErr: scriptError(ErrInternal, ""),
2010 opcode: &opcodeArray[OP_6],
2018 opcode: &opcodeArray[OP_6],
2019 data: make([]byte, 1),
2021 expectedErr: scriptError(ErrInternal, ""),
2026 opcode: &opcodeArray[OP_7],
2034 opcode: &opcodeArray[OP_7],
2035 data: make([]byte, 1),
2037 expectedErr: scriptError(ErrInternal, ""),
2042 opcode: &opcodeArray[OP_8],
2050 opcode: &opcodeArray[OP_8],
2051 data: make([]byte, 1),
2053 expectedErr: scriptError(ErrInternal, ""),
2058 opcode: &opcodeArray[OP_9],
2066 opcode: &opcodeArray[OP_9],
2067 data: make([]byte, 1),
2069 expectedErr: scriptError(ErrInternal, ""),
2074 opcode: &opcodeArray[OP_10],
2082 opcode: &opcodeArray[OP_10],
2083 data: make([]byte, 1),
2085 expectedErr: scriptError(ErrInternal, ""),
2090 opcode: &opcodeArray[OP_11],
2098 opcode: &opcodeArray[OP_11],
2099 data: make([]byte, 1),
2101 expectedErr: scriptError(ErrInternal, ""),
2106 opcode: &opcodeArray[OP_12],
2114 opcode: &opcodeArray[OP_12],
2115 data: make([]byte, 1),
2117 expectedErr: scriptError(ErrInternal, ""),
2122 opcode: &opcodeArray[OP_13],
2130 opcode: &opcodeArray[OP_13],
2131 data: make([]byte, 1),
2133 expectedErr: scriptError(ErrInternal, ""),
2138 opcode: &opcodeArray[OP_14],
2146 opcode: &opcodeArray[OP_14],
2147 data: make([]byte, 1),
2149 expectedErr: scriptError(ErrInternal, ""),
2154 opcode: &opcodeArray[OP_15],
2162 opcode: &opcodeArray[OP_15],
2163 data: make([]byte, 1),
2165 expectedErr: scriptError(ErrInternal, ""),
2170 opcode: &opcodeArray[OP_16],
2178 opcode: &opcodeArray[OP_16],
2179 data: make([]byte, 1),
2181 expectedErr: scriptError(ErrInternal, ""),
2186 opcode: &opcodeArray[OP_NOP],
2192 name: "OP_NOP long",
2194 opcode: &opcodeArray[OP_NOP],
2195 data: make([]byte, 1),
2197 expectedErr: scriptError(ErrInternal, ""),
2202 opcode: &opcodeArray[OP_VER],
2208 name: "OP_VER long",
2210 opcode: &opcodeArray[OP_VER],
2211 data: make([]byte, 1),
2213 expectedErr: scriptError(ErrInternal, ""),
2218 opcode: &opcodeArray[OP_IF],
2226 opcode: &opcodeArray[OP_IF],
2227 data: make([]byte, 1),
2229 expectedErr: scriptError(ErrInternal, ""),
2234 opcode: &opcodeArray[OP_NOTIF],
2240 name: "OP_NOTIF long",
2242 opcode: &opcodeArray[OP_NOTIF],
2243 data: make([]byte, 1),
2245 expectedErr: scriptError(ErrInternal, ""),
2250 opcode: &opcodeArray[OP_VERIF],
2256 name: "OP_VERIF long",
2258 opcode: &opcodeArray[OP_VERIF],
2259 data: make([]byte, 1),
2261 expectedErr: scriptError(ErrInternal, ""),
2264 name: "OP_VERNOTIF",
2266 opcode: &opcodeArray[OP_VERNOTIF],
2272 name: "OP_VERNOTIF long",
2274 opcode: &opcodeArray[OP_VERNOTIF],
2275 data: make([]byte, 1),
2277 expectedErr: scriptError(ErrInternal, ""),
2282 opcode: &opcodeArray[OP_ELSE],
2288 name: "OP_ELSE long",
2290 opcode: &opcodeArray[OP_ELSE],
2291 data: make([]byte, 1),
2293 expectedErr: scriptError(ErrInternal, ""),
2298 opcode: &opcodeArray[OP_ENDIF],
2304 name: "OP_ENDIF long",
2306 opcode: &opcodeArray[OP_ENDIF],
2307 data: make([]byte, 1),
2309 expectedErr: scriptError(ErrInternal, ""),
2314 opcode: &opcodeArray[OP_VERIFY],
2320 name: "OP_VERIFY long",
2322 opcode: &opcodeArray[OP_VERIFY],
2323 data: make([]byte, 1),
2325 expectedErr: scriptError(ErrInternal, ""),
2330 opcode: &opcodeArray[OP_RETURN],
2336 name: "OP_RETURN long",
2338 opcode: &opcodeArray[OP_RETURN],
2339 data: make([]byte, 1),
2341 expectedErr: scriptError(ErrInternal, ""),
2344 name: "OP_TOALTSTACK",
2346 opcode: &opcodeArray[OP_TOALTSTACK],
2352 name: "OP_TOALTSTACK long",
2354 opcode: &opcodeArray[OP_TOALTSTACK],
2355 data: make([]byte, 1),
2357 expectedErr: scriptError(ErrInternal, ""),
2360 name: "OP_FROMALTSTACK",
2362 opcode: &opcodeArray[OP_FROMALTSTACK],
2368 name: "OP_FROMALTSTACK long",
2370 opcode: &opcodeArray[OP_FROMALTSTACK],
2371 data: make([]byte, 1),
2373 expectedErr: scriptError(ErrInternal, ""),
2378 opcode: &opcodeArray[OP_2DROP],
2384 name: "OP_2DROP long",
2386 opcode: &opcodeArray[OP_2DROP],
2387 data: make([]byte, 1),
2389 expectedErr: scriptError(ErrInternal, ""),
2394 opcode: &opcodeArray[OP_2DUP],
2400 name: "OP_2DUP long",
2402 opcode: &opcodeArray[OP_2DUP],
2403 data: make([]byte, 1),
2405 expectedErr: scriptError(ErrInternal, ""),
2410 opcode: &opcodeArray[OP_3DUP],
2416 name: "OP_3DUP long",
2418 opcode: &opcodeArray[OP_3DUP],
2419 data: make([]byte, 1),
2421 expectedErr: scriptError(ErrInternal, ""),
2426 opcode: &opcodeArray[OP_2OVER],
2432 name: "OP_2OVER long",
2434 opcode: &opcodeArray[OP_2OVER],
2435 data: make([]byte, 1),
2437 expectedErr: scriptError(ErrInternal, ""),
2442 opcode: &opcodeArray[OP_2ROT],
2448 name: "OP_2ROT long",
2450 opcode: &opcodeArray[OP_2ROT],
2451 data: make([]byte, 1),
2453 expectedErr: scriptError(ErrInternal, ""),
2458 opcode: &opcodeArray[OP_2SWAP],
2464 name: "OP_2SWAP long",
2466 opcode: &opcodeArray[OP_2SWAP],
2467 data: make([]byte, 1),
2469 expectedErr: scriptError(ErrInternal, ""),
2474 opcode: &opcodeArray[OP_IFDUP],
2480 name: "OP_IFDUP long",
2482 opcode: &opcodeArray[OP_IFDUP],
2483 data: make([]byte, 1),
2485 expectedErr: scriptError(ErrInternal, ""),
2490 opcode: &opcodeArray[OP_DEPTH],
2496 name: "OP_DEPTH long",
2498 opcode: &opcodeArray[OP_DEPTH],
2499 data: make([]byte, 1),
2501 expectedErr: scriptError(ErrInternal, ""),
2506 opcode: &opcodeArray[OP_DROP],
2512 name: "OP_DROP long",
2514 opcode: &opcodeArray[OP_DROP],
2515 data: make([]byte, 1),
2517 expectedErr: scriptError(ErrInternal, ""),
2522 opcode: &opcodeArray[OP_DUP],
2528 name: "OP_DUP long",
2530 opcode: &opcodeArray[OP_DUP],
2531 data: make([]byte, 1),
2533 expectedErr: scriptError(ErrInternal, ""),
2538 opcode: &opcodeArray[OP_NIP],
2544 name: "OP_NIP long",
2546 opcode: &opcodeArray[OP_NIP],
2547 data: make([]byte, 1),
2549 expectedErr: scriptError(ErrInternal, ""),
2554 opcode: &opcodeArray[OP_OVER],
2560 name: "OP_OVER long",
2562 opcode: &opcodeArray[OP_OVER],
2563 data: make([]byte, 1),
2565 expectedErr: scriptError(ErrInternal, ""),
2570 opcode: &opcodeArray[OP_PICK],
2576 name: "OP_PICK long",
2578 opcode: &opcodeArray[OP_PICK],
2579 data: make([]byte, 1),
2581 expectedErr: scriptError(ErrInternal, ""),
2586 opcode: &opcodeArray[OP_ROLL],
2592 name: "OP_ROLL long",
2594 opcode: &opcodeArray[OP_ROLL],
2595 data: make([]byte, 1),
2597 expectedErr: scriptError(ErrInternal, ""),
2602 opcode: &opcodeArray[OP_ROT],
2608 name: "OP_ROT long",
2610 opcode: &opcodeArray[OP_ROT],
2611 data: make([]byte, 1),
2613 expectedErr: scriptError(ErrInternal, ""),
2618 opcode: &opcodeArray[OP_SWAP],
2624 name: "OP_SWAP long",
2626 opcode: &opcodeArray[OP_SWAP],
2627 data: make([]byte, 1),
2629 expectedErr: scriptError(ErrInternal, ""),
2634 opcode: &opcodeArray[OP_TUCK],
2640 name: "OP_TUCK long",
2642 opcode: &opcodeArray[OP_TUCK],
2643 data: make([]byte, 1),
2645 expectedErr: scriptError(ErrInternal, ""),
2650 opcode: &opcodeArray[OP_CAT],
2656 name: "OP_CAT long",
2658 opcode: &opcodeArray[OP_CAT],
2659 data: make([]byte, 1),
2661 expectedErr: scriptError(ErrInternal, ""),
2666 opcode: &opcodeArray[OP_SUBSTR],
2672 name: "OP_SUBSTR long",
2674 opcode: &opcodeArray[OP_SUBSTR],
2675 data: make([]byte, 1),
2677 expectedErr: scriptError(ErrInternal, ""),
2682 opcode: &opcodeArray[OP_LEFT],
2688 name: "OP_LEFT long",
2690 opcode: &opcodeArray[OP_LEFT],
2691 data: make([]byte, 1),
2693 expectedErr: scriptError(ErrInternal, ""),
2698 opcode: &opcodeArray[OP_LEFT],
2704 name: "OP_LEFT long",
2706 opcode: &opcodeArray[OP_LEFT],
2707 data: make([]byte, 1),
2709 expectedErr: scriptError(ErrInternal, ""),
2714 opcode: &opcodeArray[OP_RIGHT],
2720 name: "OP_RIGHT long",
2722 opcode: &opcodeArray[OP_RIGHT],
2723 data: make([]byte, 1),
2725 expectedErr: scriptError(ErrInternal, ""),
2730 opcode: &opcodeArray[OP_SIZE],
2736 name: "OP_SIZE long",
2738 opcode: &opcodeArray[OP_SIZE],
2739 data: make([]byte, 1),
2741 expectedErr: scriptError(ErrInternal, ""),
2746 opcode: &opcodeArray[OP_INVERT],
2752 name: "OP_INVERT long",
2754 opcode: &opcodeArray[OP_INVERT],
2755 data: make([]byte, 1),
2757 expectedErr: scriptError(ErrInternal, ""),
2762 opcode: &opcodeArray[OP_AND],
2768 name: "OP_AND long",
2770 opcode: &opcodeArray[OP_AND],
2771 data: make([]byte, 1),
2773 expectedErr: scriptError(ErrInternal, ""),
2778 opcode: &opcodeArray[OP_OR],
2786 opcode: &opcodeArray[OP_OR],
2787 data: make([]byte, 1),
2789 expectedErr: scriptError(ErrInternal, ""),
2794 opcode: &opcodeArray[OP_XOR],
2800 name: "OP_XOR long",
2802 opcode: &opcodeArray[OP_XOR],
2803 data: make([]byte, 1),
2805 expectedErr: scriptError(ErrInternal, ""),
2810 opcode: &opcodeArray[OP_EQUAL],
2816 name: "OP_EQUAL long",
2818 opcode: &opcodeArray[OP_EQUAL],
2819 data: make([]byte, 1),
2821 expectedErr: scriptError(ErrInternal, ""),
2824 name: "OP_EQUALVERIFY",
2826 opcode: &opcodeArray[OP_EQUALVERIFY],
2832 name: "OP_EQUALVERIFY long",
2834 opcode: &opcodeArray[OP_EQUALVERIFY],
2835 data: make([]byte, 1),
2837 expectedErr: scriptError(ErrInternal, ""),
2840 name: "OP_RESERVED1",
2842 opcode: &opcodeArray[OP_RESERVED1],
2848 name: "OP_RESERVED1 long",
2850 opcode: &opcodeArray[OP_RESERVED1],
2851 data: make([]byte, 1),
2853 expectedErr: scriptError(ErrInternal, ""),
2856 name: "OP_RESERVED2",
2858 opcode: &opcodeArray[OP_RESERVED2],
2864 name: "OP_RESERVED2 long",
2866 opcode: &opcodeArray[OP_RESERVED2],
2867 data: make([]byte, 1),
2869 expectedErr: scriptError(ErrInternal, ""),
2874 opcode: &opcodeArray[OP_1ADD],
2880 name: "OP_1ADD long",
2882 opcode: &opcodeArray[OP_1ADD],
2883 data: make([]byte, 1),
2885 expectedErr: scriptError(ErrInternal, ""),
2890 opcode: &opcodeArray[OP_1SUB],
2896 name: "OP_1SUB long",
2898 opcode: &opcodeArray[OP_1SUB],
2899 data: make([]byte, 1),
2901 expectedErr: scriptError(ErrInternal, ""),
2906 opcode: &opcodeArray[OP_2MUL],
2912 name: "OP_2MUL long",
2914 opcode: &opcodeArray[OP_2MUL],
2915 data: make([]byte, 1),
2917 expectedErr: scriptError(ErrInternal, ""),
2922 opcode: &opcodeArray[OP_2DIV],
2928 name: "OP_2DIV long",
2930 opcode: &opcodeArray[OP_2DIV],
2931 data: make([]byte, 1),
2933 expectedErr: scriptError(ErrInternal, ""),
2938 opcode: &opcodeArray[OP_NEGATE],
2944 name: "OP_NEGATE long",
2946 opcode: &opcodeArray[OP_NEGATE],
2947 data: make([]byte, 1),
2949 expectedErr: scriptError(ErrInternal, ""),
2954 opcode: &opcodeArray[OP_ABS],
2960 name: "OP_ABS long",
2962 opcode: &opcodeArray[OP_ABS],
2963 data: make([]byte, 1),
2965 expectedErr: scriptError(ErrInternal, ""),
2970 opcode: &opcodeArray[OP_NOT],
2976 name: "OP_NOT long",
2978 opcode: &opcodeArray[OP_NOT],
2979 data: make([]byte, 1),
2981 expectedErr: scriptError(ErrInternal, ""),
2984 name: "OP_0NOTEQUAL",
2986 opcode: &opcodeArray[OP_0NOTEQUAL],
2992 name: "OP_0NOTEQUAL long",
2994 opcode: &opcodeArray[OP_0NOTEQUAL],
2995 data: make([]byte, 1),
2997 expectedErr: scriptError(ErrInternal, ""),
3002 opcode: &opcodeArray[OP_ADD],
3008 name: "OP_ADD long",
3010 opcode: &opcodeArray[OP_ADD],
3011 data: make([]byte, 1),
3013 expectedErr: scriptError(ErrInternal, ""),
3018 opcode: &opcodeArray[OP_SUB],
3024 name: "OP_SUB long",
3026 opcode: &opcodeArray[OP_SUB],
3027 data: make([]byte, 1),
3029 expectedErr: scriptError(ErrInternal, ""),
3034 opcode: &opcodeArray[OP_MUL],
3040 name: "OP_MUL long",
3042 opcode: &opcodeArray[OP_MUL],
3043 data: make([]byte, 1),
3045 expectedErr: scriptError(ErrInternal, ""),
3050 opcode: &opcodeArray[OP_DIV],
3056 name: "OP_DIV long",
3058 opcode: &opcodeArray[OP_DIV],
3059 data: make([]byte, 1),
3061 expectedErr: scriptError(ErrInternal, ""),
3066 opcode: &opcodeArray[OP_MOD],
3072 name: "OP_MOD long",
3074 opcode: &opcodeArray[OP_MOD],
3075 data: make([]byte, 1),
3077 expectedErr: scriptError(ErrInternal, ""),
3082 opcode: &opcodeArray[OP_LSHIFT],
3088 name: "OP_LSHIFT long",
3090 opcode: &opcodeArray[OP_LSHIFT],
3091 data: make([]byte, 1),
3093 expectedErr: scriptError(ErrInternal, ""),
3098 opcode: &opcodeArray[OP_RSHIFT],
3104 name: "OP_RSHIFT long",
3106 opcode: &opcodeArray[OP_RSHIFT],
3107 data: make([]byte, 1),
3109 expectedErr: scriptError(ErrInternal, ""),
3114 opcode: &opcodeArray[OP_BOOLAND],
3120 name: "OP_BOOLAND long",
3122 opcode: &opcodeArray[OP_BOOLAND],
3123 data: make([]byte, 1),
3125 expectedErr: scriptError(ErrInternal, ""),
3130 opcode: &opcodeArray[OP_BOOLOR],
3136 name: "OP_BOOLOR long",
3138 opcode: &opcodeArray[OP_BOOLOR],
3139 data: make([]byte, 1),
3141 expectedErr: scriptError(ErrInternal, ""),
3144 name: "OP_NUMEQUAL",
3146 opcode: &opcodeArray[OP_NUMEQUAL],
3152 name: "OP_NUMEQUAL long",
3154 opcode: &opcodeArray[OP_NUMEQUAL],
3155 data: make([]byte, 1),
3157 expectedErr: scriptError(ErrInternal, ""),
3160 name: "OP_NUMEQUALVERIFY",
3162 opcode: &opcodeArray[OP_NUMEQUALVERIFY],
3168 name: "OP_NUMEQUALVERIFY long",
3170 opcode: &opcodeArray[OP_NUMEQUALVERIFY],
3171 data: make([]byte, 1),
3173 expectedErr: scriptError(ErrInternal, ""),
3176 name: "OP_NUMNOTEQUAL",
3178 opcode: &opcodeArray[OP_NUMNOTEQUAL],
3184 name: "OP_NUMNOTEQUAL long",
3186 opcode: &opcodeArray[OP_NUMNOTEQUAL],
3187 data: make([]byte, 1),
3189 expectedErr: scriptError(ErrInternal, ""),
3192 name: "OP_LESSTHAN",
3194 opcode: &opcodeArray[OP_LESSTHAN],
3200 name: "OP_LESSTHAN long",
3202 opcode: &opcodeArray[OP_LESSTHAN],
3203 data: make([]byte, 1),
3205 expectedErr: scriptError(ErrInternal, ""),
3208 name: "OP_GREATERTHAN",
3210 opcode: &opcodeArray[OP_GREATERTHAN],
3216 name: "OP_GREATERTHAN long",
3218 opcode: &opcodeArray[OP_GREATERTHAN],
3219 data: make([]byte, 1),
3221 expectedErr: scriptError(ErrInternal, ""),
3224 name: "OP_LESSTHANOREQUAL",
3226 opcode: &opcodeArray[OP_LESSTHANOREQUAL],
3232 name: "OP_LESSTHANOREQUAL long",
3234 opcode: &opcodeArray[OP_LESSTHANOREQUAL],
3235 data: make([]byte, 1),
3237 expectedErr: scriptError(ErrInternal, ""),
3240 name: "OP_GREATERTHANOREQUAL",
3242 opcode: &opcodeArray[OP_GREATERTHANOREQUAL],
3248 name: "OP_GREATERTHANOREQUAL long",
3250 opcode: &opcodeArray[OP_GREATERTHANOREQUAL],
3251 data: make([]byte, 1),
3253 expectedErr: scriptError(ErrInternal, ""),
3258 opcode: &opcodeArray[OP_MIN],
3264 name: "OP_MIN long",
3266 opcode: &opcodeArray[OP_MIN],
3267 data: make([]byte, 1),
3269 expectedErr: scriptError(ErrInternal, ""),
3274 opcode: &opcodeArray[OP_MAX],
3280 name: "OP_MAX long",
3282 opcode: &opcodeArray[OP_MAX],
3283 data: make([]byte, 1),
3285 expectedErr: scriptError(ErrInternal, ""),
3290 opcode: &opcodeArray[OP_WITHIN],
3296 name: "OP_WITHIN long",
3298 opcode: &opcodeArray[OP_WITHIN],
3299 data: make([]byte, 1),
3301 expectedErr: scriptError(ErrInternal, ""),
3304 name: "OP_RIPEMD160",
3306 opcode: &opcodeArray[OP_RIPEMD160],
3312 name: "OP_RIPEMD160 long",
3314 opcode: &opcodeArray[OP_RIPEMD160],
3315 data: make([]byte, 1),
3317 expectedErr: scriptError(ErrInternal, ""),
3322 opcode: &opcodeArray[OP_SHA1],
3328 name: "OP_SHA1 long",
3330 opcode: &opcodeArray[OP_SHA1],
3331 data: make([]byte, 1),
3333 expectedErr: scriptError(ErrInternal, ""),
3338 opcode: &opcodeArray[OP_SHA256],
3344 name: "OP_SHA256 long",
3346 opcode: &opcodeArray[OP_SHA256],
3347 data: make([]byte, 1),
3349 expectedErr: scriptError(ErrInternal, ""),
3354 opcode: &opcodeArray[OP_HASH160],
3360 name: "OP_HASH160 long",
3362 opcode: &opcodeArray[OP_HASH160],
3363 data: make([]byte, 1),
3365 expectedErr: scriptError(ErrInternal, ""),
3370 opcode: &opcodeArray[OP_HASH256],
3376 name: "OP_HASH256 long",
3378 opcode: &opcodeArray[OP_HASH256],
3379 data: make([]byte, 1),
3381 expectedErr: scriptError(ErrInternal, ""),
3384 name: "OP_CODESAPERATOR",
3386 opcode: &opcodeArray[OP_CODESEPARATOR],
3392 name: "OP_CODESEPARATOR long",
3394 opcode: &opcodeArray[OP_CODESEPARATOR],
3395 data: make([]byte, 1),
3397 expectedErr: scriptError(ErrInternal, ""),
3400 name: "OP_CHECKSIG",
3402 opcode: &opcodeArray[OP_CHECKSIG],
3408 name: "OP_CHECKSIG long",
3410 opcode: &opcodeArray[OP_CHECKSIG],
3411 data: make([]byte, 1),
3413 expectedErr: scriptError(ErrInternal, ""),
3416 name: "OP_CHECKSIGVERIFY",
3418 opcode: &opcodeArray[OP_CHECKSIGVERIFY],
3424 name: "OP_CHECKSIGVERIFY long",
3426 opcode: &opcodeArray[OP_CHECKSIGVERIFY],
3427 data: make([]byte, 1),
3429 expectedErr: scriptError(ErrInternal, ""),
3432 name: "OP_CHECKMULTISIG",
3434 opcode: &opcodeArray[OP_CHECKMULTISIG],
3440 name: "OP_CHECKMULTISIG long",
3442 opcode: &opcodeArray[OP_CHECKMULTISIG],
3443 data: make([]byte, 1),
3445 expectedErr: scriptError(ErrInternal, ""),
3448 name: "OP_CHECKMULTISIGVERIFY",
3450 opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY],
3456 name: "OP_CHECKMULTISIGVERIFY long",
3458 opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY],
3459 data: make([]byte, 1),
3461 expectedErr: scriptError(ErrInternal, ""),
3466 opcode: &opcodeArray[OP_NOP1],
3472 name: "OP_NOP1 long",
3474 opcode: &opcodeArray[OP_NOP1],
3475 data: make([]byte, 1),
3477 expectedErr: scriptError(ErrInternal, ""),
3482 opcode: &opcodeArray[OP_NOP2],
3488 name: "OP_NOP2 long",
3490 opcode: &opcodeArray[OP_NOP2],
3491 data: make([]byte, 1),
3493 expectedErr: scriptError(ErrInternal, ""),
3498 opcode: &opcodeArray[OP_NOP3],
3504 name: "OP_NOP3 long",
3506 opcode: &opcodeArray[OP_NOP3],
3507 data: make([]byte, 1),
3509 expectedErr: scriptError(ErrInternal, ""),
3514 opcode: &opcodeArray[OP_NOP4],
3520 name: "OP_NOP4 long",
3522 opcode: &opcodeArray[OP_NOP4],
3523 data: make([]byte, 1),
3525 expectedErr: scriptError(ErrInternal, ""),
3530 opcode: &opcodeArray[OP_NOP5],
3536 name: "OP_NOP5 long",
3538 opcode: &opcodeArray[OP_NOP5],
3539 data: make([]byte, 1),
3541 expectedErr: scriptError(ErrInternal, ""),
3546 opcode: &opcodeArray[OP_NOP6],
3552 name: "OP_NOP6 long",
3554 opcode: &opcodeArray[OP_NOP6],
3555 data: make([]byte, 1),
3557 expectedErr: scriptError(ErrInternal, ""),
3562 opcode: &opcodeArray[OP_NOP7],
3568 name: "OP_NOP7 long",
3570 opcode: &opcodeArray[OP_NOP7],
3571 data: make([]byte, 1),
3573 expectedErr: scriptError(ErrInternal, ""),
3578 opcode: &opcodeArray[OP_NOP8],
3584 name: "OP_NOP8 long",
3586 opcode: &opcodeArray[OP_NOP8],
3587 data: make([]byte, 1),
3589 expectedErr: scriptError(ErrInternal, ""),
3594 opcode: &opcodeArray[OP_NOP9],
3600 name: "OP_NOP9 long",
3602 opcode: &opcodeArray[OP_NOP9],
3603 data: make([]byte, 1),
3605 expectedErr: scriptError(ErrInternal, ""),
3610 opcode: &opcodeArray[OP_NOP10],
3616 name: "OP_NOP10 long",
3618 opcode: &opcodeArray[OP_NOP10],
3619 data: make([]byte, 1),
3621 expectedErr: scriptError(ErrInternal, ""),
3624 name: "OP_PUBKEYHASH",
3626 opcode: &opcodeArray[OP_PUBKEYHASH],
3632 name: "OP_PUBKEYHASH long",
3634 opcode: &opcodeArray[OP_PUBKEYHASH],
3635 data: make([]byte, 1),
3637 expectedErr: scriptError(ErrInternal, ""),
3642 opcode: &opcodeArray[OP_PUBKEY],
3648 name: "OP_PUBKEY long",
3650 opcode: &opcodeArray[OP_PUBKEY],
3651 data: make([]byte, 1),
3653 expectedErr: scriptError(ErrInternal, ""),
3656 name: "OP_INVALIDOPCODE",
3658 opcode: &opcodeArray[OP_INVALIDOPCODE],
3664 name: "OP_INVALIDOPCODE long",
3666 opcode: &opcodeArray[OP_INVALIDOPCODE],
3667 data: make([]byte, 1),
3669 expectedErr: scriptError(ErrInternal, ""),
3673 for _, test := range tests {
3674 _, err := test.pop.bytes()
3675 if e := tstCheckScriptError(err, test.expectedErr); e != nil {
3676 t.Errorf("Parsed opcode test '%s': %v", test.name, e)
3682 // TestPushedData ensured the PushedData function extracts the expected data out
3683 // of various scripts.
3684 func TestPushedData(t *testing.T) {
3687 var tests = []struct {
3693 "0 IF 0 ELSE 2 ENDIF",
3698 "16777216 10000000",
3700 {0x00, 0x00, 0x00, 0x01}, // 16777216
3701 {0x80, 0x96, 0x98, 0x00}, // 10000000
3706 "DUP HASH160 '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem' EQUALVERIFY CHECKSIG",
3708 // 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem
3710 0x31, 0x37, 0x56, 0x5a, 0x4e, 0x58, 0x31, 0x53, 0x4e, 0x35,
3711 0x4e, 0x74, 0x4b, 0x61, 0x38, 0x55, 0x51, 0x46, 0x78, 0x77,
3712 0x51, 0x62, 0x46, 0x65, 0x46, 0x63, 0x33, 0x69, 0x71, 0x52,
3713 0x59, 0x68, 0x65, 0x6d,
3719 "PUSHDATA4 1000 EQUAL",
3725 for i, test := range tests {
3726 script := mustParseShortForm(test.script)
3727 data, err := PushedData(script)
3728 if test.valid && err != nil {
3729 t.Errorf("TestPushedData failed test #%d: %v\n", i, err)
3731 } else if !test.valid && err == nil {
3732 t.Errorf("TestPushedData failed test #%d: test should "+
3736 if !reflect.DeepEqual(data, test.out) {
3737 t.Errorf("TestPushedData failed test #%d: want: %x "+
3738 "got: %x\n", i, test.out, data)
3743 // TestHasCanonicalPush ensures the canonicalPush function works as expected.
3744 func TestHasCanonicalPush(t *testing.T) {
3747 for i := 0; i < 65535; i++ {
3748 script, err := NewScriptBuilder().AddInt64(int64(i)).Script()
3750 t.Errorf("Script: test #%d unexpected error: %v\n", i,
3754 if result := IsPushOnlyScript(script); !result {
3755 t.Errorf("IsPushOnlyScript: test #%d failed: %x\n", i,
3759 pops, err := parseScript(script)
3761 t.Errorf("parseScript: #%d failed: %v", i, err)
3764 for _, pop := range pops {
3765 if result := canonicalPush(pop); !result {
3766 t.Errorf("canonicalPush: test #%d failed: %x\n",
3772 for i := 0; i <= MaxScriptElementSize; i++ {
3773 builder := NewScriptBuilder()
3774 builder.AddData(bytes.Repeat([]byte{0x49}, i))
3775 script, err := builder.Script()
3777 t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err)
3780 if result := IsPushOnlyScript(script); !result {
3781 t.Errorf("StandardPushesTests IsPushOnlyScript test #%d failed: %x\n", i, script)
3784 pops, err := parseScript(script)
3786 t.Errorf("StandardPushesTests #%d failed to TstParseScript: %v", i, err)
3789 for _, pop := range pops {
3790 if result := canonicalPush(pop); !result {
3791 t.Errorf("StandardPushesTests TstHasCanonicalPushes test #%d failed: %x\n", i, script)
3798 // TestGetPreciseSigOps ensures the more precise signature operation counting
3799 // mechanism which includes signatures in P2SH scripts works as expected.
3800 func TestGetPreciseSigOps(t *testing.T) {
3809 name: "scriptSig doesn't parse",
3810 scriptSig: mustParseShortForm("PUSHDATA1 0x02"),
3813 name: "scriptSig isn't push only",
3814 scriptSig: mustParseShortForm("1 DUP"),
3818 name: "scriptSig length 0",
3823 name: "No script at the end",
3824 // No script at end but still push only.
3825 scriptSig: mustParseShortForm("1 1"),
3829 name: "pushed script doesn't parse",
3830 scriptSig: mustParseShortForm("DATA_2 PUSHDATA1 0x02"),
3834 // The signature in the p2sh script is nonsensical for the tests since
3835 // this script will never be executed. What matters is that it matches
3836 // the right pattern.
3837 pkScript := mustParseShortForm("HASH160 DATA_20 0x433ec2ac1ffa1b7b7d0" +
3838 "27f564529c57197f9ae88 EQUAL")
3839 for _, test := range tests {
3840 count := GetPreciseSigOpCount(test.scriptSig, pkScript, true)
3841 if count != test.nSigOps {
3842 t.Errorf("%s: expected count of %d, got %d", test.name,
3843 test.nSigOps, count)
3849 // TestGetWitnessSigOpCount tests that the sig op counting for p2wkh, p2wsh,
3850 // nested p2sh, and invalid variants are counted properly.
3851 func TestGetWitnessSigOpCount(t *testing.T) {
3858 witness wire.TxWitness
3862 // A regualr p2wkh witness program. The output being spent
3863 // should only have a single sig-op counted.
3866 pkScript: mustParseShortForm("OP_0 DATA_20 " +
3867 "0x365ab47888e150ff46f8d51bce36dcd680f1283f"),
3868 witness: wire.TxWitness{
3869 hexToBytes("3045022100ee9fe8f9487afa977" +
3870 "6647ebcf0883ce0cd37454d7ce19889d34ba2c9" +
3871 "9ce5a9f402200341cb469d0efd3955acb9e46" +
3872 "f568d7e2cc10f9084aaff94ced6dc50a59134ad01"),
3873 hexToBytes("03f0000d0639a22bfaf217e4c9428" +
3874 "9c2b0cc7fa1036f7fd5d9f61a9d6ec153100e"),
3878 // A p2wkh witness program nested within a p2sh output script.
3879 // The pattern should be recognized properly and attribute only
3882 name: "nested p2sh",
3883 sigScript: hexToBytes("160014ad0ffa2e387f07" +
3884 "e7ead14dc56d5a97dbd6ff5a23"),
3885 pkScript: mustParseShortForm("HASH160 DATA_20 " +
3886 "0xb3a84b564602a9d68b4c9f19c2ea61458ff7826c EQUAL"),
3887 witness: wire.TxWitness{
3888 hexToBytes("3045022100cb1c2ac1ff1d57d" +
3889 "db98f7bdead905f8bf5bcc8641b029ce8eef25" +
3890 "c75a9e22a4702203be621b5c86b771288706be5" +
3891 "a7eee1db4fceabf9afb7583c1cc6ee3f8297b21201"),
3892 hexToBytes("03f0000d0639a22bfaf217e4c9" +
3893 "4289c2b0cc7fa1036f7fd5d9f61a9d6ec153100e"),
3897 // A p2sh script that spends a 2-of-2 multi-sig output.
3899 name: "p2wsh multi-sig spend",
3901 pkScript: hexToBytes("0020e112b88a0cd87ba387f" +
3902 "449d443ee2596eb353beb1f0351ab2cba8909d875db23"),
3903 witness: wire.TxWitness{
3904 hexToBytes("522103b05faca7ceda92b493" +
3905 "3f7acdf874a93de0dc7edc461832031cd69cbb1d1e" +
3906 "6fae2102e39092e031c1621c902e3704424e8d8" +
3907 "3ca481d4d4eeae1b7970f51c78231207e52ae"),
3910 // A p2wsh witness program. However, the witness script fails
3911 // to parse after the valid portion of the script. As a result,
3912 // the valid portion of the script should still be counted.
3914 name: "witness script doesn't parse",
3916 pkScript: hexToBytes("0020e112b88a0cd87ba387f44" +
3917 "9d443ee2596eb353beb1f0351ab2cba8909d875db23"),
3918 witness: wire.TxWitness{
3919 mustParseShortForm("DUP HASH160 " +
3920 "'17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem'" +
3921 " EQUALVERIFY CHECKSIG DATA_20 0x91"),
3926 for _, test := range tests {
3927 count := GetWitnessSigOpCount(test.sigScript, test.pkScript,
3929 if count != test.numSigOps {
3930 t.Errorf("%s: expected count of %d, got %d", test.name,
3931 test.numSigOps, count)
3937 // TestRemoveOpcodes ensures that removing opcodes from scripts behaves as
3939 func TestRemoveOpcodes(t *testing.T) {
3950 // Nothing to remove.
3951 name: "nothing to remove",
3953 remove: OP_CODESEPARATOR,
3957 // Test basic opcode removal.
3958 name: "codeseparator 1",
3959 before: "NOP CODESEPARATOR TRUE",
3960 remove: OP_CODESEPARATOR,
3964 // The opcode in question is actually part of the data
3965 // in a previous opcode.
3966 name: "codeseparator by coincidence",
3967 before: "NOP DATA_1 CODESEPARATOR TRUE",
3968 remove: OP_CODESEPARATOR,
3969 after: "NOP DATA_1 CODESEPARATOR TRUE",
3972 name: "invalid opcode",
3974 remove: OP_CODESEPARATOR,
3978 name: "invalid length (insruction)",
3979 before: "PUSHDATA1",
3980 remove: OP_CODESEPARATOR,
3981 err: scriptError(ErrMalformedPush, ""),
3984 name: "invalid length (data)",
3985 before: "PUSHDATA1 0xff 0xfe",
3986 remove: OP_CODESEPARATOR,
3987 err: scriptError(ErrMalformedPush, ""),
3991 // tstRemoveOpcode is a convenience function to parse the provided
3992 // raw script, remove the passed opcode, then unparse the result back
3993 // into a raw script.
3994 tstRemoveOpcode := func(script []byte, opcode byte) ([]byte, error) {
3995 pops, err := parseScript(script)
3999 pops = removeOpcode(pops, opcode)
4000 return unparseScript(pops)
4003 for _, test := range tests {
4004 before := mustParseShortForm(test.before)
4005 after := mustParseShortForm(test.after)
4006 result, err := tstRemoveOpcode(before, test.remove)
4007 if e := tstCheckScriptError(err, test.err); e != nil {
4008 t.Errorf("%s: %v", test.name, e)
4012 if !bytes.Equal(after, result) {
4013 t.Errorf("%s: value does not equal expected: exp: %q"+
4014 " got: %q", test.name, after, result)
4019 // TestRemoveOpcodeByData ensures that removing data carrying opcodes based on
4020 // the data they contain works as expected.
4021 func TestRemoveOpcodeByData(t *testing.T) {
4032 name: "nothing to do",
4033 before: []byte{OP_NOP},
4034 remove: []byte{1, 2, 3, 4},
4035 after: []byte{OP_NOP},
4038 name: "simple case",
4039 before: []byte{OP_DATA_4, 1, 2, 3, 4},
4040 remove: []byte{1, 2, 3, 4},
4044 name: "simple case (miss)",
4045 before: []byte{OP_DATA_4, 1, 2, 3, 4},
4046 remove: []byte{1, 2, 3, 5},
4047 after: []byte{OP_DATA_4, 1, 2, 3, 4},
4050 // padded to keep it canonical.
4051 name: "simple case (pushdata1)",
4052 before: append(append([]byte{OP_PUSHDATA1, 76},
4053 bytes.Repeat([]byte{0}, 72)...),
4054 []byte{1, 2, 3, 4}...),
4055 remove: []byte{1, 2, 3, 4},
4059 name: "simple case (pushdata1 miss)",
4060 before: append(append([]byte{OP_PUSHDATA1, 76},
4061 bytes.Repeat([]byte{0}, 72)...),
4062 []byte{1, 2, 3, 4}...),
4063 remove: []byte{1, 2, 3, 5},
4064 after: append(append([]byte{OP_PUSHDATA1, 76},
4065 bytes.Repeat([]byte{0}, 72)...),
4066 []byte{1, 2, 3, 4}...),
4069 name: "simple case (pushdata1 miss noncanonical)",
4070 before: []byte{OP_PUSHDATA1, 4, 1, 2, 3, 4},
4071 remove: []byte{1, 2, 3, 4},
4072 after: []byte{OP_PUSHDATA1, 4, 1, 2, 3, 4},
4075 name: "simple case (pushdata2)",
4076 before: append(append([]byte{OP_PUSHDATA2, 0, 1},
4077 bytes.Repeat([]byte{0}, 252)...),
4078 []byte{1, 2, 3, 4}...),
4079 remove: []byte{1, 2, 3, 4},
4083 name: "simple case (pushdata2 miss)",
4084 before: append(append([]byte{OP_PUSHDATA2, 0, 1},
4085 bytes.Repeat([]byte{0}, 252)...),
4086 []byte{1, 2, 3, 4}...),
4087 remove: []byte{1, 2, 3, 4, 5},
4088 after: append(append([]byte{OP_PUSHDATA2, 0, 1},
4089 bytes.Repeat([]byte{0}, 252)...),
4090 []byte{1, 2, 3, 4}...),
4093 name: "simple case (pushdata2 miss noncanonical)",
4094 before: []byte{OP_PUSHDATA2, 4, 0, 1, 2, 3, 4},
4095 remove: []byte{1, 2, 3, 4},
4096 after: []byte{OP_PUSHDATA2, 4, 0, 1, 2, 3, 4},
4099 // This is padded to make the push canonical.
4100 name: "simple case (pushdata4)",
4101 before: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0},
4102 bytes.Repeat([]byte{0}, 65532)...),
4103 []byte{1, 2, 3, 4}...),
4104 remove: []byte{1, 2, 3, 4},
4108 name: "simple case (pushdata4 miss noncanonical)",
4109 before: []byte{OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4},
4110 remove: []byte{1, 2, 3, 4},
4111 after: []byte{OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4},
4114 // This is padded to make the push canonical.
4115 name: "simple case (pushdata4 miss)",
4116 before: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0},
4117 bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...),
4118 remove: []byte{1, 2, 3, 4, 5},
4119 after: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0},
4120 bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...),
4123 name: "invalid opcode ",
4124 before: []byte{OP_UNKNOWN187},
4125 remove: []byte{1, 2, 3, 4},
4126 after: []byte{OP_UNKNOWN187},
4129 name: "invalid length (instruction)",
4130 before: []byte{OP_PUSHDATA1},
4131 remove: []byte{1, 2, 3, 4},
4132 err: scriptError(ErrMalformedPush, ""),
4135 name: "invalid length (data)",
4136 before: []byte{OP_PUSHDATA1, 255, 254},
4137 remove: []byte{1, 2, 3, 4},
4138 err: scriptError(ErrMalformedPush, ""),
4142 // tstRemoveOpcodeByData is a convenience function to parse the provided
4143 // raw script, remove the passed data, then unparse the result back
4144 // into a raw script.
4145 tstRemoveOpcodeByData := func(script []byte, data []byte) ([]byte, error) {
4146 pops, err := parseScript(script)
4150 pops = removeOpcodeByData(pops, data)
4151 return unparseScript(pops)
4154 for _, test := range tests {
4155 result, err := tstRemoveOpcodeByData(test.before, test.remove)
4156 if e := tstCheckScriptError(err, test.err); e != nil {
4157 t.Errorf("%s: %v", test.name, e)
4161 if !bytes.Equal(test.after, result) {
4162 t.Errorf("%s: value does not equal expected: exp: %q"+
4163 " got: %q", test.name, test.after, result)
4168 // TestIsPayToScriptHash ensures the IsPayToScriptHash function returns the
4169 // expected results for all the scripts in scriptClassTests.
4170 func TestIsPayToScriptHash(t *testing.T) {
4173 for _, test := range scriptClassTests {
4174 script := mustParseShortForm(test.script)
4175 shouldBe := (test.class == ScriptHashTy)
4176 p2sh := IsPayToScriptHash(script)
4177 if p2sh != shouldBe {
4178 t.Errorf("%s: expected p2sh %v, got %v", test.name,
4184 // TestIsPayToWitnessScriptHash ensures the IsPayToWitnessScriptHash function
4185 // returns the expected results for all the scripts in scriptClassTests.
4186 func TestIsPayToWitnessScriptHash(t *testing.T) {
4189 for _, test := range scriptClassTests {
4190 script := mustParseShortForm(test.script)
4191 shouldBe := (test.class == WitnessV0ScriptHashTy)
4192 p2wsh := IsPayToWitnessScriptHash(script)
4193 if p2wsh != shouldBe {
4194 t.Errorf("%s: expected p2wsh %v, got %v", test.name,
4200 // TestIsPayToWitnessPubKeyHash ensures the IsPayToWitnessPubKeyHash function
4201 // returns the expected results for all the scripts in scriptClassTests.
4202 func TestIsPayToWitnessPubKeyHash(t *testing.T) {
4205 for _, test := range scriptClassTests {
4206 script := mustParseShortForm(test.script)
4207 shouldBe := (test.class == WitnessV0PubKeyHashTy)
4208 p2wkh := IsPayToWitnessPubKeyHash(script)
4209 if p2wkh != shouldBe {
4210 t.Errorf("%s: expected p2wkh %v, got %v", test.name,
4216 // TestHasCanonicalPushes ensures the canonicalPush function properly determines
4217 // what is considered a canonical push for the purposes of removeOpcodeByData.
4218 func TestHasCanonicalPushes(t *testing.T) {
4227 name: "does not parse",
4228 script: "0x046708afdb0fe5548271967f1a67130b7105cd6a82" +
4229 "8e03909a67962e0ea1f61d",
4233 name: "non-canonical push",
4234 script: "PUSHDATA1 0x04 0x01020304",
4239 for i, test := range tests {
4240 script := mustParseShortForm(test.script)
4241 pops, err := parseScript(script)
4244 t.Errorf("TstParseScript #%d failed: %v", i, err)
4248 for _, pop := range pops {
4249 if canonicalPush(pop) != test.expected {
4250 t.Errorf("canonicalPush: #%d (%s) wrong result"+
4251 "\ngot: %v\nwant: %v", i, test.name,
4252 true, test.expected)
4259 // TestIsPushOnlyScript ensures the IsPushOnlyScript function returns the
4260 // expected results.
4261 func TestIsPushOnlyScript(t *testing.T) {
4269 name: "does not parse",
4270 script: mustParseShortForm("0x046708afdb0fe5548271967f1a67130" +
4271 "b7105cd6a828e03909a67962e0ea1f61d"),
4275 if IsPushOnlyScript(test.script) != test.expected {
4276 t.Errorf("IsPushOnlyScript (%s) wrong result\ngot: %v\nwant: "+
4277 "%v", test.name, true, test.expected)
4281 // TestIsUnspendable ensures the IsUnspendable function returns the expected
4283 func TestIsUnspendable(t *testing.T) {
4293 pkScript: []byte{0x6a, 0x04, 0x74, 0x65, 0x73, 0x74},
4298 pkScript: []byte{0x76, 0xa9, 0x14, 0x29, 0x95, 0xa0,
4299 0xfe, 0x68, 0x43, 0xfa, 0x9b, 0x95, 0x45,
4300 0x97, 0xf0, 0xdc, 0xa7, 0xa4, 0x4d, 0xf6,
4301 0xfa, 0x0b, 0x5c, 0x88, 0xac},
4306 for i, test := range tests {
4307 res := IsUnspendable(test.pkScript)
4308 if res != test.expected {
4309 t.Errorf("TestIsUnspendable #%d failed: got %v want %v",
4310 i, res, test.expected)