aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/util.py
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2024-01-30 19:27:21 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2024-03-11 12:58:20 +0530
commitbf9669af9ccc33dcade09bceb27d6745e9d9a75a (patch)
treed44e0a9af26cede51cff63b56557f37e919fa81d /test/functional/test_framework/util.py
parent4cc99df44aec4d104590aee46cf18318e22a8568 (diff)
test: Rename early key response test and move random_bitflip to util
Early key response test is a special kind of test which requires modified v2 handshake functions. More such tests can be added where v2 handshake functions send incorrect garbage terminator, excess garbage bytes etc.. Hence, rename p2p_v2_earlykey.py to a general test file name - p2p_v2_misbehaving.py. random_bitflip function (used in signature tests prior to this commit) can be used in p2p_v2_misbehaving test to generate wrong garbage terminator, wrong garbage bytes etc.. So, move the function to util.
Diffstat (limited to 'test/functional/test_framework/util.py')
-rw-r--r--test/functional/test_framework/util.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index b4b05b1597..53f4a8ee4d 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -14,6 +14,7 @@ import logging
import os
import pathlib
import platform
+import random
import re
import time
@@ -230,6 +231,12 @@ def ceildiv(a, b):
return -(-a // b)
+def random_bitflip(data):
+ data = list(data)
+ data[random.randrange(len(data))] ^= (1 << (random.randrange(8)))
+ return bytes(data)
+
+
def get_fee(tx_size, feerate_btc_kvb):
"""Calculate the fee in BTC given a feerate is BTC/kvB. Reflects CFeeRate::GetFee"""
feerate_sat_kvb = int(feerate_btc_kvb * Decimal(1e8)) # Fee in sat/kvb as an int to avoid float precision errors