rpc_estimatefee.py
1 #!/usr/bin/env python3 2 # Copyright (c) 2018-2022 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 # wrong type for conf_target 25 assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimatesmartfee, 'foo') 26 assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 'foo') 27 28 # wrong type for estimatesmartfee(estimate_mode) 29 assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].estimatesmartfee, 1, 1) 30 assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"', self.nodes[0].estimatesmartfee, 1, 'foo') 31 32 # wrong type for estimaterawfee(threshold) 33 assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 1, 'foo') 34 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.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().main()