rpc_estimatefee.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2018-present The Bitcoin Core 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 the estimatefee RPCs.
   6  
   7  Test the following RPCs:
   8     - estimatesmartfee
   9     - estimaterawfee
  10  """
  11  
  12  from test_framework.test_framework import BitcoinTestFramework
  13  from test_framework.util import assert_raises_rpc_error
  14  
  15  class EstimateFeeTest(BitcoinTestFramework):
  16      def set_test_params(self):
  17          self.num_nodes = 1
  18  
  19      def run_test(self):
  20          # missing required params
  21          assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee)
  22          assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee)
  23  
  24          # cli handles wrong types differently
  25          if not self.options.usecli:
  26              # wrong type for conf_target
  27              assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimatesmartfee, 'foo')
  28              assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 'foo')
  29              # wrong type for estimatesmartfee(estimate_mode)
  30              assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].estimatesmartfee, 1, 1)
  31              # wrong type for estimaterawfee(threshold)
  32              assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 1, 'foo')
  33  
  34          assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"', self.nodes[0].estimatesmartfee, 1, 'foo')
  35          # extra params
  36          assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee, 1, 'ECONOMICAL', 1)
  37          assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee, 1, 1, 1)
  38  
  39          # max value of 1008 per src/policy/fees/block_policy_estimator.h
  40          assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", self.nodes[0].estimaterawfee, 1009)
  41  
  42          # valid calls
  43          self.nodes[0].estimatesmartfee(1)
  44          # self.nodes[0].estimatesmartfee(1, None)
  45          self.nodes[0].estimatesmartfee(1, 'ECONOMICAL')
  46          self.nodes[0].estimatesmartfee(1, 'unset')
  47          self.nodes[0].estimatesmartfee(1, 'conservative')
  48  
  49          self.nodes[0].estimaterawfee(1)
  50          self.nodes[0].estimaterawfee(1, None)
  51          self.nodes[0].estimaterawfee(1, 1)
  52  
  53  
  54  if __name__ == '__main__':
  55      EstimateFeeTest(__file__).main()
  56