From faf3cd659a72473a1aa73c4367a145f4ec64f146 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 7 Feb 2024 11:30:21 +0100 Subject: [PATCH 1/4] test: Normalize struct.pack format * Add () around some int values * Remove b-prefix from strings This is needed for the scripted diff to work. --- test/functional/feature_addrman.py | 10 +++++----- test/functional/test_framework/script.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index 95d33d62ea..c17b697ec1 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -29,14 +29,14 @@ def serialize_addrman( INCOMPATIBILITY_BASE = 32 r = MAGIC_BYTES[net_magic] r += struct.pack("B", format) - r += struct.pack("B", INCOMPATIBILITY_BASE + lowest_compatible) + r += struct.pack("B", (INCOMPATIBILITY_BASE + lowest_compatible)) r += ser_uint256(bucket_key) - r += struct.pack(" Date: Wed, 7 Feb 2024 11:20:41 +0100 Subject: [PATCH 2/4] test: Use int.to_bytes over struct packing This is done in prepration for the scripted diff, which can not deal with those lines. --- test/functional/p2p_invalid_messages.py | 3 +-- test/functional/test_framework/script.py | 4 ++-- test/functional/wallet_balance.py | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index 40a69936bc..adcbb4fd05 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -5,7 +5,6 @@ """Test node responses to invalid network messages.""" import random -import struct import time from test_framework.messages import ( @@ -233,7 +232,7 @@ class InvalidMessagesTest(BitcoinTestFramework): '208d')) # port def test_addrv2_unrecognized_network(self): - now_hex = struct.pack(' Date: Wed, 7 Feb 2024 11:26:05 +0100 Subject: [PATCH 3/4] scripted-diff: test: Use int.to_bytes over struct packing -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's!struct.pack\(.H., (.*)\)!\1.to_bytes(2, "big")!g' $( git grep -l struct.pack ) -END VERIFY SCRIPT- --- contrib/seeds/generate-seeds.py | 6 ++--- contrib/signet/miner | 4 ++-- test/functional/feature_addrman.py | 12 +++++----- test/functional/p2p_segwit.py | 12 +++++----- test/functional/test_framework/p2p.py | 2 +- test/functional/test_framework/script.py | 28 ++++++++++++------------ 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py index e921757802..c84be1055d 100755 --- a/contrib/seeds/generate-seeds.py +++ b/contrib/seeds/generate-seeds.py @@ -115,7 +115,7 @@ def parse_spec(s): def ser_compact_size(l): r = b"" if l < 253: - r = struct.pack("B", l) + r = l.to_bytes(1, "little") elif l < 0x10000: r = struct.pack("H', spec[2]) + r += spec[2].to_bytes(2, "big") return r def process_nodes(g, f, structname): diff --git a/contrib/signet/miner b/contrib/signet/miner index e5daf9f993..7b7b3feb39 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -52,10 +52,10 @@ def signet_txs(block, challenge): mroot = block.get_merkle_root(hashes) sd = b"" - sd += struct.pack(" Date: Wed, 7 Feb 2024 13:19:37 +0100 Subject: [PATCH 4/4] test: Remove struct.pack from almost all places --- contrib/seeds/generate-seeds.py | 7 +++---- test/functional/feature_addrman.py | 1 - test/functional/feature_block.py | 3 +-- test/functional/p2p_segwit.py | 1 - test/functional/test_framework/script.py | 1 - 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py index c84be1055d..f67e7b0f4c 100755 --- a/contrib/seeds/generate-seeds.py +++ b/contrib/seeds/generate-seeds.py @@ -29,7 +29,6 @@ These should be pasted into `src/chainparamsseeds.h`. from base64 import b32decode from enum import Enum -import struct import sys import os import re @@ -117,11 +116,11 @@ def ser_compact_size(l): if l < 253: r = l.to_bytes(1, "little") elif l < 0x10000: - r = struct.pack("