13
13
BALANCE = (BLOCKS - 100 ) * 50
14
14
15
15
class TestBitcoinCli (BitcoinTestFramework ):
16
-
17
16
def set_test_params (self ):
18
17
self .setup_clean_chain = True
19
18
self .num_nodes = 1
@@ -33,12 +32,12 @@ def run_test(self):
33
32
user , password = get_auth_cookie (self .nodes [0 ].datadir , self .chain )
34
33
35
34
self .log .info ("Test -stdinrpcpass option" )
36
- assert_equal (BLOCKS , self .nodes [0 ].cli ('-rpcuser=%s' % user , '-stdinrpcpass' , input = password ).getblockcount ())
37
- assert_raises_process_error (1 , " Incorrect rpcuser or rpcpassword" , self .nodes [0 ].cli ('-rpcuser=%s' % user , '-stdinrpcpass' , input = " foo" ).echo )
35
+ assert_equal (BLOCKS , self .nodes [0 ].cli ('-rpcuser={}' . format ( user ) , '-stdinrpcpass' , input = password ).getblockcount ())
36
+ assert_raises_process_error (1 , ' Incorrect rpcuser or rpcpassword' , self .nodes [0 ].cli ('-rpcuser={}' . format ( user ) , '-stdinrpcpass' , input = ' foo' ).echo )
38
37
39
38
self .log .info ("Test -stdin and -stdinrpcpass" )
40
- assert_equal ([" foo" , " bar" ], self .nodes [0 ].cli ('-rpcuser=%s' % user , '-stdin' , '-stdinrpcpass' , input = password + " \n foo\n bar" ).echo ())
41
- assert_raises_process_error (1 , " Incorrect rpcuser or rpcpassword" , self .nodes [0 ].cli ('-rpcuser=%s' % user , '-stdin' , '-stdinrpcpass' , input = " foo" ).echo )
39
+ assert_equal ([' foo' , ' bar' ], self .nodes [0 ].cli ('-rpcuser={}' . format ( user ) , '-stdin' , '-stdinrpcpass' , input = password + ' \n foo\n bar' ).echo ())
40
+ assert_raises_process_error (1 , ' Incorrect rpcuser or rpcpassword' , self .nodes [0 ].cli ('-rpcuser={}' . format ( user ) , '-stdin' , '-stdinrpcpass' , input = ' foo' ).echo )
42
41
43
42
self .log .info ("Test connecting to a non-existing server" )
44
43
assert_raises_process_error (1 , "Could not connect to the server" , self .nodes [0 ].cli ('-rpcport=1' ).echo )
@@ -52,7 +51,7 @@ def run_test(self):
52
51
self .log .info ("Test -getinfo returns expected network and blockchain info" )
53
52
if self .is_wallet_compiled ():
54
53
self .nodes [0 ].encryptwallet (password )
55
- cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ()
54
+ cli_get_info = self .nodes [0 ].cli ().send_cli ('-getinfo' )
56
55
network_info = self .nodes [0 ].getnetworkinfo ()
57
56
blockchain_info = self .nodes [0 ].getblockchaininfo ()
58
57
assert_equal (cli_get_info ['version' ], network_info ['version' ])
@@ -76,20 +75,17 @@ def run_test(self):
76
75
else :
77
76
self .log .info ("*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped" )
78
77
79
- self .stop_node (0 )
80
-
81
78
self .log .info ("Test -version with node stopped" )
82
- cli_response = self .nodes [0 ].cli ("-version" ).send_cli ()
79
+ self .stop_node (0 )
80
+ cli_response = self .nodes [0 ].cli ().send_cli ('-version' )
83
81
assert "{} RPC client version" .format (self .config ['environment' ]['PACKAGE_NAME' ]) in cli_response
84
82
85
- self .log .info ("Test -rpcwait option waits for RPC connection instead of failing" )
86
- # Start node without RPC connection.
87
- self .nodes [0 ].start ()
88
- # Verify failure without -rpcwait.
89
- assert_raises_process_error (1 , "Could not connect to the server" , self .nodes [0 ].cli ('getblockcount' ).echo )
90
- # Verify success using -rpcwait.
91
- assert_equal (BLOCKS , self .nodes [0 ].cli ('-rpcwait' , 'getblockcount' ).send_cli ())
83
+ self .log .info ("Test -rpcwait option successfully waits for RPC connection" )
84
+ self .nodes [0 ].start () # start node without RPC connection
85
+ self .nodes [0 ].wait_for_cookie_credentials () # ensure cookie file is available to avoid race condition
86
+ blocks = self .nodes [0 ].cli ('-rpcwait' ).send_cli ('getblockcount' )
92
87
self .nodes [0 ].wait_for_rpc_connection ()
88
+ assert_equal (blocks , BLOCKS )
93
89
94
90
95
91
if __name__ == '__main__' :
0 commit comments