feature_fee_estimates_persist.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2014-2021 The Limenka developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  """Test fee estimates persistence.
   6  
   7  By default, limenkad will dump fee estimates on shutdown and
   8  then reload it on startup.
   9  
  10  Test is as follows:
  11  
  12    - start node0
  13    - call the savefeeestimates RPC and verify the RPC succeeds and
  14      that the file exists
  15    - make the file read only and attempt to call the savefeeestimates RPC
  16      with the expecation that it will fail
  17    - move the read only file and shut down the node, verify the node writes
  18      on shutdown a file that is identical to the one we saved via the RPC
  19  
  20  """
  21  
  22  import filecmp
  23  import os
  24  
  25  from test_framework.test_framework import LimenkaTestFramework
  26  from test_framework.util import assert_raises_rpc_error
  27  
  28  
  29  class FeeEstimatesPersistTest(LimenkaTestFramework):
  30      def set_test_params(self):
  31          self.num_nodes = 1
  32  
  33      def run_test(self):
  34          fee_estimatesdat = os.path.join(self.nodes[0].chain_path, 'fee_estimates.dat')
  35          self.log.debug('Verify the fee_estimates.dat file does not exists on start up')
  36          assert not os.path.isfile(fee_estimatesdat)
  37          self.nodes[0].savefeeestimates()
  38          self.log.debug('Verify the fee_estimates.dat file exists after calling savefeeestimates RPC')
  39          assert os.path.isfile(fee_estimatesdat)
  40          self.log.debug("Prevent limenkad from writing fee_estimates.dat to disk. Verify that `savefeeestimates` fails")
  41          fee_estimatesdatold = fee_estimatesdat + '.old'
  42          os.rename(fee_estimatesdat, fee_estimatesdatold)
  43          os.mkdir(fee_estimatesdat)
  44          assert_raises_rpc_error(-1, "Unable to dump fee estimates to disk", self.nodes[0].savefeeestimates)
  45          os.rmdir(fee_estimatesdat)
  46          self.stop_nodes()
  47          self.log.debug("Verify that fee_estimates are written on shutdown")
  48          assert os.path.isfile(fee_estimatesdat)
  49          self.log.debug("Verify that the fee estimates from a shutdown are identical from the ones from savefeeestimates")
  50          assert filecmp.cmp(fee_estimatesdat, fee_estimatesdatold)
  51  
  52  
  53  if __name__ == "__main__":
  54      FeeEstimatesPersistTest(__file__).main()
  55