Skip to content

Commit 05ccbe9

Browse files
committed
Merge #16598: test: Remove confusing hash256 function in util
afc0966 Moved and renamed hash256 from util.py to zmq_interface.py (Elichai Turkel) Pull request description: Right now there are two `hash256(bytes)` in the test framework: first: https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L186 second: https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/messages.py#L60 While they have the same name they're actually doing different things, one just does a sha256d and the other sha256d and reverses the bytes. so I renamed the second one to be `hash256r` to signify that it's hash256 reversed. ACKs for top commit: MarcoFalke: unsigned ACK afc0966 fanquake: ACK afc0966 Tree-SHA512: fb0e2db6f09c0248d92f2fd72d05a78cec1bebb44449239dbeecefa62cf4bd01d180b2e6dbcee48a8a9cea79a909e224256cabdd0739f334c2943647fe0c5fe4
2 parents c3b605c + afc0966 commit 05ccbe9

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

test/functional/interface_zmq.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
99
from test_framework.test_framework import BitcoinTestFramework
10-
from test_framework.messages import CTransaction
11-
from test_framework.util import (
12-
assert_equal,
13-
hash256,
14-
)
10+
from test_framework.messages import CTransaction, hash256
11+
from test_framework.util import assert_equal
1512
from io import BytesIO
1613

1714
ADDRESS = "tcp://127.0.0.1:28332"
1815

16+
def hash256_reversed(byte_str):
17+
return hash256(byte_str)[::-1]
18+
1919
class ZMQSubscriber:
2020
def __init__(self, socket, topic):
2121
self.sequence = 0
@@ -103,7 +103,7 @@ def _zmq_test(self):
103103

104104
# Should receive the generated raw block.
105105
block = self.rawblock.receive()
106-
assert_equal(genhashes[x], hash256(block[:80]).hex())
106+
assert_equal(genhashes[x], hash256_reversed(block[:80]).hex())
107107

108108
if self.is_wallet_compiled():
109109
self.log.info("Wait for tx from second node")
@@ -116,7 +116,7 @@ def _zmq_test(self):
116116

117117
# Should receive the broadcasted raw transaction.
118118
hex = self.rawtx.receive()
119-
assert_equal(payment_txid, hash256(hex).hex())
119+
assert_equal(payment_txid, hash256_reversed(hex).hex())
120120

121121

122122
self.log.info("Test the getzmqnotifications RPC")

test/functional/test_framework/util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from base64 import b64encode
88
from binascii import unhexlify
99
from decimal import Decimal, ROUND_DOWN
10-
import hashlib
1110
import inspect
1211
import json
1312
import logging
@@ -183,12 +182,6 @@ def check_json_precision():
183182
def count_bytes(hex_string):
184183
return len(bytearray.fromhex(hex_string))
185184

186-
def hash256(byte_str):
187-
sha256 = hashlib.sha256()
188-
sha256.update(byte_str)
189-
sha256d = hashlib.sha256()
190-
sha256d.update(sha256.digest())
191-
return sha256d.digest()[::-1]
192185

193186
def hex_str_to_bytes(hex_str):
194187
return unhexlify(hex_str.encode('ascii'))

0 commit comments

Comments
 (0)