mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-26 14:00:29 +01:00
scripted-diff: test: rename FromHex to from_hex
-BEGIN VERIFY SCRIPT- sed -i 's/\<FromHex\>/from_hex/g' $(git grep -l FromHex) -END VERIFY SCRIPT- Co-authored-by: MarcoFalke <falke.marco@gmail.com>
This commit is contained in:
@@ -23,7 +23,7 @@ PATH_BASE_TEST_FUNCTIONAL = os.path.abspath(os.path.join(PATH_BASE_CONTRIB_SIGNE
|
|||||||
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
|
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
|
||||||
|
|
||||||
from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
|
from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
|
||||||
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, FromHex, deser_string, hash256, ser_compact_size, ser_string, ser_uint256, tx_from_hex, uint256_from_str # noqa: E402
|
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, from_hex, deser_string, hash256, ser_compact_size, ser_string, ser_uint256, tx_from_hex, uint256_from_str # noqa: E402
|
||||||
from test_framework.script import CScriptOp # noqa: E402
|
from test_framework.script import CScriptOp # noqa: E402
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -37,7 +37,7 @@ RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
|
|||||||
|
|
||||||
# #### some helpers that could go into test_framework
|
# #### some helpers that could go into test_framework
|
||||||
|
|
||||||
# like FromHex, but without the hex part
|
# like from_hex, but without the hex part
|
||||||
def FromBinary(cls, stream):
|
def FromBinary(cls, stream):
|
||||||
"""deserialize a binary stream (or bytes object) into an object"""
|
"""deserialize a binary stream (or bytes object) into an object"""
|
||||||
# handle bytes object by turning it into a stream
|
# handle bytes object by turning it into a stream
|
||||||
@@ -195,7 +195,7 @@ def finish_block(block, signet_solution, grind_cmd):
|
|||||||
headhex = CBlockHeader.serialize(block).hex()
|
headhex = CBlockHeader.serialize(block).hex()
|
||||||
cmd = grind_cmd.split(" ") + [headhex]
|
cmd = grind_cmd.split(" ") + [headhex]
|
||||||
newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
|
newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
|
||||||
newhead = FromHex(CBlockHeader(), newheadhex.decode('utf8'))
|
newhead = from_hex(CBlockHeader(), newheadhex.decode('utf8'))
|
||||||
block.nNonce = newhead.nNonce
|
block.nNonce = newhead.nNonce
|
||||||
block.rehash()
|
block.rehash()
|
||||||
return block
|
return block
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import struct
|
|||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CBlock,
|
CBlock,
|
||||||
COutPoint,
|
COutPoint,
|
||||||
FromHex,
|
from_hex,
|
||||||
)
|
)
|
||||||
from test_framework.muhash import MuHash3072
|
from test_framework.muhash import MuHash3072
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
@@ -32,13 +32,13 @@ class UTXOSetHashTest(BitcoinTestFramework):
|
|||||||
# Generate 100 blocks and remove the first since we plan to spend its
|
# Generate 100 blocks and remove the first since we plan to spend its
|
||||||
# coinbase
|
# coinbase
|
||||||
block_hashes = wallet.generate(1) + node.generate(99)
|
block_hashes = wallet.generate(1) + node.generate(99)
|
||||||
blocks = list(map(lambda block: FromHex(CBlock(), node.getblock(block, False)), block_hashes))
|
blocks = list(map(lambda block: from_hex(CBlock(), node.getblock(block, False)), block_hashes))
|
||||||
blocks.pop(0)
|
blocks.pop(0)
|
||||||
|
|
||||||
# Create a spending transaction and mine a block which includes it
|
# Create a spending transaction and mine a block which includes it
|
||||||
txid = wallet.send_self_transfer(from_node=node)['txid']
|
txid = wallet.send_self_transfer(from_node=node)['txid']
|
||||||
tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid])
|
tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid])
|
||||||
blocks.append(FromHex(CBlock(), node.getblock(tx_block['hash'], False)))
|
blocks.append(from_hex(CBlock(), node.getblock(tx_block['hash'], False)))
|
||||||
|
|
||||||
# Serialize the outputs that should be in the UTXO set and add them to
|
# Serialize the outputs that should be in the UTXO set and add them to
|
||||||
# a MuHash object
|
# a MuHash object
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from test_framework.messages import (
|
|||||||
CTxIn,
|
CTxIn,
|
||||||
CTxInWitness,
|
CTxInWitness,
|
||||||
CTxOut,
|
CTxOut,
|
||||||
FromHex,
|
from_hex,
|
||||||
HeaderAndShortIDs,
|
HeaderAndShortIDs,
|
||||||
MSG_BLOCK,
|
MSG_BLOCK,
|
||||||
MSG_CMPCT_BLOCK,
|
MSG_CMPCT_BLOCK,
|
||||||
@@ -321,7 +321,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||||||
block_hash = int(node.generate(1)[0], 16)
|
block_hash = int(node.generate(1)[0], 16)
|
||||||
|
|
||||||
# Store the raw block in our internal format.
|
# Store the raw block in our internal format.
|
||||||
block = FromHex(CBlock(), node.getblock("%064x" % block_hash, False))
|
block = from_hex(CBlock(), node.getblock("%064x" % block_hash, False))
|
||||||
for tx in block.vtx:
|
for tx in block.vtx:
|
||||||
tx.calc_sha256()
|
tx.calc_sha256()
|
||||||
block.rehash()
|
block.rehash()
|
||||||
@@ -614,7 +614,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||||||
current_height = chain_height
|
current_height = chain_height
|
||||||
while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH):
|
while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH):
|
||||||
block_hash = node.getblockhash(current_height)
|
block_hash = node.getblockhash(current_height)
|
||||||
block = FromHex(CBlock(), node.getblock(block_hash, False))
|
block = from_hex(CBlock(), node.getblock(block_hash, False))
|
||||||
|
|
||||||
msg = msg_getblocktxn()
|
msg = msg_getblocktxn()
|
||||||
msg.block_txn_request = BlockTransactionsRequest(int(block_hash, 16), [])
|
msg.block_txn_request = BlockTransactionsRequest(int(block_hash, 16), [])
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CBlockHeader,
|
CBlockHeader,
|
||||||
FromHex,
|
from_hex,
|
||||||
)
|
)
|
||||||
from test_framework.p2p import (
|
from test_framework.p2p import (
|
||||||
P2PInterface,
|
P2PInterface,
|
||||||
@@ -42,8 +42,8 @@ class RejectLowDifficultyHeadersTest(BitcoinTestFramework):
|
|||||||
self.headers = [l for l in h_lines if not l.startswith(FORK_PREFIX)]
|
self.headers = [l for l in h_lines if not l.startswith(FORK_PREFIX)]
|
||||||
self.headers_fork = [l[len(FORK_PREFIX):] for l in h_lines if l.startswith(FORK_PREFIX)]
|
self.headers_fork = [l[len(FORK_PREFIX):] for l in h_lines if l.startswith(FORK_PREFIX)]
|
||||||
|
|
||||||
self.headers = [FromHex(CBlockHeader(), h) for h in self.headers]
|
self.headers = [from_hex(CBlockHeader(), h) for h in self.headers]
|
||||||
self.headers_fork = [FromHex(CBlockHeader(), h) for h in self.headers_fork]
|
self.headers_fork = [from_hex(CBlockHeader(), h) for h in self.headers_fork]
|
||||||
|
|
||||||
self.log.info("Feed all non-fork headers, including and up to the first checkpoint")
|
self.log.info("Feed all non-fork headers, including and up to the first checkpoint")
|
||||||
peer_checkpoint = self.nodes[0].add_p2p_connection(P2PInterface())
|
peer_checkpoint = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from test_framework.blocktools import (
|
|||||||
)
|
)
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CBlockHeader,
|
CBlockHeader,
|
||||||
FromHex,
|
from_hex,
|
||||||
msg_block,
|
msg_block,
|
||||||
)
|
)
|
||||||
from test_framework.p2p import P2PInterface
|
from test_framework.p2p import P2PInterface
|
||||||
@@ -314,7 +314,7 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
header_hex = node.getblockheader(blockhash=besthash, verbose=False)
|
header_hex = node.getblockheader(blockhash=besthash, verbose=False)
|
||||||
assert_is_hex_string(header_hex)
|
assert_is_hex_string(header_hex)
|
||||||
|
|
||||||
header = FromHex(CBlockHeader(), header_hex)
|
header = from_hex(CBlockHeader(), header_hex)
|
||||||
header.calc_sha256()
|
header.calc_sha256()
|
||||||
assert_equal(header.hash, besthash)
|
assert_equal(header.hash, besthash)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
from test_framework.blocktools import COINBASE_MATURITY
|
from test_framework.blocktools import COINBASE_MATURITY
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CMerkleBlock,
|
CMerkleBlock,
|
||||||
FromHex,
|
from_hex,
|
||||||
)
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
@@ -94,7 +94,7 @@ class MerkleBlockTest(BitcoinTestFramework):
|
|||||||
assert txid1 in self.nodes[0].verifytxoutproof(proof)
|
assert txid1 in self.nodes[0].verifytxoutproof(proof)
|
||||||
assert txid2 in self.nodes[1].verifytxoutproof(proof)
|
assert txid2 in self.nodes[1].verifytxoutproof(proof)
|
||||||
|
|
||||||
tweaked_proof = FromHex(CMerkleBlock(), proof)
|
tweaked_proof = from_hex(CMerkleBlock(), proof)
|
||||||
|
|
||||||
# Make sure that our serialization/deserialization is working
|
# Make sure that our serialization/deserialization is working
|
||||||
assert txid1 in self.nodes[0].verifytxoutproof(tweaked_proof.serialize().hex())
|
assert txid1 in self.nodes[0].verifytxoutproof(tweaked_proof.serialize().hex())
|
||||||
|
|||||||
@@ -191,14 +191,14 @@ def ser_string_vector(l):
|
|||||||
|
|
||||||
|
|
||||||
# Deserialize from a hex string representation (eg from RPC)
|
# Deserialize from a hex string representation (eg from RPC)
|
||||||
def FromHex(obj, hex_string):
|
def from_hex(obj, hex_string):
|
||||||
obj.deserialize(BytesIO(hex_str_to_bytes(hex_string)))
|
obj.deserialize(BytesIO(hex_str_to_bytes(hex_string)))
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
def tx_from_hex(hex_string):
|
def tx_from_hex(hex_string):
|
||||||
"""Deserialize from hex string to a transaction object"""
|
"""Deserialize from hex string to a transaction object"""
|
||||||
return FromHex(CTransaction(), hex_string)
|
return from_hex(CTransaction(), hex_string)
|
||||||
|
|
||||||
|
|
||||||
# Objects that map to bitcoind objects, which can be serialized/deserialized
|
# Objects that map to bitcoind objects, which can be serialized/deserialized
|
||||||
|
|||||||
Reference in New Issue
Block a user