aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_reindex.py
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-06-30 12:42:47 +0200
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2024-07-26 17:30:53 +0200
commitfa359255fe6b4de5f26784bfc147dbfb58bef116 (patch)
tree74c593230af3b43fb84cd036a444259f76043bad /test/functional/feature_reindex.py
parentfa7f7ac040a9467c307b20e77dc47c87d7377ded (diff)
Add -blocksxor boolean option
Diffstat (limited to 'test/functional/feature_reindex.py')
-rwxr-xr-xtest/functional/feature_reindex.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py
index 50a9ae1c06..504b3dfff4 100755
--- a/test/functional/feature_reindex.py
+++ b/test/functional/feature_reindex.py
@@ -39,9 +39,19 @@ 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)
+
with open(blk0, 'r+b') as bf:
# Read at least the first few blocks (including genesis)
- b = bf.read(2000)
+ b = util_xor(bf.read(2000), xor_dat, offset=0)
# Find the offsets of blocks 2, 3, and 4 (the first 3 blocks beyond genesis)
# by searching for the regtest marker bytes (see pchMessageStart).
@@ -55,12 +65,12 @@ class ReindexTest(BitcoinTestFramework):
b4_start = find_block(b, b3_start)
# Blocks 2 and 3 should be the same size.
- assert_equal(b3_start-b2_start, b4_start-b3_start)
+ assert_equal(b3_start - b2_start, b4_start - b3_start)
# Swap the second and third blocks (don't disturb the genesis block).
bf.seek(b2_start)
- bf.write(b[b3_start:b4_start])
- bf.write(b[b2_start:b3_start])
+ bf.write(util_xor(b[b3_start:b4_start], xor_dat, offset=b2_start))
+ bf.write(util_xor(b[b2_start:b3_start], xor_dat, offset=b3_start))
# The reindexing code should detect and accommodate out of order blocks.
with self.nodes[0].assert_debug_log([