Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_P2SH_tests.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(sign) { | ||||
standardScripts[2] << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | standardScripts[2] << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | ||||
standardScripts[3] = GetScriptForDestination(key[2].GetPubKey().GetID()); | standardScripts[3] = GetScriptForDestination(key[2].GetPubKey().GetID()); | ||||
CScript evalScripts[4]; | CScript evalScripts[4]; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
keystore.AddCScript(standardScripts[i]); | keystore.AddCScript(standardScripts[i]); | ||||
evalScripts[i] = GetScriptForDestination(CScriptID(standardScripts[i])); | evalScripts[i] = GetScriptForDestination(CScriptID(standardScripts[i])); | ||||
} | } | ||||
CMutableTransaction txFrom; // Funding transaction: | // Funding transaction: | ||||
CMutableTransaction txFrom; | |||||
std::string reason; | std::string reason; | ||||
txFrom.vout.resize(8); | txFrom.vout.resize(8); | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
txFrom.vout[i].scriptPubKey = evalScripts[i]; | txFrom.vout[i].scriptPubKey = evalScripts[i]; | ||||
txFrom.vout[i].nValue = COIN; | txFrom.vout[i].nValue = COIN; | ||||
txFrom.vout[i + 4].scriptPubKey = standardScripts[i]; | txFrom.vout[i + 4].scriptPubKey = standardScripts[i]; | ||||
txFrom.vout[i + 4].nValue = COIN; | txFrom.vout[i + 4].nValue = COIN; | ||||
} | } | ||||
BOOST_CHECK(IsStandardTx(CTransaction(txFrom), reason)); | BOOST_CHECK(IsStandardTx(CTransaction(txFrom), reason)); | ||||
CMutableTransaction txTo[8]; // Spending transactions | // Spending transactions | ||||
CMutableTransaction txTo[8]; | |||||
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 = COutPoint(txFrom.GetId(), i); | txTo[i].vin[0].prevout = COutPoint(txFrom.GetId(), i); | ||||
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()), | 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); | ||||
for (int j = 0; j < 8; j++) { | for (int j = 0; j < 8; j++) { | ||||
CScript sigSave = txTo[i].vin[0].scriptSig; | CScript sigSave = txTo[i].vin[0].scriptSig; | ||||
▲ Show 20 Lines • Show All 330 Lines • Show Last 20 Lines |