Exemplo n.º 1
0
    def run_test(self):
        node = self.nodes[0]

        # Mine a block to leave initial block download
        node.generate(1)
        candidate = node.getminingcandidate()

        [block, coinbase] = create_block_from_candidate(candidate, False)
        solve_bad(block)

        submitResult = node.submitblock(ToHex(block))
        assert submitResult == 'high-hash'

        submitResult = node.verifyblockcandidate(ToHex(block))
        assert submitResult == None
Exemplo n.º 2
0
    def create_and_submit_block(self, blockNode, candidate, get_coinbase):
        node = self.nodes[blockNode]

        # Do POW for mining candidate and submit solution
        block, coinbase_tx = create_block_from_candidate(candidate, get_coinbase)
        self.log.info("block hash before submit: " + str(block.hash))

        if (get_coinbase):
            self.log.info("Checking submission with provided coinbase")
            return node.submitminingsolution({'id': candidate['id'], 'nonce': block.nNonce})
        else:
            self.log.info("Checking submission with generated coinbase")
            return node.submitminingsolution({'id': candidate['id'],
                                              'nonce': block.nNonce,
                                              'coinbase': '{}'.format(ToHex(coinbase_tx))})
    def test_with_submitminingsolution(self):
        """
            Verify getminincandidate and submitminingsolution
        """
        blockhashes = self.nodes[0].generate(5)
        b2_hash = blockhashes[1]
        b3_hash = blockhashes[2]
        self.nodes[0].softrejectblock(b3_hash, 2)
        assert_equal(self.nodes[0].getbestblockhash(), b2_hash)

        candidate = self.nodes[0].getminingcandidate(True)
        block, coinbase_tx = create_block_from_candidate(candidate, True)
        self.nodes[0].submitminingsolution({
            'id':
            candidate['id'],
            'nonce':
            block.nNonce,
            'coinbase':
            '{}'.format(ToHex(coinbase_tx))
        })
        assert_equal(self.nodes[0].getbestblockhash(), block.hash)
        assert_equal(self.nodes[0].getblockcount(), 3)
Exemplo n.º 4
0
    def run_test(self):
        test_node = NodeConnCB()
        connections = []
        connections.append(
            NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_node))
        test_node.add_connection(connections[0])
        NetworkThread().start()

        starting_height = 3
        self.nodes[0].generate(starting_height)

        # Create block with P2SH output and send it to node.
        # It should be validated and accepted.
        block = self.make_block_withP2SH_coinbase()
        test_node.send_message(msg_block(block))
        test_node.sync_with_ping()
        # check if block was accepted
        assert_equal(self.nodes[0].getbestblockhash(), block.hash)

        # submitblock with P2SH in coinbase tx (not included in blockchain)
        block = self.make_block_withP2SH_coinbase()
        block.solve()
        assert_raises_rpc_error(-26, "bad-txns-vout-p2sh",
                                self.nodes[0].submitblock, ToHex(block))

        # verifyblockcandidate with P2SH in coinbase tx (not included in blockchain)
        assert_raises_rpc_error(-26, "bad-txns-vout-p2sh",
                                self.nodes[0].verifyblockcandidate,
                                ToHex(block))

        # submitblock without P2SH in coinbase tx (included in blockchain)
        hashPrev = int(self.nodes[0].getbestblockhash(), 16)
        ctx = create_coinbase(self.nodes[0].getblockcount() + 1)
        block2 = create_block(hashPrev, ctx)
        block2.solve()
        self.nodes[0].submitblock(ToHex(block2))
        assert_equal(block2.hash, self.nodes[0].getbestblockhash())

        # submit block with: submitminingsolution
        # Add P2SH to coinbase output - should be rejected
        candidate = self.nodes[0].getminingcandidate(False)
        block, ctx = create_block_from_candidate(candidate, False)
        coinbase_tx = create_coinbase_P2SH(self.nodes[0].getblockcount() + 1,
                                           example_script_hash)

        # submitminingsolution with P2SH in coinbase tx - should be denied.
        assert_raises_rpc_error(
            -26, "bad-txns-vout-p2sh", self.nodes[0].submitminingsolution, {
                'id': candidate['id'],
                'nonce': block.nNonce,
                'coinbase': '{}'.format(ToHex(coinbase_tx))
            })
        # submitminingsolution without P2SH in coinbase - should be accepted
        candidate = self.nodes[0].getminingcandidate(False)
        block, ctx = create_block_from_candidate(candidate, False)
        result = self.nodes[0].submitminingsolution({
            'id':
            candidate['id'],
            'nonce':
            block.nNonce,
            'coinbase':
            '{}'.format(ToHex(ctx))
        })
        assert_equal(result, True)
        assert_equal(block.hash, self.nodes[0].getbestblockhash())

        # generatetoaddress with nonP2SH address
        height_before = self.nodes[0].getblockcount()
        address = self.nodes[0].getnewaddress()
        self.nodes[0].generatetoaddress(1, address)
        height_after = self.nodes[0].getblockcount()
        assert_equal(height_before + 1, height_after)

        # generatetoaddress with P2SH address (example for regtest: 2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc)
        assert_raises_rpc_error(-26, "bad-txns-vout-p2sh",
                                self.nodes[0].generatetoaddress, 1,
                                '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc')