aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-08-18 09:57:56 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-09-21 10:09:45 +0200
commitfa7a883f5a219d5f3c2f992b090db4e6c279db12 (patch)
tree6b6660bc9fb7f0d00c2a13a30ff47204f7927144 /test
parentfa298971e6890715e2b0b93f2a7f445d32d6622f (diff)
downloadbitcoin-fa7a883f5a219d5f3c2f992b090db4e6c279db12.tar.xz
addrman: Replace assert with throw on corrupt data
Assert should only be used for program internal logic errors, not to sanitize external user input.
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_addrman.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py
index 42afd74ac9..55d3e48c64 100755
--- a/test/functional/feature_addrman.py
+++ b/test/functional/feature_addrman.py
@@ -19,6 +19,7 @@ def serialize_addrman(
format=1,
lowest_compatible=3,
net_magic="regtest",
+ bucket_key=1,
len_new=None,
len_tried=None,
mock_checksum=None,
@@ -29,7 +30,7 @@ def serialize_addrman(
r = MAGIC_BYTES[net_magic]
r += struct.pack("B", format)
r += struct.pack("B", INCOMPATIBILITY_BASE + lowest_compatible)
- r += ser_uint256(1)
+ r += ser_uint256(bucket_key)
r += struct.pack("i", len_new or len(new))
r += struct.pack("i", len_tried or len(tried))
ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
@@ -119,6 +120,14 @@ class AddrmanTest(BitcoinTestFramework):
match=ErrorMatch.FULL_REGEX,
)
+ self.log.info("Check that corrupt addrman cannot be read (failed check)")
+ self.stop_node(0)
+ write_addrman(peers_dat, bucket_key=0)
+ self.nodes[0].assert_start_raises_init_error(
+ expected_msg=init_error("Corrupt data. Consistency check failed with code -16: .*"),
+ match=ErrorMatch.FULL_REGEX,
+ )
+
self.log.info("Check that missing addrman is recreated")
self.stop_node(0)
os.remove(peers_dat)