MCPcopy Create free account
hub / github.com/ElementsProject/elements / test_basic

Method test_basic

test/functional/interface_zmq.py:177–246  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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()

Callers 1

run_testMethod · 0.95

Calls 13

setup_zmq_testMethod · 0.95
deserializeMethod · 0.95
calc_sha256Method · 0.95
CTransactionClass · 0.90
assert_equalFunction · 0.90
hash256_reversedFunction · 0.85
infoMethod · 0.80
hexMethod · 0.80
restart_nodeMethod · 0.45
generatetoaddressMethod · 0.45
receiveMethod · 0.45
is_wallet_compiledMethod · 0.45

Tested by

no test coverage detected