Skip to content

Commit fa52e13

Browse files
author
MarcoFalke
committed
test: Remove struct.pack from almost all places
1 parent fa826db commit fa52e13

File tree

5 files changed

+4
-9
lines changed

5 files changed

+4
-9
lines changed

contrib/seeds/generate-seeds.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
from base64 import b32decode
3131
from enum import Enum
32-
import struct
3332
import sys
3433
import os
3534
import re
@@ -117,11 +116,11 @@ def ser_compact_size(l):
117116
if l < 253:
118117
r = l.to_bytes(1, "little")
119118
elif l < 0x10000:
120-
r = struct.pack("<BH", 253, l)
119+
r = (253).to_bytes(1, "little") + l.to_bytes(2, "little")
121120
elif l < 0x100000000:
122-
r = struct.pack("<BI", 254, l)
121+
r = (254).to_bytes(1, "little") + l.to_bytes(4, "little")
123122
else:
124-
r = struct.pack("<BQ", 255, l)
123+
r = (255).to_bytes(1, "little") + l.to_bytes(8, "little")
125124
return r
126125

127126
def bip155_serialize(spec):

test/functional/feature_addrman.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import os
88
import re
9-
import struct
109

1110
from test_framework.messages import ser_uint256, hash256, MAGIC_BYTES
1211
from test_framework.netutil import ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT, ADDRMAN_BUCKET_SIZE

test/functional/feature_block.py

Lines changed: 1 addition & 2 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 block processing."""
66
import copy
7-
import struct
87
import time
98

109
from test_framework.blocktools import (
@@ -67,7 +66,7 @@ def initialize(self, base_block):
6766
def serialize(self, with_witness=False):
6867
r = b""
6968
r += super(CBlock, self).serialize()
70-
r += struct.pack("<BQ", 255, len(self.vtx))
69+
r += (255).to_bytes(1, "little") + len(self.vtx).to_bytes(8, "little")
7170
for tx in self.vtx:
7271
if with_witness:
7372
r += tx.serialize_with_witness()

test/functional/p2p_segwit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Test segwit transactions and blocks on P2P network."""
66
from decimal import Decimal
77
import random
8-
import struct
98
import time
109

1110
from test_framework.blocktools import (

test/functional/test_framework/script.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
from collections import namedtuple
11-
import struct
1211
import unittest
1312

1413
from .key import TaggedHash, tweak_add_pubkey, compute_xonly_pubkey

0 commit comments

Comments
 (0)