MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/script_tests.cpp:498–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496} // namespace
497
498BOOST_AUTO_TEST_CASE(script_build)
499{
500 const KeyData keys;
501
502 std::vector<TestBuilder> tests;
503
504 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
505 "P2PK", 0
506 ).PushSig(keys.key0));
507 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
508 "P2PK, bad sig", 0
509 ).PushSig(keys.key0).DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE));
510
511 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
512 "P2PKH", 0
513 ).PushSig(keys.key1).Push(keys.pubkey1C));
514 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey2C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
515 "P2PKH, bad pubkey", 0
516 ).PushSig(keys.key2).Push(keys.pubkey2C).DamagePush(5).ScriptError(SCRIPT_ERR_EQUALVERIFY));
517
518 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
519 "P2PK anyonecanpay", 0
520 ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY));
521 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
522 "P2PK anyonecanpay marked with normal hashtype", 0
523 ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY).EditPush(70, "81", "01").ScriptError(SCRIPT_ERR_EVAL_FALSE));
524
525 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
526 "P2SH(P2PK)", SCRIPT_VERIFY_P2SH, true
527 ).PushSig(keys.key0).PushRedeem());
528 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
529 "P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true
530 ).PushSig(keys.key0).PushRedeem().DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE));
531
532 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey0.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
533 "P2SH(P2PKH)", SCRIPT_VERIFY_P2SH, true
534 ).PushSig(keys.key0).Push(keys.pubkey0).PushRedeem());
535 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
536 "P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true
537 ).PushSig(keys.key0).DamagePush(10).PushRedeem());
538 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
539 "P2SH(P2PKH), bad sig", SCRIPT_VERIFY_P2SH, true
540 ).PushSig(keys.key0).DamagePush(10).PushRedeem().ScriptError(SCRIPT_ERR_EQUALVERIFY));
541
542 tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
543 "3-of-3", 0
544 ).Num(0).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
545 tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
546 "3-of-3, 2 sigs", 0
547 ).Num(0).PushSig(keys.key0).PushSig(keys.key1).Num(0).ScriptError(SCRIPT_ERR_EVAL_FALSE));
548
549 tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
550 "P2SH(2-of-3)", SCRIPT_VERIFY_P2SH, true
551 ).Num(0).PushSig(keys.key1).PushSig(keys.key2).PushRedeem());
552 tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
553 "P2SH(2-of-3), 1 sig", SCRIPT_VERIFY_P2SH, true
554 ).Num(0).PushSig(keys.key1).Num(0).PushRedeem().ScriptError(SCRIPT_ERR_EVAL_FALSE));
555

Callers

nothing calls this directly

Calls 15

TestBuilderClass · 0.85
ToByteVectorFunction · 0.85
CSHA256Class · 0.85
read_jsonFunction · 0.85
JSONPrettyPrintFunction · 0.85
fopenFunction · 0.85
ParseHexFunction · 0.85
ParseScriptErrorFunction · 0.85
DoTestFunction · 0.85
EvalScriptFunction · 0.85
ScriptErrorStringFunction · 0.85

Tested by

no test coverage detected