MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / test_basic

Method test_basic

test/functional/interface_zmq.py:184–262  ·  view source on GitHub ↗
(self, unix = False)

Source from the content-addressed store, hash-verified

182 return subscribers
183
184 def test_basic(self, unix = False):
185 self.log.info(f"Running basic test with {'ipc' if unix else 'tcp'} protocol")
186
187 # Invalid zmq arguments don't take down the node, see #17185.
188 self.restart_node(0, ["-zmqpubrawtx=foo", "-zmqpubhashtx=bar"])
189
190 address = f"tcp://127.0.0.1:{self.zmq_port_base}"
191
192 if unix:
193 # Use the shortest temp path possible since paths may have as little as 92-char limit
194 socket_path = tempfile.NamedTemporaryFile().name
195 address = f"ipc://{socket_path}"
196
197 subs = self.setup_zmq_test([(topic, address) for topic in ["hashblock", "hashtx", "rawblock", "rawtx"]])
198
199 hashblock = subs[0]
200 hashtx = subs[1]
201 rawblock = subs[2]
202 rawtx = subs[3]
203
204 num_blocks = 5
205 self.log.info(f"Generate {num_blocks} blocks (and {num_blocks} coinbase txes)")
206 genhashes = self.generatetoaddress(self.nodes[0], num_blocks, ADDRESS_BCRT1_UNSPENDABLE)
207
208 for x in range(num_blocks):
209 # Should receive the coinbase txid.
210 txid = hashtx.receive()
211
212 # Should receive the coinbase raw transaction.
213 tx = tx_from_hex(rawtx.receive().hex())
214 assert_equal(tx.txid_hex, txid.hex())
215
216 # Should receive the generated raw block.
217 hex = rawblock.receive()
218 block = CBlock()
219 block.deserialize(BytesIO(hex))
220 assert block.is_valid()
221 assert_equal(block.vtx[0].txid_hex, tx.txid_hex)
222 assert_equal(len(block.vtx), 1)
223 assert_equal(genhashes[x], hash256_reversed(hex[:80]).hex())
224
225 # Should receive the generated block hash.
226 hash = hashblock.receive().hex()
227 assert_equal(genhashes[x], hash)
228 # The block should only have the coinbase txid.
229 assert_equal([txid.hex()], self.nodes[1].getblock(hash)["tx"])
230
231
232 self.log.info("Wait for tx from second node")
233 payment_tx = self.wallet.send_self_transfer(from_node=self.nodes[1])
234 payment_txid = payment_tx['txid']
235 self.sync_all()
236 # Should receive the broadcasted txid.
237 txid = hashtx.receive()
238 assert_equal(payment_txid, txid.hex())
239
240 # Should receive the broadcasted raw transaction.
241 hex = rawtx.receive()

Callers 1

run_testMethod · 0.95

Calls 13

setup_zmq_testMethod · 0.95
deserializeMethod · 0.95
is_validMethod · 0.95
tx_from_hexFunction · 0.90
assert_equalFunction · 0.90
CBlockClass · 0.90
hash256_reversedFunction · 0.85
infoMethod · 0.80
receiveMethod · 0.80
send_self_transferMethod · 0.80
sync_allMethod · 0.80
restart_nodeMethod · 0.45

Tested by

no test coverage detected