scripted-diff: test: Use int.to_bytes over struct packing

-BEGIN VERIFY SCRIPT-
 sed -i --regexp-extended 's!struct.pack\(.<?B., (.*)\)!\1.to_bytes(1, "little")!g'             $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<I., (.*)\)!\1.to_bytes(4, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<H., (.*)\)!\1.to_bytes(2, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<i., (.*)\)!\1.to_bytes(4, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<q., (.*)\)!\1.to_bytes(8, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.>H., (.*)\)!\1.to_bytes(2, "big")!g'                 $( git grep -l struct.pack )
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke committed 2024-05-07 15:40:47 +02:00
1 parent faf2a975ad
commit fa826db477
6 files changed
+32 -32

No files matched your search

+6 -6
View File
@@ -1165,16 +1165,16 @@ class SegWitTest(BitcoinTestFramework):
if not self.wit.is_null():
flags |= 1
r = b""
r += struct.pack("<i", self.nVersion)
r += self.nVersion.to_bytes(4, "little", signed=True)
if flags:
dummy = []
r += ser_vector(dummy)
r += struct.pack("<B", flags)
r += flags.to_bytes(1, "little")
r += ser_vector(self.vin)
r += ser_vector(self.vout)
if flags & 1:
r += self.wit.serialize()
r += struct.pack("<I", self.nLockTime)
r += self.nLockTime.to_bytes(4, "little")
return r
tx2 = BrokenCTransaction()
@@ -1976,11 +1976,11 @@ class SegWitTest(BitcoinTestFramework):
def serialize_with_bogus_witness(tx):
flags = 3
r = b""
r += struct.pack("<i", tx.nVersion)
r += tx.nVersion.to_bytes(4, "little", signed=True)
if flags:
dummy = []
r += ser_vector(dummy)
r += struct.pack("<B", flags)
r += flags.to_bytes(1, "little")
r += ser_vector(tx.vin)
r += ser_vector(tx.vout)
if flags & 1:
@@ -1990,7 +1990,7 @@ class SegWitTest(BitcoinTestFramework):
for _ in range(len(tx.wit.vtxinwit), len(tx.vin)):
tx.wit.vtxinwit.append(CTxInWitness())
r += tx.wit.serialize()
r += struct.pack("<I", tx.nLockTime)
r += tx.nLockTime.to_bytes(4, "little")
return r
class msg_bogus_tx(msg_tx):