From 64b80d5c5bc1311cd2fb188f2d84aff6704e27d7 Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Thu, 28 Sep 2023 13:58:18 +0200 Subject: [PATCH 1/2] test: simplify feature_init --- test/functional/feature_init.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 94f5116f9b0..1b657e2c47a 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -133,15 +133,12 @@ class InitStressTest(BitcoinTestFramework): for target_file in target_files: self.log.info(f"Perturbing file to ensure failure {target_file}") - with open(target_file, "rb") as tf_read: - contents = tf_read.read() - tweaked_contents = bytearray(contents) + with open(target_file, "r+b") as tf: # Since the genesis block is not checked by -checkblocks, the # perturbation window must be chosen such that a higher block # in blk*.dat is affected. - tweaked_contents[150:350] = b'1' * 200 - with open(target_file, "wb") as tf_write: - tf_write.write(bytes(tweaked_contents)) + tf.seek(150) + tf.write(b'1' * 200) start_expecting_error(err_fragment) From 5ab6419f380cc0a8cde78b125f3eeee5fcba43ae Mon Sep 17 00:00:00 2001 From: L0la L33tz Date: Sun, 8 Oct 2023 16:58:45 +0200 Subject: [PATCH 2/2] test: randomized perturbing in feature_init --- test/functional/feature_init.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 1b657e2c47a..37ef3de4dda 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -5,6 +5,7 @@ """Stress tests related to node initialization.""" import os from pathlib import Path +from random import randint import shutil from test_framework.test_framework import BitcoinTestFramework, SkipTest @@ -137,8 +138,8 @@ class InitStressTest(BitcoinTestFramework): # Since the genesis block is not checked by -checkblocks, the # perturbation window must be chosen such that a higher block # in blk*.dat is affected. - tf.seek(150) - tf.write(b'1' * 200) + tf.seek(randint (150, 15000)) + tf.write(b'1' * randint(20, 2000)) start_expecting_error(err_fragment)