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.
pull/29431/head
stratospher 9 months ago
parent 4cc99df44a
commit bf9669af9c

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

@ -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

@ -264,7 +264,7 @@ BASE_SCRIPTS = [
'p2p_invalid_tx.py --v2transport',
'p2p_v2_transport.py',
'p2p_v2_encrypted.py',
'p2p_v2_earlykeyresponse.py',
'p2p_v2_misbehaving.py',
'example_test.py',
'mempool_accept_v3.py',
'wallet_txn_doublespend.py --legacy-wallet',

Loading…
Cancel
Save