mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
test: move create_malleated_version() to messages.py for reuse
This commit is contained in:
@@ -29,7 +29,10 @@ import time
|
||||
import unittest
|
||||
|
||||
from test_framework.crypto.siphash import siphash256
|
||||
from test_framework.util import assert_equal
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_not_equal,
|
||||
)
|
||||
|
||||
MAX_LOCATOR_SZ = 101
|
||||
MAX_BLOCK_WEIGHT = 4000000
|
||||
@@ -253,6 +256,23 @@ def tx_from_hex(hex_string):
|
||||
return from_hex(CTransaction(), hex_string)
|
||||
|
||||
|
||||
def malleate_tx_to_invalid_witness(tx):
|
||||
"""
|
||||
Create a malleated version of the tx where the witness is replaced with garbage data.
|
||||
Returns a CTransaction object.
|
||||
"""
|
||||
tx_bad_wit = tx_from_hex(tx["hex"])
|
||||
tx_bad_wit.wit.vtxinwit = [CTxInWitness()]
|
||||
# Add garbage data to witness 0. We cannot simply strip the witness, as the node would
|
||||
# classify it as a transaction in which the witness was missing rather than wrong.
|
||||
tx_bad_wit.wit.vtxinwit[0].scriptWitness.stack = [b'garbage']
|
||||
|
||||
assert_equal(tx["txid"], tx_bad_wit.txid_hex)
|
||||
assert_not_equal(tx["wtxid"], tx_bad_wit.wtxid_hex)
|
||||
|
||||
return tx_bad_wit
|
||||
|
||||
|
||||
# like from_hex, but without the hex part
|
||||
def from_binary(cls, stream):
|
||||
"""deserialize a binary stream (or bytes object) into an object"""
|
||||
|
||||
Reference in New Issue
Block a user