mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
test: Add bad-txns-*-toolarge test cases to invalid_txs
This commit is contained in:
parent
ac5c5d0162
commit
faae5a9a35
3 changed files with 31 additions and 5 deletions
|
@ -21,7 +21,13 @@ Invalid tx cases not covered here can be found by running:
|
||||||
"""
|
"""
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
from test_framework.messages import CTransaction, CTxIn, CTxOut, COutPoint
|
from test_framework.messages import (
|
||||||
|
COutPoint,
|
||||||
|
CTransaction,
|
||||||
|
CTxIn,
|
||||||
|
CTxOut,
|
||||||
|
MAX_MONEY,
|
||||||
|
)
|
||||||
from test_framework import script as sc
|
from test_framework import script as sc
|
||||||
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
|
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
|
||||||
from test_framework.script import (
|
from test_framework.script import (
|
||||||
|
@ -166,7 +172,7 @@ class SpendTooMuch(BadTxTemplate):
|
||||||
self.spend_tx, 0, script_pub_key=basic_p2sh, amount=(self.spend_avail + 1))
|
self.spend_tx, 0, script_pub_key=basic_p2sh, amount=(self.spend_avail + 1))
|
||||||
|
|
||||||
|
|
||||||
class SpendNegative(BadTxTemplate):
|
class CreateNegative(BadTxTemplate):
|
||||||
reject_reason = 'bad-txns-vout-negative'
|
reject_reason = 'bad-txns-vout-negative'
|
||||||
expect_disconnect = True
|
expect_disconnect = True
|
||||||
|
|
||||||
|
@ -174,6 +180,25 @@ class SpendNegative(BadTxTemplate):
|
||||||
return create_tx_with_script(self.spend_tx, 0, amount=-1)
|
return create_tx_with_script(self.spend_tx, 0, amount=-1)
|
||||||
|
|
||||||
|
|
||||||
|
class CreateTooLarge(BadTxTemplate):
|
||||||
|
reject_reason = 'bad-txns-vout-toolarge'
|
||||||
|
expect_disconnect = True
|
||||||
|
|
||||||
|
def get_tx(self):
|
||||||
|
return create_tx_with_script(self.spend_tx, 0, amount=MAX_MONEY + 1)
|
||||||
|
|
||||||
|
|
||||||
|
class CreateSumTooLarge(BadTxTemplate):
|
||||||
|
reject_reason = 'bad-txns-txouttotal-toolarge'
|
||||||
|
expect_disconnect = True
|
||||||
|
|
||||||
|
def get_tx(self):
|
||||||
|
tx = create_tx_with_script(self.spend_tx, 0, amount=MAX_MONEY)
|
||||||
|
tx.vout = [tx.vout[0]] * 2
|
||||||
|
tx.calc_sha256()
|
||||||
|
return tx
|
||||||
|
|
||||||
|
|
||||||
class InvalidOPIFConstruction(BadTxTemplate):
|
class InvalidOPIFConstruction(BadTxTemplate):
|
||||||
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
|
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
|
||||||
expect_disconnect = True
|
expect_disconnect = True
|
||||||
|
@ -237,4 +262,3 @@ DisabledOpcodeTemplates = [getDisabledOpcodeTemplate(opcode) for opcode in [
|
||||||
def iter_all_templates():
|
def iter_all_templates():
|
||||||
"""Iterate through all bad transaction template types."""
|
"""Iterate through all bad transaction template types."""
|
||||||
return BadTxTemplate.__subclasses__()
|
return BadTxTemplate.__subclasses__()
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ from test_framework.messages import (
|
||||||
CTransaction,
|
CTransaction,
|
||||||
CTxOut,
|
CTxOut,
|
||||||
MAX_BLOCK_BASE_SIZE,
|
MAX_BLOCK_BASE_SIZE,
|
||||||
|
MAX_MONEY,
|
||||||
)
|
)
|
||||||
from test_framework.script import (
|
from test_framework.script import (
|
||||||
hash160,
|
hash160,
|
||||||
|
@ -220,7 +221,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
||||||
# The following two validations prevent overflow of the output amounts (see CVE-2010-5139).
|
# The following two validations prevent overflow of the output amounts (see CVE-2010-5139).
|
||||||
self.log.info('A transaction with too large output value')
|
self.log.info('A transaction with too large output value')
|
||||||
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
|
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
|
||||||
tx.vout[0].nValue = 21000000 * COIN + 1
|
tx.vout[0].nValue = MAX_MONEY + 1
|
||||||
self.check_mempool_result(
|
self.check_mempool_result(
|
||||||
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}],
|
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}],
|
||||||
rawtxs=[tx.serialize().hex()],
|
rawtxs=[tx.serialize().hex()],
|
||||||
|
@ -229,7 +230,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
||||||
self.log.info('A transaction with too large sum of output values')
|
self.log.info('A transaction with too large sum of output values')
|
||||||
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
|
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
|
||||||
tx.vout = [tx.vout[0]] * 2
|
tx.vout = [tx.vout[0]] * 2
|
||||||
tx.vout[0].nValue = 21000000 * COIN
|
tx.vout[0].nValue = MAX_MONEY
|
||||||
self.check_mempool_result(
|
self.check_mempool_result(
|
||||||
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}],
|
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}],
|
||||||
rawtxs=[tx.serialize().hex()],
|
rawtxs=[tx.serialize().hex()],
|
||||||
|
|
|
@ -39,6 +39,7 @@ MAX_LOCATOR_SZ = 101
|
||||||
MAX_BLOCK_BASE_SIZE = 1000000
|
MAX_BLOCK_BASE_SIZE = 1000000
|
||||||
|
|
||||||
COIN = 100000000 # 1 btc in satoshis
|
COIN = 100000000 # 1 btc in satoshis
|
||||||
|
MAX_MONEY = 21000000 * COIN
|
||||||
|
|
||||||
BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out
|
BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue