Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_P2SH_tests.cpp
Show All 28 Lines | static bool Verify(const CScript &scriptSig, const CScript &scriptPubKey, | ||||
CMutableTransaction txFrom; | CMutableTransaction txFrom; | ||||
txFrom.vout.resize(1); | txFrom.vout.resize(1); | ||||
txFrom.vout[0].scriptPubKey = scriptPubKey; | txFrom.vout[0].scriptPubKey = scriptPubKey; | ||||
CMutableTransaction txTo; | CMutableTransaction txTo; | ||||
txTo.vin.resize(1); | txTo.vin.resize(1); | ||||
txTo.vout.resize(1); | txTo.vout.resize(1); | ||||
txTo.vin[0].prevout.n = 0; | txTo.vin[0].prevout.n = 0; | ||||
txTo.vin[0].prevout.hash = txFrom.GetId(); | txTo.vin[0].prevout.hash = txFrom.GetHash(); | ||||
txTo.vin[0].scriptSig = scriptSig; | txTo.vin[0].scriptSig = scriptSig; | ||||
txTo.vout[0].nValue = 1; | txTo.vout[0].nValue = 1; | ||||
return VerifyScript(scriptSig, scriptPubKey, | return VerifyScript(scriptSig, scriptPubKey, | ||||
(fStrict ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE) | | (fStrict ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE) | | ||||
SCRIPT_ENABLE_SIGHASH_FORKID, | SCRIPT_ENABLE_SIGHASH_FORKID, | ||||
MutableTransactionSignatureChecker( | MutableTransactionSignatureChecker( | ||||
&txTo, 0, txFrom.vout[0].nValue.GetSatoshis()), | &txTo, 0, txFrom.vout[0].nValue.GetSatoshis()), | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(sign) { | ||||
} | } | ||||
BOOST_CHECK(IsStandardTx(txFrom, reason)); | BOOST_CHECK(IsStandardTx(txFrom, reason)); | ||||
CMutableTransaction txTo[8]; // Spending transactions | CMutableTransaction txTo[8]; // Spending transactions | ||||
for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
txTo[i].vin.resize(1); | txTo[i].vin.resize(1); | ||||
txTo[i].vout.resize(1); | txTo[i].vout.resize(1); | ||||
txTo[i].vin[0].prevout.n = i; | txTo[i].vin[0].prevout.n = i; | ||||
txTo[i].vin[0].prevout.hash = txFrom.GetId(); | txTo[i].vin[0].prevout.hash = txFrom.GetHash(); | ||||
txTo[i].vout[0].nValue = 1; | txTo[i].vout[0].nValue = 1; | ||||
BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | ||||
strprintf("IsMine %d", i)); | strprintf("IsMine %d", i)); | ||||
} | } | ||||
for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID), | SIGHASH_ALL | SIGHASH_FORKID), | ||||
strprintf("SignSignature %d", i)); | strprintf("SignSignature %d", i)); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(set) { | ||||
BOOST_CHECK(IsStandardTx(txFrom, reason)); | BOOST_CHECK(IsStandardTx(txFrom, reason)); | ||||
// Spending transactions | // Spending transactions | ||||
CMutableTransaction txTo[4]; | CMutableTransaction txTo[4]; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
txTo[i].vin.resize(1); | txTo[i].vin.resize(1); | ||||
txTo[i].vout.resize(1); | txTo[i].vout.resize(1); | ||||
txTo[i].vin[0].prevout.n = i; | txTo[i].vin[0].prevout.n = i; | ||||
txTo[i].vin[0].prevout.hash = txFrom.GetId(); | txTo[i].vin[0].prevout.hash = txFrom.GetHash(); | ||||
txTo[i].vout[0].nValue = 1 * CENT.GetSatoshis(); | txTo[i].vout[0].nValue = 1 * CENT.GetSatoshis(); | ||||
txTo[i].vout[0].scriptPubKey = inner[i]; | txTo[i].vout[0].scriptPubKey = inner[i]; | ||||
BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | ||||
strprintf("IsMine %d", i)); | strprintf("IsMine %d", i)); | ||||
} | } | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID), | SIGHASH_ALL | SIGHASH_FORKID), | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(AreInputsStandard) { | ||||
CMutableTransaction txTo; | CMutableTransaction txTo; | ||||
txTo.vout.resize(1); | txTo.vout.resize(1); | ||||
txTo.vout[0].scriptPubKey = | txTo.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key[1].GetPubKey().GetID()); | GetScriptForDestination(key[1].GetPubKey().GetID()); | ||||
txTo.vin.resize(5); | txTo.vin.resize(5); | ||||
for (int i = 0; i < 5; i++) { | for (int i = 0; i < 5; i++) { | ||||
txTo.vin[i].prevout.n = i; | txTo.vin[i].prevout.n = i; | ||||
txTo.vin[i].prevout.hash = txFrom.GetId(); | txTo.vin[i].prevout.hash = txFrom.GetHash(); | ||||
} | } | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL | SIGHASH_FORKID)); | SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL | SIGHASH_FORKID)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
SignSignature(keystore, txFrom, txTo, 1, SIGHASH_ALL | SIGHASH_FORKID)); | SignSignature(keystore, txFrom, txTo, 1, SIGHASH_ALL | SIGHASH_FORKID)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
SignSignature(keystore, txFrom, txTo, 2, SIGHASH_ALL | SIGHASH_FORKID)); | SignSignature(keystore, txFrom, txTo, 2, SIGHASH_ALL | SIGHASH_FORKID)); | ||||
// SignSignature doesn't know how to sign these. We're not testing | // SignSignature doesn't know how to sign these. We're not testing | ||||
Show All 11 Lines | BOOST_AUTO_TEST_CASE(AreInputsStandard) { | ||||
CMutableTransaction txToNonStd1; | CMutableTransaction txToNonStd1; | ||||
txToNonStd1.vout.resize(1); | txToNonStd1.vout.resize(1); | ||||
txToNonStd1.vout[0].scriptPubKey = | txToNonStd1.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key[1].GetPubKey().GetID()); | GetScriptForDestination(key[1].GetPubKey().GetID()); | ||||
txToNonStd1.vout[0].nValue = 1000; | txToNonStd1.vout[0].nValue = 1000; | ||||
txToNonStd1.vin.resize(1); | txToNonStd1.vin.resize(1); | ||||
txToNonStd1.vin[0].prevout.n = 5; | txToNonStd1.vin[0].prevout.n = 5; | ||||
txToNonStd1.vin[0].prevout.hash = txFrom.GetId(); | txToNonStd1.vin[0].prevout.hash = txFrom.GetHash(); | ||||
txToNonStd1.vin[0].scriptSig | txToNonStd1.vin[0].scriptSig | ||||
<< std::vector<uint8_t>(sixteenSigops.begin(), sixteenSigops.end()); | << std::vector<uint8_t>(sixteenSigops.begin(), sixteenSigops.end()); | ||||
BOOST_CHECK(!::AreInputsStandard(txToNonStd1, coins)); | BOOST_CHECK(!::AreInputsStandard(txToNonStd1, coins)); | ||||
BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd1, coins), 16U); | BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd1, coins), 16U); | ||||
CMutableTransaction txToNonStd2; | CMutableTransaction txToNonStd2; | ||||
txToNonStd2.vout.resize(1); | txToNonStd2.vout.resize(1); | ||||
txToNonStd2.vout[0].scriptPubKey = | txToNonStd2.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key[1].GetPubKey().GetID()); | GetScriptForDestination(key[1].GetPubKey().GetID()); | ||||
txToNonStd2.vout[0].nValue = 1000; | txToNonStd2.vout[0].nValue = 1000; | ||||
txToNonStd2.vin.resize(1); | txToNonStd2.vin.resize(1); | ||||
txToNonStd2.vin[0].prevout.n = 6; | txToNonStd2.vin[0].prevout.n = 6; | ||||
txToNonStd2.vin[0].prevout.hash = txFrom.GetId(); | txToNonStd2.vin[0].prevout.hash = txFrom.GetHash(); | ||||
txToNonStd2.vin[0].scriptSig | txToNonStd2.vin[0].scriptSig | ||||
<< std::vector<uint8_t>(twentySigops.begin(), twentySigops.end()); | << std::vector<uint8_t>(twentySigops.begin(), twentySigops.end()); | ||||
BOOST_CHECK(!::AreInputsStandard(txToNonStd2, coins)); | BOOST_CHECK(!::AreInputsStandard(txToNonStd2, coins)); | ||||
BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd2, coins), 20U); | BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd2, coins), 20U); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |