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

Method run_test

test/functional/example_test.py:142–219  ·  view source on GitHub ↗

Main test logic

(self)

Source from the content-addressed store, hash-verified

140 self.log.info("Running custom_method")
141
142 def run_test(self):
143 """Main test logic"""
144
145 # Create P2P connections will wait for a verack to make sure the connection is fully up
146 peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())
147
148 # Generating a block on one of the nodes will get us out of IBD
149 blocks = [int(self.generate(self.nodes[0], sync_fun=lambda: self.sync_all(self.nodes[0:2]), nblocks=1)[0], 16)]
150
151 # Notice above how we called an RPC by calling a method with the same
152 # name on the node object. Notice also how we used a keyword argument
153 # to specify a named RPC argument. Neither of those are defined on the
154 # node object. Instead there's some __getattr__() magic going on under
155 # the covers to dispatch unrecognised attribute calls to the RPC
156 # interface.
157
158 # Logs are nice. Do plenty of them. They can be used in place of comments for
159 # breaking the test into sub-sections.
160 self.log.info("Starting test!")
161
162 self.log.info("Calling a custom function")
163 custom_function()
164
165 self.log.info("Calling a custom method")
166 self.custom_method()
167
168 self.log.info("Create some blocks")
169 self.tip = int(self.nodes[0].getbestblockhash(), 16)
170 self.block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1
171
172 height = self.nodes[0].getblockcount()
173
174 for _ in range(10):
175 # Use the blocktools functionality to manually build a block.
176 # Calling the generate() rpc is easier, but this allows us to exactly
177 # control the blocks and transactions.
178 block = create_block(self.tip, height=height+1, ntime=self.block_time)
179 block.solve()
180 block_message = msg_block(block)
181 # Send message is used to send a P2P message to the node over our P2PInterface
182 peer_messaging.send_without_ping(block_message)
183 self.tip = block.hash_int
184 blocks.append(self.tip)
185 self.block_time += 1
186 height += 1
187
188 self.log.info("Wait for node1 to reach current tip (height 11) using RPC")
189 self.nodes[1].waitforblockheight(11)
190
191 self.log.info("Connect node2 and node1")
192 self.connect_nodes(1, 2)
193
194 self.log.info("Wait for node2 to receive all the blocks from node1")
195 self.sync_all()
196
197 self.log.info("Add P2P connection to node2")
198 self.nodes[0].disconnect_p2ps()
199

Callers

nothing calls this directly

Calls 15

custom_methodMethod · 0.95
create_blockFunction · 0.90
CInvClass · 0.90
assert_equalFunction · 0.90
custom_functionFunction · 0.85
msg_blockClass · 0.85
msg_getdataClass · 0.85
add_p2p_connectionMethod · 0.80
sync_allMethod · 0.80
infoMethod · 0.80
solveMethod · 0.80
send_without_pingMethod · 0.80

Tested by

no test coverage detected