MCPcopy Create free account
hub / github.com/RavenProject/Ravencoin / run_test

Method run_test

test/functional/example_test.py:124–191  ·  view source on GitHub ↗

Main test logic

(self)

Source from the content-addressed store, hash-verified

122 self.log.info("Running custom_method")
123
124 def run_test(self):
125 """Main test logic"""
126
127 # Create a P2P connection to one of the nodes
128 node0 = BaseNode()
129 connections = [NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0)]
130 node0.add_connection(connections[0])
131
132 # Start up network handling in another thread. This needs to be called
133 # after the P2P connections have been created.
134 NetworkThread().start()
135 # wait_for_verack ensures that the P2P connection is fully up.
136 node0.wait_for_verack()
137
138 # Generating a block on one of the nodes will get us out of IBD
139 blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
140 self.sync_all([self.nodes[0:1]])
141
142 # Notice above how we called an RPC by calling a method with the same
143 # name on the node object. Notice also how we used a keyword argument
144 # to specify a named RPC argument. Neither of those are defined on the
145 # node object. Instead there's some __getattr__() magic going on under
146 # the covers to dispatch unrecognised attribute calls to the RPC
147 # interface.
148
149 # Logs are nice. Do plenty of them. They can be used in place of comments for
150 # breaking the test into sub-sections.
151 self.log.info("Starting test!")
152
153 self.log.info("Calling a custom function")
154 custom_function()
155
156 self.log.info("Calling a custom method")
157 self.custom_method()
158
159 self.log.info("Create some blocks")
160 self.tip = int(self.nodes[0].getbestblockhash(), 16)
161 self.block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1
162
163 self.nodes[0].generate(10)
164
165 self.log.info("Wait for node1 to reach current tip (height 11) using RPC")
166 self.nodes[1].waitforblockheight(11)
167
168 self.log.info("Connect node2 and node1")
169 connect_nodes(self.nodes[1], 2)
170
171 self.log.info("Add P2P connection to node2")
172 node2 = BaseNode()
173 connections.append(NodeConn('127.0.0.1', p2p_port(2), self.nodes[2], node2))
174 node2.add_connection(connections[1])
175 node2.wait_for_verack()
176
177 self.log.info("Wait for node2 reach current tip. Test that it has propagated all the blocks to us")
178
179 getdata_request = MsgGetdata()
180 for block in blocks:
181 getdata_request.inv.append(CInv(2, block))

Callers

nothing calls this directly

Calls 15

custom_methodMethod · 0.95
NodeConnClass · 0.90
p2p_portFunction · 0.90
NetworkThreadClass · 0.90
connect_nodesFunction · 0.90
assert_equalFunction · 0.90
custom_functionFunction · 0.85
MsgGetdataClass · 0.85
add_connectionMethod · 0.80
wait_for_verackMethod · 0.80
generateMethod · 0.80
sync_allMethod · 0.80

Tested by

no test coverage detected