def run_test(self):
    chain_height = self.nodes[0].getblockcount()
    assert_equal(chain_height, 200)
    self.log.debug('Mine a single block to get out of IBD')
    self.nodes[0].generate(1)
    self.sync_all()
    self.log.debug('Send 5 transactions from node2 (to its own address)')
    for i in range(5):
        self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal('10'))
    self.sync_all()
    self.log.debug('Verify that node0 and node1 have 5 transactions in their mempools')
    assert_equal(len(self.nodes[0].getrawmempool()), 5)
    assert_equal(len(self.nodes[1].getrawmempool()), 5)
    self.log.debug('Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.')
    self.stop_nodes()
    self.start_node(0)
    self.start_node(1)
    time.sleep(1)
    wait_until((lambda : (len(self.nodes[0].getrawmempool()) == 5)))
    assert_equal(len(self.nodes[1].getrawmempool()), 0)
    self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
    self.stop_nodes()
    self.start_node(0, extra_args=['-persistmempool=0'])
    time.sleep(1)
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    self.log.debug('Stop-start node0. Verify that it has the transactions in its mempool.')
    self.stop_nodes()
    self.start_node(0)
    wait_until((lambda : (len(self.nodes[0].getrawmempool()) == 5)))
    mempooldat0 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'mempool.dat')
    mempooldat1 = os.path.join(self.options.tmpdir, 'node1', 'regtest', 'mempool.dat')
    self.log.debug('Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it')
    os.remove(mempooldat0)
    self.nodes[0].savemempool()
    assert os.path.isfile(mempooldat0)
    self.log.debug('Stop nodes, make node1 use mempool.dat from node0. Verify it has 5 transactions')
    os.rename(mempooldat0, mempooldat1)
    self.stop_nodes()
    self.start_node(1, extra_args=[])
    wait_until((lambda : (len(self.nodes[1].getrawmempool()) == 5)))
    self.log.debug('Prevent bwscoind from writing mempool.dat to disk. Verify that `savemempool` fails')
    mempooldotnew1 = (mempooldat1 + '.new')
    with os.fdopen(os.open(mempooldotnew1, os.O_CREAT, 0), 'w'):
        pass
    assert_raises_rpc_error((- 1), 'Unable to dump mempool to disk', self.nodes[1].savemempool)
    os.remove(mempooldotnew1)
def run_test(self):
    chain_height = self.nodes[0].getblockcount()
    assert_equal(chain_height, 200)
    self.log.debug('Mine a single block to get out of IBD')
    self.nodes[0].generate(1)
    self.sync_all()
    self.log.debug('Send 5 transactions from node2 (to its own address)')
    for i in range(5):
        self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal('10'))
    self.sync_all()
    self.log.debug('Verify that node0 and node1 have 5 transactions in their mempools')
    assert_equal(len(self.nodes[0].getrawmempool()), 5)
    assert_equal(len(self.nodes[1].getrawmempool()), 5)
    self.log.debug('Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.')
    self.stop_nodes()
    self.start_node(0)
    self.start_node(1)
    time.sleep(1)
    wait_until((lambda : (len(self.nodes[0].getrawmempool()) == 5)))
    assert_equal(len(self.nodes[1].getrawmempool()), 0)
    self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
    self.stop_nodes()
    self.start_node(0, extra_args=['-persistmempool=0'])
    time.sleep(1)
    assert_equal(len(self.nodes[0].getrawmempool()), 0)
    self.log.debug('Stop-start node0. Verify that it has the transactions in its mempool.')
    self.stop_nodes()
    self.start_node(0)
    wait_until((lambda : (len(self.nodes[0].getrawmempool()) == 5)))
    mempooldat0 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'mempool.dat')
    mempooldat1 = os.path.join(self.options.tmpdir, 'node1', 'regtest', 'mempool.dat')
    self.log.debug('Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it')
    os.remove(mempooldat0)
    self.nodes[0].savemempool()
    assert os.path.isfile(mempooldat0)
    self.log.debug('Stop nodes, make node1 use mempool.dat from node0. Verify it has 5 transactions')
    os.rename(mempooldat0, mempooldat1)
    self.stop_nodes()
    self.start_node(1, extra_args=[])
    wait_until((lambda : (len(self.nodes[1].getrawmempool()) == 5)))
    self.log.debug('Prevent bwscoind from writing mempool.dat to disk. Verify that `savemempool` fails')
    mempooldotnew1 = (mempooldat1 + '.new')
    with os.fdopen(os.open(mempooldotnew1, os.O_CREAT, 0), 'w'):
        pass
    assert_raises_rpc_error((- 1), 'Unable to dump mempool to disk', self.nodes[1].savemempool)
    os.remove(mempooldotnew1)