Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_zmq.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the ZMQ notification interface.""" | """Test the ZMQ notification interface.""" | ||||
import configparser | import configparser | ||||
import struct | import struct | ||||
from io import BytesIO | |||||
from test_framework.test_framework import BitcoinTestFramework, SkipTest | from test_framework.test_framework import BitcoinTestFramework, SkipTest | ||||
from test_framework.messages import CTransaction | |||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
bytes_to_hex_str, | bytes_to_hex_str, | ||||
hash256, | hash256, | ||||
) | ) | ||||
class ZMQSubscriber: | class ZMQSubscriber: | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def _zmq_test(self): | ||||
self.sync_all() | self.sync_all() | ||||
for x in range(num_blocks): | for x in range(num_blocks): | ||||
# Should receive the coinbase txid. | # Should receive the coinbase txid. | ||||
txid = self.hashtx.receive() | txid = self.hashtx.receive() | ||||
# Should receive the coinbase raw transaction. | # Should receive the coinbase raw transaction. | ||||
hex = self.rawtx.receive() | hex = self.rawtx.receive() | ||||
assert_equal(hash256(hex), txid) | tx = CTransaction() | ||||
tx.deserialize(BytesIO(hex)) | |||||
tx.calc_sha256() | |||||
assert_equal(tx.hash, bytes_to_hex_str(txid)) | |||||
# Should receive the generated block hash. | # Should receive the generated block hash. | ||||
hash = bytes_to_hex_str(self.hashblock.receive()) | hash = bytes_to_hex_str(self.hashblock.receive()) | ||||
assert_equal(genhashes[x], hash) | assert_equal(genhashes[x], hash) | ||||
# The block should only have the coinbase txid. | # The block should only have the coinbase txid. | ||||
assert_equal([bytes_to_hex_str(txid)], | assert_equal([bytes_to_hex_str(txid)], | ||||
self.nodes[1].getblock(hash)["tx"]) | self.nodes[1].getblock(hash)["tx"]) | ||||
Show All 20 Lines |