mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
test: refactor: move read_xor_key
/util_xor
helpers to util module
This commit is contained in:
parent
1a41e63575
commit
6b3676be3e
2 changed files with 19 additions and 10 deletions
|
@ -12,7 +12,11 @@
|
|||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.messages import MAGIC_BYTES
|
||||
from test_framework.util import assert_equal
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
read_xor_key,
|
||||
util_xor,
|
||||
)
|
||||
|
||||
|
||||
class ReindexTest(BitcoinTestFramework):
|
||||
|
@ -39,15 +43,7 @@ class ReindexTest(BitcoinTestFramework):
|
|||
# we're generating them rather than getting them from peers), so to
|
||||
# test out-of-order handling, swap blocks 1 and 2 on disk.
|
||||
blk0 = self.nodes[0].blocks_path / "blk00000.dat"
|
||||
with open(self.nodes[0].blocks_path / "xor.dat", "rb") as xor_f:
|
||||
NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size()
|
||||
xor_dat = xor_f.read(NUM_XOR_BYTES)
|
||||
|
||||
def util_xor(data, key, *, offset):
|
||||
data = bytearray(data)
|
||||
for i in range(len(data)):
|
||||
data[i] ^= key[(i + offset) % len(key)]
|
||||
return bytes(data)
|
||||
xor_dat = read_xor_key(node=self.nodes[0])
|
||||
|
||||
with open(blk0, 'r+b') as bf:
|
||||
# Read at least the first few blocks (including genesis)
|
||||
|
|
|
@ -311,6 +311,13 @@ def sha256sum_file(filename):
|
|||
return h.digest()
|
||||
|
||||
|
||||
def util_xor(data, key, *, offset):
|
||||
data = bytearray(data)
|
||||
for i in range(len(data)):
|
||||
data[i] ^= key[(i + offset) % len(key)]
|
||||
return bytes(data)
|
||||
|
||||
|
||||
# RPC/P2P connection constants and functions
|
||||
############################################
|
||||
|
||||
|
@ -508,6 +515,12 @@ def check_node_connections(*, node, num_in, num_out):
|
|||
assert_equal(info["connections_out"], num_out)
|
||||
|
||||
|
||||
def read_xor_key(*, node):
|
||||
with open(node.blocks_path / "xor.dat", "rb") as xor_f:
|
||||
NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size()
|
||||
return xor_f.read(NUM_XOR_BYTES)
|
||||
|
||||
|
||||
# Transaction/Block functions
|
||||
#############################
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue