aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-07-16 01:56:56 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-07-19 15:40:51 +0200
commit7c0dfec2dd9998932d13dd183c3ce4b22bd5851b (patch)
tree4924be6c5d5e2860c6366ff33d536fca2b320e57 /test/functional/test_framework
parent597a4b35f6e11d0ec5181e0d4d2d8f9bbf59898a (diff)
downloadbitcoin-7c0dfec2dd9998932d13dd183c3ce4b22bd5851b.tar.xz
refactor: move `from_binary` helper from signet miner to test framework
Can be easily reviewed with `--color-moved=dimmed-zebra`.
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/messages.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py
index e6d9f9ae3a..4a68312379 100755
--- a/test/functional/test_framework/messages.py
+++ b/test/functional/test_framework/messages.py
@@ -208,6 +208,20 @@ def tx_from_hex(hex_string):
return from_hex(CTransaction(), hex_string)
+# like from_hex, but without the hex part
+def from_binary(cls, stream):
+ """deserialize a binary stream (or bytes object) into an object"""
+ # handle bytes object by turning it into a stream
+ was_bytes = isinstance(stream, bytes)
+ if was_bytes:
+ stream = BytesIO(stream)
+ obj = cls()
+ obj.deserialize(stream)
+ if was_bytes:
+ assert len(stream.read()) == 0
+ return obj
+
+
# Objects that map to bitcoind objects, which can be serialized/deserialized