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