mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
test: Use int.to_bytes over struct packing
This is done in prepration for the scripted diff, which can not deal with those lines.
This commit is contained in:
parent
faf3cd659a
commit
faf2a975ad
3 changed files with 5 additions and 7 deletions
|
@ -5,7 +5,6 @@
|
||||||
"""Test node responses to invalid network messages."""
|
"""Test node responses to invalid network messages."""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import struct
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
|
@ -233,7 +232,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||||
'208d')) # port
|
'208d')) # port
|
||||||
|
|
||||||
def test_addrv2_unrecognized_network(self):
|
def test_addrv2_unrecognized_network(self):
|
||||||
now_hex = struct.pack('<I', int(time.time())).hex()
|
now_hex = int(time.time()).to_bytes(4, "little").hex()
|
||||||
self.test_addrv2('unrecognized network',
|
self.test_addrv2('unrecognized network',
|
||||||
[
|
[
|
||||||
'received: addrv2 (25 bytes)',
|
'received: addrv2 (25 bytes)',
|
||||||
|
|
|
@ -800,13 +800,13 @@ def BIP341_sha_prevouts(txTo):
|
||||||
return sha256(b"".join(i.prevout.serialize() for i in txTo.vin))
|
return sha256(b"".join(i.prevout.serialize() for i in txTo.vin))
|
||||||
|
|
||||||
def BIP341_sha_amounts(spent_utxos):
|
def BIP341_sha_amounts(spent_utxos):
|
||||||
return sha256(b"".join(struct.pack("<q", u.nValue) for u in spent_utxos))
|
return sha256(b"".join(u.nValue.to_bytes(8, "little", signed=True) for u in spent_utxos))
|
||||||
|
|
||||||
def BIP341_sha_scriptpubkeys(spent_utxos):
|
def BIP341_sha_scriptpubkeys(spent_utxos):
|
||||||
return sha256(b"".join(ser_string(u.scriptPubKey) for u in spent_utxos))
|
return sha256(b"".join(ser_string(u.scriptPubKey) for u in spent_utxos))
|
||||||
|
|
||||||
def BIP341_sha_sequences(txTo):
|
def BIP341_sha_sequences(txTo):
|
||||||
return sha256(b"".join(struct.pack("<I", i.nSequence) for i in txTo.vin))
|
return sha256(b"".join(i.nSequence.to_bytes(4, "little") for i in txTo.vin))
|
||||||
|
|
||||||
def BIP341_sha_outputs(txTo):
|
def BIP341_sha_outputs(txTo):
|
||||||
return sha256(b"".join(o.serialize() for o in txTo.vout))
|
return sha256(b"".join(o.serialize() for o in txTo.vout))
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test the wallet balance RPC methods."""
|
"""Test the wallet balance RPC methods."""
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import struct
|
|
||||||
|
|
||||||
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
|
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
|
||||||
from test_framework.blocktools import COINBASE_MATURITY
|
from test_framework.blocktools import COINBASE_MATURITY
|
||||||
|
@ -266,8 +265,8 @@ class WalletTest(BitcoinTestFramework):
|
||||||
tx_orig = self.nodes[0].gettransaction(txid)['hex']
|
tx_orig = self.nodes[0].gettransaction(txid)['hex']
|
||||||
# Increase fee by 1 coin
|
# Increase fee by 1 coin
|
||||||
tx_replace = tx_orig.replace(
|
tx_replace = tx_orig.replace(
|
||||||
struct.pack("<q", 99 * 10**8).hex(),
|
(99 * 10**8).to_bytes(8, "little", signed=True).hex(),
|
||||||
struct.pack("<q", 98 * 10**8).hex(),
|
(98 * 10**8).to_bytes(8, "little", signed=True).hex(),
|
||||||
)
|
)
|
||||||
tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)['hex']
|
tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)['hex']
|
||||||
# Total balance is given by the sum of outputs of the tx
|
# Total balance is given by the sum of outputs of the tx
|
||||||
|
|
Loading…
Add table
Reference in a new issue