Changeset View
Changeset View
Standalone View
Standalone View
src/test/DoS_tests.cpp
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(DoS_mapOrphans) { | ||||
// 50 orphan transactions: | // 50 orphan transactions: | ||||
for (int i = 0; i < 50; i++) { | for (int i = 0; i < 50; i++) { | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].prevout.n = 0; | tx.vin[0].prevout.n = 0; | ||||
tx.vin[0].prevout.hash = GetRandHash(); | tx.vin[0].prevout.hash = GetRandHash(); | ||||
tx.vin[0].scriptSig << OP_1; | tx.vin[0].scriptSig << OP_1; | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].nValue = 1 * CENT; | tx.vout[0].nValue = 1 * CENT.GetSatoshis(); | ||||
tx.vout[0].scriptPubKey = | tx.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key.GetPubKey().GetID()); | GetScriptForDestination(key.GetPubKey().GetID()); | ||||
AddOrphanTx(MakeTransactionRef(tx), i); | AddOrphanTx(MakeTransactionRef(tx), i); | ||||
} | } | ||||
// ... and 50 that depend on other orphans: | // ... and 50 that depend on other orphans: | ||||
for (int i = 0; i < 50; i++) { | for (int i = 0; i < 50; i++) { | ||||
CTransactionRef txPrev = RandomOrphan(); | CTransactionRef txPrev = RandomOrphan(); | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].prevout.n = 0; | tx.vin[0].prevout.n = 0; | ||||
tx.vin[0].prevout.hash = txPrev->GetId(); | tx.vin[0].prevout.hash = txPrev->GetId(); | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].nValue = 1 * CENT; | tx.vout[0].nValue = 1 * CENT.GetSatoshis(); | ||||
tx.vout[0].scriptPubKey = | tx.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key.GetPubKey().GetID()); | GetScriptForDestination(key.GetPubKey().GetID()); | ||||
SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL); | SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL); | ||||
AddOrphanTx(MakeTransactionRef(tx), i); | AddOrphanTx(MakeTransactionRef(tx), i); | ||||
} | } | ||||
// This really-big orphan should be ignored: | // This really-big orphan should be ignored: | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
CTransactionRef txPrev = RandomOrphan(); | CTransactionRef txPrev = RandomOrphan(); | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].nValue = 1 * CENT; | tx.vout[0].nValue = 1 * CENT.GetSatoshis(); | ||||
tx.vout[0].scriptPubKey = | tx.vout[0].scriptPubKey = | ||||
GetScriptForDestination(key.GetPubKey().GetID()); | GetScriptForDestination(key.GetPubKey().GetID()); | ||||
tx.vin.resize(2777); | tx.vin.resize(2777); | ||||
for (unsigned int j = 0; j < tx.vin.size(); j++) { | for (unsigned int j = 0; j < tx.vin.size(); j++) { | ||||
tx.vin[j].prevout.n = j; | tx.vin[j].prevout.n = j; | ||||
tx.vin[j].prevout.hash = txPrev->GetId(); | tx.vin[j].prevout.hash = txPrev->GetId(); | ||||
} | } | ||||
SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL); | SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL); | ||||
Show All 25 Lines |