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