(self)
| 35 | self.skip_if_no_wallet() |
| 36 | |
| 37 | def run_test(self): |
| 38 | node = self.nodes[0] |
| 39 | |
| 40 | self.log.info('getmininginfo') |
| 41 | mining_info = node.getmininginfo() |
| 42 | assert_equal(mining_info['blocks'], 200) |
| 43 | assert_equal(mining_info['chain'], 'regtest') |
| 44 | assert_equal(mining_info['currentblocktx'], 0) |
| 45 | assert_equal(mining_info['currentblockweight'], 0) |
| 46 | assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10')) |
| 47 | assert_equal(mining_info['networkhashps'], Decimal('0.003333333333333334')) |
| 48 | assert_equal(mining_info['pooledtx'], 0) |
| 49 | |
| 50 | # Mine a block to leave initial block download |
| 51 | node.generate(1) |
| 52 | tmpl = node.getblocktemplate() |
| 53 | self.log.info("getblocktemplate: Test capability advertised") |
| 54 | assert 'proposal' in tmpl['capabilities'] |
| 55 | assert 'coinbasetxn' not in tmpl |
| 56 | |
| 57 | coinbase_tx = create_coinbase(height=int(tmpl["height"]) + 1) |
| 58 | # sequence numbers must not be max for nLockTime to have effect |
| 59 | coinbase_tx.vin[0].nSequence = 2 ** 32 - 2 |
| 60 | coinbase_tx.rehash() |
| 61 | |
| 62 | block = CBlock() |
| 63 | block.nVersion = tmpl["version"] |
| 64 | block.hashPrevBlock = int(tmpl["previousblockhash"], 16) |
| 65 | block.nTime = tmpl["curtime"] |
| 66 | block.nBits = int(tmpl["bits"], 16) |
| 67 | block.nHeight = int(tmpl["height"]) |
| 68 | block.nNonce = 0 |
| 69 | block.vtx = [coinbase_tx] |
| 70 | |
| 71 | self.log.info("getblocktemplate: Test valid block") |
| 72 | assert_template(node, block, None) |
| 73 | |
| 74 | self.log.info("submitblock: Test block decode failure") |
| 75 | assert_raises_rpc_error(-22, "Block decode failed", node.submitblock, b2x(block.serialize(legacy=False)[:-15])) |
| 76 | |
| 77 | self.log.info("getblocktemplate: Test bad input hash for coinbase transaction") |
| 78 | bad_block = copy.deepcopy(block) |
| 79 | bad_block.vtx[0].vin[0].prevout.hash += 1 |
| 80 | bad_block.vtx[0].rehash() |
| 81 | assert_template(node, bad_block, 'bad-cb-missing') |
| 82 | |
| 83 | self.log.info("submitblock: Test invalid coinbase transaction") |
| 84 | assert_raises_rpc_error(-22, "Block does not start with a coinbase", node.submitblock, b2x(bad_block.serialize(legacy=False))) |
| 85 | |
| 86 | self.log.info("getblocktemplate: Test truncated final transaction") |
| 87 | assert_raises_rpc_error(-22, "Block decode failed", node.getblocktemplate, {'data': b2x(block.serialize(legacy=False)[:-1]), 'mode': 'proposal'}) |
| 88 | |
| 89 | self.log.info("getblocktemplate: Test duplicate transaction") |
| 90 | bad_block = copy.deepcopy(block) |
| 91 | bad_block.vtx.append(bad_block.vtx[0]) |
| 92 | assert_template(node, bad_block, 'bad-txns-duplicate') |
| 93 | |
| 94 | self.log.info("getblocktemplate: Test invalid transaction") |
nothing calls this directly
no test coverage detected