| 652 | } // namespace |
| 653 | |
| 654 | BOOST_AUTO_TEST_CASE(script_build) |
| 655 | { |
| 656 | const KeyData keys; |
| 657 | |
| 658 | std::vector<TestBuilder> tests; |
| 659 | |
| 660 | // replay attack tests |
| 661 | add_replay_tests_mode(tests, keys, REPLAY_NO_FORKID); |
| 662 | add_replay_tests_mode(tests, keys, REPLAY_INCORRECT_FORKID); |
| 663 | add_replay_tests_mode(tests, keys, REPLAY_FORKID_WRONG_HASH); |
| 664 | |
| 665 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG, |
| 666 | "P2PK", 0 |
| 667 | ).PushSig(keys.key0)); |
| 668 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG, |
| 669 | "P2PK, bad sig", 0 |
| 670 | ).PushSig(keys.key0).DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE)); |
| 671 | |
| 672 | tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG, |
| 673 | "P2PKH", 0 |
| 674 | ).PushSig(keys.key1).Push(keys.pubkey1C)); |
| 675 | tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey2C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG, |
| 676 | "P2PKH, bad pubkey", 0 |
| 677 | ).PushSig(keys.key2).Push(keys.pubkey2C).DamagePush(5).ScriptError(SCRIPT_ERR_EQUALVERIFY)); |
| 678 | |
| 679 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG, |
| 680 | "P2PK anyonecanpay", 0 |
| 681 | ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_FORKID | SIGHASH_ANYONECANPAY)); |
| 682 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG, |
| 683 | "P2PK anyonecanpay marked with normal hashtype", 0 |
| 684 | ).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_FORKID | SIGHASH_ANYONECANPAY).EditPush(70, "C1", "01").ScriptError(SCRIPT_ERR_EVAL_FALSE)); |
| 685 | |
| 686 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG, |
| 687 | "P2SH(P2PK)", SCRIPT_VERIFY_P2SH, true |
| 688 | ).PushSig(keys.key0).PushRedeem()); |
| 689 | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG, |
| 690 | "P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true |
| 691 | ).PushSig(keys.key0).PushRedeem().DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE)); |
| 692 | |
| 693 | tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey0.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG, |
| 694 | "P2SH(P2PKH)", SCRIPT_VERIFY_P2SH, true |
| 695 | ).PushSig(keys.key0).Push(keys.pubkey0).PushRedeem()); |
| 696 | tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG, |
| 697 | "P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true |
| 698 | ).PushSig(keys.key0).DamagePush(10).PushRedeem()); |
| 699 | tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG, |
| 700 | "P2SH(P2PKH), bad sig", SCRIPT_VERIFY_P2SH, true |
| 701 | ).PushSig(keys.key0).DamagePush(10).PushRedeem().ScriptError(SCRIPT_ERR_EQUALVERIFY)); |
| 702 | |
| 703 | tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG, |
| 704 | "3-of-3", 0 |
| 705 | ).Num(0).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2)); |
| 706 | tests.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG, |
| 707 | "3-of-3, 2 sigs", 0 |
| 708 | ).Num(0).PushSig(keys.key0).PushSig(keys.key1).Num(0).ScriptError(SCRIPT_ERR_EVAL_FALSE)); |
| 709 | |
| 710 | tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG, |
| 711 | "P2SH(2-of-3)", SCRIPT_VERIFY_P2SH, true |
nothing calls this directly
no test coverage detected