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