MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/script_tests.cpp:430–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428BOOST_FIXTURE_TEST_SUITE(script_tests, ScriptTest)
429
430BOOST_AUTO_TEST_CASE(script_build)
431{
432 const KeyData keys;
433
434 std::vector<TestBuilder> tests;
435
436 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
437 "P2PK", 0
438 ).PushSig(keys.key0));
439 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
440 "P2PK, bad sig", 0
441 ).PushSig(keys.key0).DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE));
442
443 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
444 "P2PKH", 0
445 ).PushSig(keys.key1).Push(keys.pubkey1C));
446 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey2C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
447 "P2PKH, bad pubkey", 0
448 ).PushSig(keys.key2).Push(keys.pubkey2C).DamagePush(5).ScriptError(SCRIPT_ERR_EQUALVERIFY));
449
450 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
451 "P2PK anyonecanpay", 0
452 ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY));
453 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
454 "P2PK anyonecanpay marked with normal hashtype", 0
455 ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY).EditPush(70, "81", "01").ScriptError(SCRIPT_ERR_EVAL_FALSE));
456
457 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
458 "P2SH(P2PK)", SCRIPT_VERIFY_P2SH, true
459 ).PushSig(keys.key0).PushRedeem());
460 tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
461 "P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true
462 ).PushSig(keys.key0).PushRedeem().DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE));
463
464 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey0.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
465 "P2SH(P2PKH)", SCRIPT_VERIFY_P2SH, true
466 ).PushSig(keys.key0).Push(keys.pubkey0).PushRedeem());
467 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
468 "P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true
469 ).PushSig(keys.key0).DamagePush(10).PushRedeem());
470 tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
471 "P2SH(P2PKH), bad sig", SCRIPT_VERIFY_P2SH, true
472 ).PushSig(keys.key0).DamagePush(10).PushRedeem().ScriptError(SCRIPT_ERR_EQUALVERIFY));
473
474 tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
475 "3-of-3", 0
476 ).Num(0).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
477 tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
478 "3-of-3, 2 sigs", 0
479 ).Num(0).PushSig(keys.key0).PushSig(keys.key1).Num(0).ScriptError(SCRIPT_ERR_EVAL_FALSE));
480
481 tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
482 "P2SH(2-of-3)", SCRIPT_VERIFY_P2SH, true
483 ).Num(0).PushSig(keys.key1).PushSig(keys.key2).PushRedeem());
484 tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
485 "P2SH(2-of-3), 1 sig", SCRIPT_VERIFY_P2SH, true
486 ).Num(0).PushSig(keys.key1).Num(0).PushRedeem().ScriptError(SCRIPT_ERR_EVAL_FALSE));
487

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
ParseScriptErrorFunction · 0.85
EvalScriptFunction · 0.85
ScriptErrorStringFunction · 0.85
GenerateRandomKeyFunction · 0.85

Tested by

no test coverage detected