def test_chainlock_overrides_islock(self, test_block_conflict):
    rawtx1 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx2 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx3 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx1_obj = FromHex(CTransaction(), rawtx1)
    rawtx2_obj = FromHex(CTransaction(), rawtx2)
    rawtx3_obj = FromHex(CTransaction(), rawtx3)
    rawtx1_txid = self.nodes[0].sendrawtransaction(rawtx1)
    rawtx2_txid = encode(hash256(hex_str_to_bytes(rawtx2))[::(- 1)], 'hex_codec').decode('ascii')
    rawtx3_txid = encode(hash256(hex_str_to_bytes(rawtx3))[::(- 1)], 'hex_codec').decode('ascii')
    inputs = []
    n = 0
    for out in rawtx1_obj.vout:
        if (out.nValue == 100000000):
            inputs.append({'txid': rawtx1_txid, 'vout': n})
        n += 1
    rawtx4 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
    rawtx4 = self.nodes[0].signrawtransaction(rawtx4)['hex']
    rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
    for node in self.nodes:
        self.wait_for_instantlock(rawtx1_txid, node)
        self.wait_for_instantlock(rawtx4_txid, node)
    block = self.create_block(self.nodes[0], [rawtx2_obj])
    if test_block_conflict:
        submit_result = self.nodes[0].submitblock(ToHex(block))
        assert (submit_result == 'conflict-tx-lock')
    cl = self.create_chainlock((self.nodes[0].getblockcount() + 1), block.sha256)
    self.test_node.send_clsig(cl)
    sleep(1)
    submit_result = self.nodes[1].submitblock(ToHex(block))
    if test_block_conflict:
        assert (submit_result == 'duplicate')
    else:
        assert (submit_result is None)
    for node in self.nodes:
        self.wait_for_chainlock(node, ('%064x' % block.sha256))
    inputs = []
    n = 0
    for out in rawtx2_obj.vout:
        if (out.nValue == 100000000):
            inputs.append({'txid': rawtx2_txid, 'vout': n})
        n += 1
    rawtx5 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
    rawtx5 = self.nodes[0].signrawtransaction(rawtx5)['hex']
    rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
    for node in self.nodes:
        self.wait_for_instantlock(rawtx5_txid, node)
    for node in self.nodes:
        assert_raises_jsonrpc((- 5), 'No such mempool or blockchain transaction', node.getrawtransaction, rawtx1_txid, True)
        assert_raises_jsonrpc((- 5), 'No such mempool or blockchain transaction', node.getrawtransaction, rawtx4_txid, True)
        rawtx = node.getrawtransaction(rawtx2_txid, True)
        assert rawtx['chainlock']
        assert rawtx['instantlock']
        assert (not rawtx['instantlock_internal'])
def test_chainlock_overrides_islock(self, test_block_conflict):
    rawtx1 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx2 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx3 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
    rawtx1_obj = FromHex(CTransaction(), rawtx1)
    rawtx2_obj = FromHex(CTransaction(), rawtx2)
    rawtx3_obj = FromHex(CTransaction(), rawtx3)
    rawtx1_txid = self.nodes[0].sendrawtransaction(rawtx1)
    rawtx2_txid = encode(hash256(hex_str_to_bytes(rawtx2))[::(- 1)], 'hex_codec').decode('ascii')
    rawtx3_txid = encode(hash256(hex_str_to_bytes(rawtx3))[::(- 1)], 'hex_codec').decode('ascii')
    inputs = []
    n = 0
    for out in rawtx1_obj.vout:
        if (out.nValue == 100000000):
            inputs.append({'txid': rawtx1_txid, 'vout': n})
        n += 1
    rawtx4 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
    rawtx4 = self.nodes[0].signrawtransaction(rawtx4)['hex']
    rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
    for node in self.nodes:
        self.wait_for_instantlock(rawtx1_txid, node)
        self.wait_for_instantlock(rawtx4_txid, node)
    block = self.create_block(self.nodes[0], [rawtx2_obj])
    if test_block_conflict:
        submit_result = self.nodes[0].submitblock(ToHex(block))
        assert (submit_result == 'conflict-tx-lock')
    cl = self.create_chainlock((self.nodes[0].getblockcount() + 1), block.sha256)
    self.test_node.send_clsig(cl)
    sleep(1)
    submit_result = self.nodes[1].submitblock(ToHex(block))
    if test_block_conflict:
        assert (submit_result == 'duplicate')
    else:
        assert (submit_result is None)
    for node in self.nodes:
        self.wait_for_chainlock(node, ('%064x' % block.sha256))
    inputs = []
    n = 0
    for out in rawtx2_obj.vout:
        if (out.nValue == 100000000):
            inputs.append({'txid': rawtx2_txid, 'vout': n})
        n += 1
    rawtx5 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
    rawtx5 = self.nodes[0].signrawtransaction(rawtx5)['hex']
    rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
    for node in self.nodes:
        self.wait_for_instantlock(rawtx5_txid, node)
    for node in self.nodes:
        assert_raises_jsonrpc((- 5), 'No such mempool or blockchain transaction', node.getrawtransaction, rawtx1_txid, True)
        assert_raises_jsonrpc((- 5), 'No such mempool or blockchain transaction', node.getrawtransaction, rawtx4_txid, True)
        rawtx = node.getrawtransaction(rawtx2_txid, True)
        assert rawtx['chainlock']
        assert rawtx['instantlock']
        assert (not rawtx['instantlock_internal'])