| 36 | } |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(multisig_verify) |
| 39 | { |
| 40 | unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; |
| 41 | |
| 42 | ScriptError err; |
| 43 | CKey key[4]; |
| 44 | CAmount amount = 0; |
| 45 | for (int i = 0; i < 4; i++) |
| 46 | key[i].MakeNewKey(true); |
| 47 | |
| 48 | CScript a_and_b; |
| 49 | a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG; |
| 50 | |
| 51 | CScript a_or_b; |
| 52 | a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG; |
| 53 | |
| 54 | CScript escrow; |
| 55 | escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG; |
| 56 | |
| 57 | CMutableTransaction txFrom; // Funding transaction |
| 58 | txFrom.vout.resize(3); |
| 59 | txFrom.vout[0].scriptPubKey = a_and_b; |
| 60 | txFrom.vout[1].scriptPubKey = a_or_b; |
| 61 | txFrom.vout[2].scriptPubKey = escrow; |
| 62 | |
| 63 | CMutableTransaction txTo[3]; // Spending transaction |
| 64 | for (int i = 0; i < 3; i++) |
| 65 | { |
| 66 | txTo[i].vin.resize(1); |
| 67 | txTo[i].vout.resize(1); |
| 68 | txTo[i].vin[0].prevout.n = i; |
| 69 | txTo[i].vin[0].prevout.hash = txFrom.GetHash(); |
| 70 | txTo[i].vout[0].nValue = 1; |
| 71 | } |
| 72 | |
| 73 | std::vector<CKey> keys; |
| 74 | CScript s; |
| 75 | |
| 76 | // Test a AND b: |
| 77 | keys.assign(1,key[0]); |
| 78 | keys.push_back(key[1]); |
| 79 | s = sign_multisig(a_and_b, keys, CTransaction(txTo[0]), 0); |
| 80 | BOOST_CHECK(VerifyScript(s, a_and_b, nullptr, flags, MutableTransactionSignatureChecker(&txTo[0], 0, amount, MissingDataBehavior::ASSERT_FAIL), &err)); |
| 81 | BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err)); |
| 82 | |
| 83 | for (int i = 0; i < 4; i++) |
| 84 | { |
| 85 | keys.assign(1,key[i]); |
| 86 | s = sign_multisig(a_and_b, keys, CTransaction(txTo[0]), 0); |
| 87 | BOOST_CHECK_MESSAGE(!VerifyScript(s, a_and_b, nullptr, flags, MutableTransactionSignatureChecker(&txTo[0], 0, amount, MissingDataBehavior::ASSERT_FAIL), &err), strprintf("a&b 1: %d", i)); |
| 88 | BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_INVALID_STACK_OPERATION, ScriptErrorString(err)); |
| 89 | |
| 90 | keys.assign(1,key[1]); |
| 91 | keys.push_back(key[i]); |
| 92 | s = sign_multisig(a_and_b, keys, CTransaction(txTo[0]), 0); |
| 93 | BOOST_CHECK_MESSAGE(!VerifyScript(s, a_and_b, nullptr, flags, MutableTransactionSignatureChecker(&txTo[0], 0, amount, MissingDataBehavior::ASSERT_FAIL), &err), strprintf("a&b 2: %d", i)); |
| 94 | BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_EVAL_FALSE, ScriptErrorString(err)); |
| 95 | } |
nothing calls this directly
no test coverage detected