Skip to content

Commit e9b3214

Browse files
0xBEEFCAF3ajtowns
authored andcommitted
Add DISCOURAGE_OP_CAT unit tests
1 parent a118743 commit e9b3214

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

src/test/data/script_tests.json

+84-8
Original file line numberDiff line numberDiff line change
@@ -2526,8 +2526,7 @@
25262526
["0", "CHECKSEQUENCEVERIFY", "CHECKSEQUENCEVERIFY", "UNSATISFIED_LOCKTIME", "CSV fails if stack top bit 1 << 31 is set and the tx version < 2"],
25272527
["0x050000000001", "CHECKSEQUENCEVERIFY", "CHECKSEQUENCEVERIFY", "UNSATISFIED_LOCKTIME",
25282528
"CSV fails if stack top bit 1 << 31 is not set, and tx version < 2"],
2529-
2530-
["OP_CAT tests"],
2529+
["OP_CAT (and related) script verify flag tests"],
25312530
[
25322531
[
25332532
"#SCRIPT# CAT",
@@ -2538,8 +2537,85 @@
25382537
"0x51 0x20 #TAPROOTOUTPUT#",
25392538
"P2SH,WITNESS,TAPROOT",
25402539
"OK",
2541-
"TAPSCRIPT (CAT) Test of OP_CAT flag by calling CAT on an empty stack. This does not error because no TAPSCRIPT_OP_CAT flag is set so CAT is OP_SUCCESS"
2540+
"TAPSCRIPT CAT test of OP_CAT flag by calling CAT on an empty stack. This does not error because no OP_CAT verify flag is set so CAT is OP_SUCCESS"
2541+
],
2542+
[
2543+
[
2544+
"aa",
2545+
"bb",
2546+
"#SCRIPT# CAT",
2547+
"#CONTROLBLOCK#",
2548+
0.00000001
2549+
],
2550+
"",
2551+
"0x51 0x20 #TAPROOTOUTPUT#",
2552+
"P2SH,WITNESS,TAPROOT,DISCOURAGE_OP_CAT,OP_CAT",
2553+
"DISCOURAGE_OP_CAT",
2554+
"TAPSCRIPT test of DISCOURAGE_OP_CAT flag by calling CAT on two elements. OP_CAT verify flag is set however OP_CAT is not executed due to DISCOURAGE_OP_CAT."
2555+
],
2556+
[
2557+
[
2558+
"aa",
2559+
"bb",
2560+
"#SCRIPT# CAT",
2561+
"#CONTROLBLOCK#",
2562+
0.00000001
2563+
],
2564+
"",
2565+
"0x51 0x20 #TAPROOTOUTPUT#",
2566+
"P2SH,WITNESS,TAPROOT,DISCOURAGE_OP_CAT",
2567+
"DISCOURAGE_OP_CAT",
2568+
"TAPSCRIPT test of DISCOURAGE_OP_CAT flag by calling CAT on two elements. OP_CAT verify flag is not set and OP_CAT is not executed due to DISCOURAGE_OP_CAT."
2569+
],
2570+
[
2571+
[
2572+
"#SCRIPT# CAT",
2573+
"#CONTROLBLOCK#",
2574+
0.00000001
2575+
],
2576+
"",
2577+
"0x51 0x20 #TAPROOTOUTPUT#",
2578+
"P2SH,WITNESS,TAPROOT,DISCOURAGE_OP_CAT",
2579+
"DISCOURAGE_OP_CAT",
2580+
"TAPSCRIPT test of DISCOURAGE_OP_CAT flag by calling CAT on a empty stack. Ordinarily this would be INVALID_STACK_OPERATION however due to DISCOURAGE_OP_CAT the script will throw before execution."
2581+
],
2582+
[
2583+
[
2584+
"#SCRIPT# 1",
2585+
"#CONTROLBLOCK#",
2586+
0.00000001
2587+
],
2588+
"",
2589+
"0x51 0x20 #TAPROOTOUTPUT#",
2590+
"P2SH,WITNESS,TAPROOT,DISCOURAGE_OP_CAT",
2591+
"OK",
2592+
"TAPSCRIPT test of a valid script executed with DISCOURAGE_OP_CAT. This tests demonstrates that DISCOURAGE_OP_CAT has no affect when CAT is not used."
2593+
],
2594+
[
2595+
[
2596+
"#SCRIPT# CAT",
2597+
"#CONTROLBLOCK#",
2598+
0.00000001
2599+
],
2600+
"",
2601+
"0x51 0x20 #TAPROOTOUTPUT#",
2602+
"P2SH,WITNESS,TAPROOT,DISCOURAGE_OP_CAT,DISCOURAGE_OP_SUCCESS",
2603+
"DISCOURAGE_OP_CAT",
2604+
"TAPSCRIPT test of a invalid script (CAT called with empty stack) executed with DISCOURAGE_OP_CAT and DISCOURAGE_OP_SUCCESS flags enabled. This tests demonstrates that DISCOURAGE_OP_CAT will take priority over the OP_SUCCESS discourage flag and OP_CAT is never exectuted"
2605+
],
2606+
[
2607+
[
2608+
"#SCRIPT# CAT",
2609+
"#CONTROLBLOCK#",
2610+
0.00000001
2611+
],
2612+
"",
2613+
"0x51 0x20 #TAPROOTOUTPUT#",
2614+
"P2SH,WITNESS,TAPROOT,OP_CAT,DISCOURAGE_OP_SUCCESS",
2615+
"INVALID_STACK_OPERATION",
2616+
"TAPSCRIPT CAT on no stack elements with DISCOURAGE_OP_SUCCESS and OP_CAT script verify flags enabled. This test demonstrates that OP_CAT is no longer considered OP_SUCCESS when OP_CAT verify flag is set"
25422617
],
2618+
["OP_CAT functionality tests"],
25432619
[
25442620
[
25452621
"#SCRIPT# CAT",
@@ -2550,7 +2626,7 @@
25502626
"0x51 0x20 #TAPROOTOUTPUT#",
25512627
"P2SH,WITNESS,TAPROOT,OP_CAT",
25522628
"INVALID_STACK_OPERATION",
2553-
"TAPSCRIPT Test of OP_CAT flag by calling CAT on an empty stack. This throws an error because TAPSCRIPT_OP_CAT flag is set so CAT is executed"
2629+
"TAPSCRIPT Test of OP_CAT flag by calling CAT on an empty stack. This throws an error because OP_CAT verify flag is set so CAT is executed"
25542630
],
25552631
[
25562632
[
@@ -2564,7 +2640,7 @@
25642640
"0x51 0x20 #TAPROOTOUTPUT#",
25652641
"P2SH,WITNESS,TAPROOT,OP_CAT",
25662642
"OK",
2567-
"TAPSCRIPT Test of OP_CAT flag by calling CAT on two elements. TAPSCRIPT_OP_CAT flag is set so CAT is executed."
2643+
"TAPSCRIPT Test of OP_CAT flag by calling CAT on two elements. OP_CAT verify flag is set so CAT is executed."
25682644
],
25692645
[
25702646
[
@@ -2594,7 +2670,7 @@
25942670
"0x51 0x20 #TAPROOTOUTPUT#",
25952671
"P2SH,WITNESS,TAPROOT",
25962672
"OK",
2597-
"TAPSCRIPT Test of OP_CAT flag, CATs 78a11a1260 and c1101260 together and checks it is EQUAL to stack element 78a11a1260c1101260. No TAPSCRIPT_OP_CAT set so CAT should be OP_SUCCESS."
2673+
"TAPSCRIPT Test of OP_CAT flag, CATs 78a11a1260 and c1101260 together and checks it is EQUAL to stack element 78a11a1260c1101260. No OP_CAT verify flag set so CAT should be OP_SUCCESS."
25982674
],
25992675
[
26002676
[
@@ -2740,7 +2816,7 @@
27402816
"0x51 0x20 #TAPROOTOUTPUT#",
27412817
"P2SH,WITNESS,TAPROOT,OP_CAT",
27422818
"OK",
2743-
"TAPSCRIPT Runs DUP CAT seven times on 1a1a"
2819+
"TAPSCRIPT Runs DUP CAT seven times on 1a1a"
27442820
],
27452821
[
27462822
[
@@ -2820,7 +2896,7 @@
28202896
"0x51 0x20 #TAPROOTOUTPUT#",
28212897
"P2SH,WITNESS,TAPROOT,OP_CAT",
28222898
"OK",
2823-
"TAPSCRIPT ([512 byte element, 09ca7009ca7009ca7009ca7009ca70], CAT) Tests edge case where concatenated value is exactly max stack element size (520 bytes)"
2899+
"TAPSCRIPT ([512 byte element, 09ca7009ca7009ca7009ca7009ca70], CAT) Tests edge case where concatenated value is exactly max stack element size (520 bytes)"
28242900
],
28252901
[
28262902
[

src/test/script_tests.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static ScriptErrorDesc script_errors[]={
9191
{SCRIPT_ERR_WITNESS_PUBKEYTYPE, "WITNESS_PUBKEYTYPE"},
9292
{SCRIPT_ERR_OP_CODESEPARATOR, "OP_CODESEPARATOR"},
9393
{SCRIPT_ERR_SIG_FINDANDDELETE, "SIG_FINDANDDELETE"},
94+
{SCRIPT_ERR_DISCOURAGE_OP_CAT, "DISCOURAGE_OP_CAT"},
9495
};
9596

9697
std::string FormatScriptFlags(uint32_t flags)

0 commit comments

Comments
 (0)