aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-07-19 17:41:16 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-07-19 17:42:35 +0200
commitfaf43378e223c563b0741c28a4b5406f471c1332 (patch)
treee50fcfa9f55e36744914f8679f33f2efe0930431
parentfdc1ca389646a55c4d9cb2a79feaa69f90b18c67 (diff)
downloadbitcoin-faf43378e223c563b0741c28a4b5406f471c1332.tar.xz
refactor: move helper `random_bytes` to util library
Can be easily reviewed with `--color-moved=dimmed-zebra`.
-rwxr-xr-xtest/functional/feature_taproot.py10
-rw-r--r--test/functional/test_framework/util.py8
2 files changed, 13 insertions, 5 deletions
diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py
index 0e44038196..777f873f70 100755
--- a/test/functional/feature_taproot.py
+++ b/test/functional/feature_taproot.py
@@ -91,7 +91,11 @@ from test_framework.script_util import (
script_to_p2wsh_script,
)
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_raises_rpc_error, assert_equal
+from test_framework.util import (
+ assert_raises_rpc_error,
+ assert_equal,
+ random_bytes,
+)
from test_framework.key import generate_privkey, compute_xonly_pubkey, sign_schnorr, tweak_add_privkey, ECKey
from test_framework.address import (
hash160,
@@ -566,10 +570,6 @@ def random_checksig_style(pubkey):
ret = CScript([pubkey, opcode])
return bytes(ret)
-def random_bytes(n):
- """Return a random bytes object of length n."""
- return bytes(random.getrandbits(8) for i in range(n))
-
def bitflipper(expr):
"""Return a callable that evaluates expr and returns it with a random bitflip."""
def fn(ctx):
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 58528b7858..fe61ff95f8 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -12,6 +12,7 @@ import inspect
import json
import logging
import os
+import random
import re
import time
import unittest
@@ -286,6 +287,13 @@ def sha256sum_file(filename):
d = f.read(4096)
return h.digest()
+
+# TODO: Remove and use random.randbytes(n) instead, available in Python 3.9
+def random_bytes(n):
+ """Return a random bytes object of length n."""
+ return bytes(random.getrandbits(8) for i in range(n))
+
+
# RPC/P2P connection constants and functions
############################################