Skip to content

Commit faf4337

Browse files
committed
refactor: move helper random_bytes to util library
Can be easily reviewed with `--color-moved=dimmed-zebra`.
1 parent fdc1ca3 commit faf4337

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

test/functional/feature_taproot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@
9191
script_to_p2wsh_script,
9292
)
9393
from test_framework.test_framework import BitcoinTestFramework
94-
from test_framework.util import assert_raises_rpc_error, assert_equal
94+
from test_framework.util import (
95+
assert_raises_rpc_error,
96+
assert_equal,
97+
random_bytes,
98+
)
9599
from test_framework.key import generate_privkey, compute_xonly_pubkey, sign_schnorr, tweak_add_privkey, ECKey
96100
from test_framework.address import (
97101
hash160,
@@ -566,10 +570,6 @@ def random_checksig_style(pubkey):
566570
ret = CScript([pubkey, opcode])
567571
return bytes(ret)
568572

569-
def random_bytes(n):
570-
"""Return a random bytes object of length n."""
571-
return bytes(random.getrandbits(8) for i in range(n))
572-
573573
def bitflipper(expr):
574574
"""Return a callable that evaluates expr and returns it with a random bitflip."""
575575
def fn(ctx):

test/functional/test_framework/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import json
1313
import logging
1414
import os
15+
import random
1516
import re
1617
import time
1718
import unittest
@@ -286,6 +287,13 @@ def sha256sum_file(filename):
286287
d = f.read(4096)
287288
return h.digest()
288289

290+
291+
# TODO: Remove and use random.randbytes(n) instead, available in Python 3.9
292+
def random_bytes(n):
293+
"""Return a random bytes object of length n."""
294+
return bytes(random.getrandbits(8) for i in range(n))
295+
296+
289297
# RPC/P2P connection constants and functions
290298
############################################
291299

0 commit comments

Comments
 (0)