Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_tx.py
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
CTxOut(nValue=50 * COIN - 12000, scriptPubKey=b'\x51')) | CTxOut(nValue=50 * COIN - 12000, scriptPubKey=b'\x51')) | ||||
pad_tx(tx_withhold) | pad_tx(tx_withhold) | ||||
tx_withhold.calc_sha256() | tx_withhold.calc_sha256() | ||||
# Our first orphan tx with some outputs to create further orphan txs | # Our first orphan tx with some outputs to create further orphan txs | ||||
tx_orphan_1 = CTransaction() | tx_orphan_1 = CTransaction() | ||||
tx_orphan_1.vin.append( | tx_orphan_1.vin.append( | ||||
CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0))) | CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0))) | ||||
tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=b'\x51')] * 3 | tx_orphan_1.vout = [ | ||||
CTxOut( | |||||
nValue=10 * COIN, | |||||
scriptPubKey=b'\x51')] * 3 | |||||
pad_tx(tx_orphan_1) | pad_tx(tx_orphan_1) | ||||
tx_orphan_1.calc_sha256() | tx_orphan_1.calc_sha256() | ||||
# A valid transaction with low fee | # A valid transaction with low fee | ||||
tx_orphan_2_no_fee = CTransaction() | tx_orphan_2_no_fee = CTransaction() | ||||
tx_orphan_2_no_fee.vin.append( | tx_orphan_2_no_fee.vin.append( | ||||
CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0))) | CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0))) | ||||
tx_orphan_2_no_fee.vout.append( | tx_orphan_2_no_fee.vout.append( | ||||
Show All 11 Lines | def run_test(self): | ||||
# An invalid transaction with negative fee | # An invalid transaction with negative fee | ||||
tx_orphan_2_invalid = CTransaction() | tx_orphan_2_invalid = CTransaction() | ||||
tx_orphan_2_invalid.vin.append( | tx_orphan_2_invalid.vin.append( | ||||
CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 2))) | CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 2))) | ||||
tx_orphan_2_invalid.vout.append( | tx_orphan_2_invalid.vout.append( | ||||
CTxOut(nValue=11 * COIN, scriptPubKey=b'\x51')) | CTxOut(nValue=11 * COIN, scriptPubKey=b'\x51')) | ||||
pad_tx(tx_orphan_2_invalid) | pad_tx(tx_orphan_2_invalid) | ||||
tx_orphan_2_invalid.calc_sha256() | |||||
self.log.info('Send the orphans ... ') | self.log.info('Send the orphans ... ') | ||||
# Send valid orphan txs from p2ps[0] | # Send valid orphan txs from p2ps[0] | ||||
node.p2p.send_txs_and_test( | node.p2p.send_txs_and_test( | ||||
[tx_orphan_1, tx_orphan_2_no_fee, tx_orphan_2_valid], node, success=False) | [tx_orphan_1, tx_orphan_2_no_fee, tx_orphan_2_valid], node, success=False) | ||||
# Send invalid tx from p2ps[1] | # Send invalid tx from p2ps[1] | ||||
node.p2ps[1].send_txs_and_test( | node.p2ps[1].send_txs_and_test( | ||||
[tx_orphan_2_invalid], node, success=False) | [tx_orphan_2_invalid], node, success=False) | ||||
Show All 21 Lines | def run_test(self): | ||||
# tx_orphan_no_fee, because it has too low fee (p2ps[0] is not disconnected for relaying that tx) | # tx_orphan_no_fee, because it has too low fee (p2ps[0] is not disconnected for relaying that tx) | ||||
# tx_orphan_invaid, because it has negative fee (p2ps[1] is | # tx_orphan_invaid, because it has negative fee (p2ps[1] is | ||||
# disconnected for relaying that tx) | # disconnected for relaying that tx) | ||||
# p2ps[1] is no longer connected | # p2ps[1] is no longer connected | ||||
wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) | wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) | ||||
assert_equal(expected_mempool, set(node.getrawmempool())) | assert_equal(expected_mempool, set(node.getrawmempool())) | ||||
self.log.info('Test orphan pool overflow') | |||||
orphan_tx_pool = [CTransaction() for _ in range(101)] | |||||
for i in range(len(orphan_tx_pool)): | |||||
orphan_tx_pool[i].vin.append(CTxIn(outpoint=COutPoint(i, 333))) | |||||
orphan_tx_pool[i].vout.append( | |||||
CTxOut( | |||||
nValue=11 * COIN, | |||||
scriptPubKey=b'\x51')) | |||||
pad_tx(orphan_tx_pool[i]) | |||||
with node.assert_debug_log(['mapOrphan overflow, removed 1 tx']): | |||||
node.p2p.send_txs_and_test(orphan_tx_pool, node, success=False) | |||||
rejected_parent = CTransaction() | |||||
rejected_parent.vin.append( | |||||
CTxIn( | |||||
outpoint=COutPoint( | |||||
tx_orphan_2_invalid.sha256, | |||||
0))) | |||||
rejected_parent.vout.append( | |||||
CTxOut( | |||||
nValue=11 * COIN, | |||||
scriptPubKey=b'\x51')) | |||||
pad_tx(rejected_parent) | |||||
rejected_parent.rehash() | |||||
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.hash)]): | |||||
node.p2p.send_txs_and_test([rejected_parent], node, success=False) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
InvalidTxRequestTest().main() | InvalidTxRequestTest().main() |