Skip to content

Commit bf9669a

Browse files
committed
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.
1 parent 4cc99df commit bf9669a

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

test/functional/test_framework/key.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import unittest
1515

1616
from test_framework.crypto import secp256k1
17+
from test_framework.util import random_bitflip
1718

1819
# Point with no known discrete log.
1920
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
@@ -292,11 +293,6 @@ def sign_schnorr(key, msg, aux=None, flip_p=False, flip_r=False):
292293
class TestFrameworkKey(unittest.TestCase):
293294
def test_ecdsa_and_schnorr(self):
294295
"""Test the Python ECDSA and Schnorr implementations."""
295-
def random_bitflip(sig):
296-
sig = list(sig)
297-
sig[random.randrange(len(sig))] ^= (1 << (random.randrange(8)))
298-
return bytes(sig)
299-
300296
byte_arrays = [generate_privkey() for _ in range(3)] + [v.to_bytes(32, 'big') for v in [0, ORDER - 1, ORDER, 2**256 - 1]]
301297
keys = {}
302298
for privkey_bytes in byte_arrays: # build array of key/pubkey pairs

test/functional/test_framework/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import os
1515
import pathlib
1616
import platform
17+
import random
1718
import re
1819
import time
1920

@@ -230,6 +231,12 @@ def ceildiv(a, b):
230231
return -(-a // b)
231232

232233

234+
def random_bitflip(data):
235+
data = list(data)
236+
data[random.randrange(len(data))] ^= (1 << (random.randrange(8)))
237+
return bytes(data)
238+
239+
233240
def get_fee(tx_size, feerate_btc_kvb):
234241
"""Calculate the fee in BTC given a feerate is BTC/kvB. Reflects CFeeRate::GetFee"""
235242
feerate_sat_kvb = int(feerate_btc_kvb * Decimal(1e8)) # Fee in sat/kvb as an int to avoid float precision errors

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
'p2p_invalid_tx.py --v2transport',
265265
'p2p_v2_transport.py',
266266
'p2p_v2_encrypted.py',
267-
'p2p_v2_earlykeyresponse.py',
267+
'p2p_v2_misbehaving.py',
268268
'example_test.py',
269269
'mempool_accept_v3.py',
270270
'wallet_txn_doublespend.py --legacy-wallet',

0 commit comments

Comments
 (0)