Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_P2SH_tests.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | for (int i = 0; i < 8; i++) { | ||||
txTo[i].vin[0].prevout.hash = txFrom.GetId(); | txTo[i].vin[0].prevout.hash = txFrom.GetId(); | ||||
txTo[i].vout[0].nValue = Amount(1); | txTo[i].vout[0].nValue = Amount(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, CTransaction(txFrom), | BOOST_CHECK_MESSAGE(SignSignature(keystore, CTransaction(txFrom), | ||||
txTo[i], 0, | txTo[i], 0, | ||||
SigHashType().withForkId(true)), | SigHashType().withForkId()), | ||||
strprintf("SignSignature %d", i)); | strprintf("SignSignature %d", i)); | ||||
} | } | ||||
// All of the above should be OK, and the txTos have valid signatures | // All of the above should be OK, and the txTos have valid signatures | ||||
// Check to make sure signature verification fails if we use the wrong | // Check to make sure signature verification fails if we use the wrong | ||||
// ScriptSig: | // ScriptSig: | ||||
for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
CTransaction tx(txTo[i]); | CTransaction tx(txTo[i]); | ||||
PrecomputedTransactionData txdata(tx); | PrecomputedTransactionData txdata(tx); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | for (int i = 0; i < 4; i++) { | ||||
txTo[i].vout[0].nValue = 1 * CENT; | txTo[i].vout[0].nValue = 1 * CENT; | ||||
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, CTransaction(txFrom), | BOOST_CHECK_MESSAGE(SignSignature(keystore, CTransaction(txFrom), | ||||
txTo[i], 0, | txTo[i], 0, | ||||
SigHashType().withForkId(true)), | SigHashType().withForkId()), | ||||
strprintf("SignSignature %d", i)); | strprintf("SignSignature %d", i)); | ||||
BOOST_CHECK_MESSAGE(IsStandardTx(CTransaction(txTo[i]), reason), | BOOST_CHECK_MESSAGE(IsStandardTx(CTransaction(txTo[i]), reason), | ||||
strprintf("txTo[%d].IsStandard", i)); | strprintf("txTo[%d].IsStandard", i)); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(is) { | BOOST_AUTO_TEST_CASE(is) { | ||||
// Test CScript::IsPayToScriptHash() | // Test CScript::IsPayToScriptHash() | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | 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.GetId(); | ||||
} | } | ||||
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, | BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, | ||||
SigHashType().withForkId(true))); | SigHashType().withForkId())); | ||||
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 1, | BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 1, | ||||
SigHashType().withForkId(true))); | SigHashType().withForkId())); | ||||
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 2, | BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 2, | ||||
SigHashType().withForkId(true))); | SigHashType().withForkId())); | ||||
// SignSignature doesn't know how to sign these. We're not testing | // SignSignature doesn't know how to sign these. We're not testing | ||||
// validating signatures, so just create dummy signatures that DO include | // validating signatures, so just create dummy signatures that DO include | ||||
// the correct P2SH scripts: | // the correct P2SH scripts: | ||||
txTo.vin[3].scriptSig << OP_11 << OP_11 | txTo.vin[3].scriptSig << OP_11 << OP_11 | ||||
<< std::vector<uint8_t>(oneAndTwo.begin(), | << std::vector<uint8_t>(oneAndTwo.begin(), | ||||
oneAndTwo.end()); | oneAndTwo.end()); | ||||
txTo.vin[4].scriptSig << std::vector<uint8_t>(fifteenSigops.begin(), | txTo.vin[4].scriptSig << std::vector<uint8_t>(fifteenSigops.begin(), | ||||
fifteenSigops.end()); | fifteenSigops.end()); | ||||
Show All 35 Lines |