Skip to content

Commit faf2a97

Browse files
author
MarcoFalke
committed
test: Use int.to_bytes over struct packing
This is done in prepration for the scripted diff, which can not deal with those lines.
1 parent faf3cd6 commit faf2a97

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Test node responses to invalid network messages."""
66

77
import random
8-
import struct
98
import time
109

1110
from test_framework.messages import (
@@ -233,7 +232,7 @@ def test_addrv2_too_long_address(self):
233232
'208d')) # port
234233

235234
def test_addrv2_unrecognized_network(self):
236-
now_hex = struct.pack('<I', int(time.time())).hex()
235+
now_hex = int(time.time()).to_bytes(4, "little").hex()
237236
self.test_addrv2('unrecognized network',
238237
[
239238
'received: addrv2 (25 bytes)',

test/functional/test_framework/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,13 @@ def BIP341_sha_prevouts(txTo):
800800
return sha256(b"".join(i.prevout.serialize() for i in txTo.vin))
801801

802802
def BIP341_sha_amounts(spent_utxos):
803-
return sha256(b"".join(struct.pack("<q", u.nValue) for u in spent_utxos))
803+
return sha256(b"".join(u.nValue.to_bytes(8, "little", signed=True) for u in spent_utxos))
804804

805805
def BIP341_sha_scriptpubkeys(spent_utxos):
806806
return sha256(b"".join(ser_string(u.scriptPubKey) for u in spent_utxos))
807807

808808
def BIP341_sha_sequences(txTo):
809-
return sha256(b"".join(struct.pack("<I", i.nSequence) for i in txTo.vin))
809+
return sha256(b"".join(i.nSequence.to_bytes(4, "little") for i in txTo.vin))
810810

811811
def BIP341_sha_outputs(txTo):
812812
return sha256(b"".join(o.serialize() for o in txTo.vout))

test/functional/wallet_balance.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the wallet balance RPC methods."""
66
from decimal import Decimal
7-
import struct
87

98
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
109
from test_framework.blocktools import COINBASE_MATURITY
@@ -266,8 +265,8 @@ def test_balances(*, fee_node_1=0):
266265
tx_orig = self.nodes[0].gettransaction(txid)['hex']
267266
# Increase fee by 1 coin
268267
tx_replace = tx_orig.replace(
269-
struct.pack("<q", 99 * 10**8).hex(),
270-
struct.pack("<q", 98 * 10**8).hex(),
268+
(99 * 10**8).to_bytes(8, "little", signed=True).hex(),
269+
(98 * 10**8).to_bytes(8, "little", signed=True).hex(),
271270
)
272271
tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)['hex']
273272
# Total balance is given by the sum of outputs of the tx

0 commit comments

Comments
 (0)