def run_test(self):
    self.nodes[1].generate(100)
    sync_blocks(self.nodes)
    balance = self.nodes[0].getbalance()
    txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    txC = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    sync_mempools(self.nodes)
    self.nodes[1].generate(1)
    sync_blocks(self.nodes)
    newbalance = self.nodes[0].getbalance()
    assert ((balance - newbalance) < Decimal('0.001'))
    balance = newbalance
    disconnect_nodes(self.nodes[0], 1)
    nA = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txA, 1)['vout']) if (vout['value'] == Decimal('10'))))
    nB = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txB, 1)['vout']) if (vout['value'] == Decimal('10'))))
    nC = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txC, 1)['vout']) if (vout['value'] == Decimal('10'))))
    inputs = []
    inputs.append({'txid': txA, 'vout': nA})
    inputs.append({'txid': txB, 'vout': nB})
    outputs = {}
    outputs[self.nodes[0].getnewaddress()] = Decimal('14.99998')
    outputs[self.nodes[1].getnewaddress()] = Decimal('5')
    signed = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
    txAB1 = self.nodes[0].sendrawtransaction(signed['hex'])
    nAB = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txAB1, 1)['vout']) if (vout['value'] == Decimal('14.99998'))))
    inputs = []
    inputs.append({'txid': txAB1, 'vout': nAB})
    inputs.append({'txid': txC, 'vout': nC})
    outputs = {}
    outputs[self.nodes[0].getnewaddress()] = Decimal('24.9996')
    signed2 = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
    txABC2 = self.nodes[0].sendrawtransaction(signed2['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, ((balance - Decimal('30')) + Decimal('24.9996')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.0001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    assert_equal(len(self.nodes[1].getrawmempool()), 0)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance - Decimal('24.9996')))
    unconfbalance = (self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance())
    assert_equal(unconfbalance, newbalance)
    assert (not (txABC2 in [utxo['txid'] for utxo in self.nodes[0].listunspent(0)]))
    balance = newbalance
    self.nodes[0].abandontransaction(txAB1)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance + Decimal('30')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.00001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    assert_equal(self.nodes[0].getbalance(), balance)
    self.nodes[0].sendrawtransaction(signed['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, ((balance - Decimal('20')) + Decimal('14.99998')))
    balance = newbalance
    self.nodes[0].sendrawtransaction(signed2['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (((balance - Decimal('10')) - Decimal('14.99998')) + Decimal('24.9996')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.0001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance - Decimal('24.9996')))
    balance = newbalance
    inputs = []
    inputs.append({'txid': txA, 'vout': nA})
    outputs = {}
    outputs[self.nodes[1].getnewaddress()] = Decimal('9.9999')
    tx = self.nodes[0].createrawtransaction(inputs, outputs)
    signed = self.nodes[0].signrawtransaction(tx)
    self.nodes[1].sendrawtransaction(signed['hex'])
    self.nodes[1].generate(1)
    connect_nodes(self.nodes[0], 1)
    sync_blocks(self.nodes)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance + Decimal('20')))
    balance = newbalance
    self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
    newbalance = self.nodes[0].getbalance()
    self.log.info('If balance has not declined after invalidateblock then out of mempool wallet tx which is no longer')
    self.log.info('conflicted has not resumed causing its inputs to be seen as spent.  See Issue #7315')
    self.log.info((((str(balance) + ' -> ') + str(newbalance)) + ' ?'))
def run_test(self):
    self.nodes[1].generate(100)
    sync_blocks(self.nodes)
    balance = self.nodes[0].getbalance()
    txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    txC = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal('10'))
    sync_mempools(self.nodes)
    self.nodes[1].generate(1)
    sync_blocks(self.nodes)
    newbalance = self.nodes[0].getbalance()
    assert ((balance - newbalance) < Decimal('0.001'))
    balance = newbalance
    disconnect_nodes(self.nodes[0], 1)
    nA = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txA, 1)['vout']) if (vout['value'] == Decimal('10'))))
    nB = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txB, 1)['vout']) if (vout['value'] == Decimal('10'))))
    nC = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txC, 1)['vout']) if (vout['value'] == Decimal('10'))))
    inputs = []
    inputs.append({'txid': txA, 'vout': nA})
    inputs.append({'txid': txB, 'vout': nB})
    outputs = {}
    outputs[self.nodes[0].getnewaddress()] = Decimal('14.99998')
    outputs[self.nodes[1].getnewaddress()] = Decimal('5')
    signed = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
    txAB1 = self.nodes[0].sendrawtransaction(signed['hex'])
    nAB = next((i for (i, vout) in enumerate(self.nodes[0].getrawtransaction(txAB1, 1)['vout']) if (vout['value'] == Decimal('14.99998'))))
    inputs = []
    inputs.append({'txid': txAB1, 'vout': nAB})
    inputs.append({'txid': txC, 'vout': nC})
    outputs = {}
    outputs[self.nodes[0].getnewaddress()] = Decimal('24.9996')
    signed2 = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
    txABC2 = self.nodes[0].sendrawtransaction(signed2['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, ((balance - Decimal('30')) + Decimal('24.9996')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.0001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    assert_equal(len(self.nodes[1].getrawmempool()), 0)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance - Decimal('24.9996')))
    unconfbalance = (self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance())
    assert_equal(unconfbalance, newbalance)
    assert (not (txABC2 in [utxo['txid'] for utxo in self.nodes[0].listunspent(0)]))
    balance = newbalance
    self.nodes[0].abandontransaction(txAB1)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance + Decimal('30')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.00001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    assert_equal(self.nodes[0].getbalance(), balance)
    self.nodes[0].sendrawtransaction(signed['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, ((balance - Decimal('20')) + Decimal('14.99998')))
    balance = newbalance
    self.nodes[0].sendrawtransaction(signed2['hex'])
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (((balance - Decimal('10')) - Decimal('14.99998')) + Decimal('24.9996')))
    balance = newbalance
    self.stop_node(0)
    self.start_node(0, extra_args=['-minrelaytxfee=0.0001'])
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance - Decimal('24.9996')))
    balance = newbalance
    inputs = []
    inputs.append({'txid': txA, 'vout': nA})
    outputs = {}
    outputs[self.nodes[1].getnewaddress()] = Decimal('9.9999')
    tx = self.nodes[0].createrawtransaction(inputs, outputs)
    signed = self.nodes[0].signrawtransaction(tx)
    self.nodes[1].sendrawtransaction(signed['hex'])
    self.nodes[1].generate(1)
    connect_nodes(self.nodes[0], 1)
    sync_blocks(self.nodes)
    newbalance = self.nodes[0].getbalance()
    assert_equal(newbalance, (balance + Decimal('20')))
    balance = newbalance
    self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
    newbalance = self.nodes[0].getbalance()
    self.log.info('If balance has not declined after invalidateblock then out of mempool wallet tx which is no longer')
    self.log.info('conflicted has not resumed causing its inputs to be seen as spent.  See Issue #7315')
    self.log.info((((str(balance) + ' -> ') + str(newbalance)) + ' ?'))