(self)
| 175 | return subscribers |
| 176 | |
| 177 | def test_basic(self): |
| 178 | |
| 179 | # Invalid zmq arguments don't take down the node, see #17185. |
| 180 | self.restart_node(0, ["-zmqpubrawtx=foo", "-zmqpubhashtx=bar"]) |
| 181 | |
| 182 | address = 'tcp://127.0.0.1:28332' |
| 183 | subs = self.setup_zmq_test([(topic, address) for topic in ["hashblock", "hashtx", "rawblock", "rawtx"]]) |
| 184 | |
| 185 | hashblock = subs[0] |
| 186 | hashtx = subs[1] |
| 187 | rawblock = subs[2] |
| 188 | rawtx = subs[3] |
| 189 | |
| 190 | num_blocks = 5 |
| 191 | self.log.info(f"Generate {num_blocks} blocks (and {num_blocks} coinbase txes)") |
| 192 | genhashes = self.generatetoaddress(self.nodes[0], num_blocks, ADDRESS_BCRT1_UNSPENDABLE) |
| 193 | |
| 194 | for x in range(num_blocks): |
| 195 | # Should receive the coinbase txid. |
| 196 | txid = hashtx.receive() |
| 197 | |
| 198 | # Should receive the coinbase raw transaction. |
| 199 | hex = rawtx.receive() |
| 200 | tx = CTransaction() |
| 201 | tx.deserialize(BytesIO(hex)) |
| 202 | tx.calc_sha256() |
| 203 | assert_equal(tx.hash, txid.hex()) |
| 204 | |
| 205 | # Should receive the generated raw block. |
| 206 | # 79 bytes, last byte is saying block solution is "", ellide this for hash |
| 207 | block = rawblock.receive() |
| 208 | assert_equal(genhashes[x], hash256_reversed(block[:78]).hex()) |
| 209 | |
| 210 | # Should receive the generated block hash. |
| 211 | hash = hashblock.receive().hex() |
| 212 | assert_equal(genhashes[x], hash) |
| 213 | # The block should only have the coinbase txid. |
| 214 | assert_equal([txid.hex()], self.nodes[1].getblock(hash)["tx"]) |
| 215 | |
| 216 | |
| 217 | if self.is_wallet_compiled(): |
| 218 | self.log.info("Wait for tx from second node") |
| 219 | payment_txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1.0) |
| 220 | self.sync_all() |
| 221 | |
| 222 | # Should receive the broadcasted txid. |
| 223 | txid = hashtx.receive() |
| 224 | assert_equal(payment_txid, txid.hex()) |
| 225 | |
| 226 | # Should receive the broadcasted raw transaction. |
| 227 | hex = rawtx.receive() |
| 228 | assert_equal(payment_txid, hash256_reversed(hex).hex()) |
| 229 | |
| 230 | # Mining the block with this tx should result in second notification |
| 231 | # after coinbase tx notification |
| 232 | self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE) |
| 233 | hashtx.receive() |
| 234 | txid = hashtx.receive() |
no test coverage detected