Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_bitcoin_cli.py
Show All 13 Lines | |||||
# The block reward of coinbaseoutput.nValue (50) BTC/block matures after | # The block reward of coinbaseoutput.nValue (50) BTC/block matures after | ||||
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect | # COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect | ||||
# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block. | # node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block. | ||||
BLOCKS = 101 | BLOCKS = 101 | ||||
BALANCE = (BLOCKS - 100) * 50 | BALANCE = (BLOCKS - 100) * 50 | ||||
class TestBitcoinCli(BitcoinTestFramework): | class TestBitcoinCli(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_cli() | self.skip_if_no_cli() | ||||
def run_test(self): | def run_test(self): | ||||
"""Main test logic""" | """Main test logic""" | ||||
self.nodes[0].generate(BLOCKS) | self.nodes[0].generate(BLOCKS) | ||||
self.log.info( | self.log.info( | ||||
"Compare responses from getblockchaininfo RPC and `bitcoin-cli getblockchaininfo`") | "Compare responses from getblockchaininfo RPC and `bitcoin-cli getblockchaininfo`") | ||||
cli_response = self.nodes[0].cli.getblockchaininfo() | cli_response = self.nodes[0].cli.getblockchaininfo() | ||||
rpc_response = self.nodes[0].getblockchaininfo() | rpc_response = self.nodes[0].getblockchaininfo() | ||||
assert_equal(cli_response, rpc_response) | assert_equal(cli_response, rpc_response) | ||||
user, password = get_auth_cookie(self.nodes[0].datadir, self.chain) | user, password = get_auth_cookie(self.nodes[0].datadir, self.chain) | ||||
self.log.info("Test -stdinrpcpass option") | self.log.info("Test -stdinrpcpass option") | ||||
assert_equal(BLOCKS, self.nodes[0].cli( | assert_equal( | ||||
'-rpcuser={}'.format(user), '-stdinrpcpass', input=password).getblockcount()) | BLOCKS, | ||||
assert_raises_process_error(1, "Incorrect rpcuser or rpcpassword", self.nodes[0].cli( | self.nodes[0].cli( | ||||
'-rpcuser={}'.format(user), '-stdinrpcpass', input="foo").echo) | '-rpcuser={}'.format(user), | ||||
'-stdinrpcpass', | |||||
input=password).getblockcount()) | |||||
assert_raises_process_error( | |||||
1, | |||||
'Incorrect rpcuser or rpcpassword', | |||||
self.nodes[0].cli( | |||||
'-rpcuser={}'.format(user), | |||||
'-stdinrpcpass', | |||||
input='foo').echo) | |||||
self.log.info("Test -stdin and -stdinrpcpass") | self.log.info("Test -stdin and -stdinrpcpass") | ||||
assert_equal(["foo", "bar"], self.nodes[0].cli('-rpcuser={}'.format(user), | assert_equal(['foo', | ||||
'-stdin', '-stdinrpcpass', input=password + "\nfoo\nbar").echo()) | 'bar'], | ||||
assert_raises_process_error(1, "Incorrect rpcuser or rpcpassword", self.nodes[0].cli( | self.nodes[0].cli('-rpcuser={}'.format(user), | ||||
'-rpcuser={}'.format(user), '-stdin', '-stdinrpcpass', input="foo").echo) | '-stdin', | ||||
'-stdinrpcpass', | |||||
input=password + '\nfoo\nbar').echo()) | |||||
assert_raises_process_error( | |||||
1, | |||||
'Incorrect rpcuser or rpcpassword', | |||||
self.nodes[0].cli( | |||||
'-rpcuser={}'.format(user), | |||||
'-stdin', | |||||
'-stdinrpcpass', | |||||
input='foo').echo) | |||||
self.log.info("Test connecting to a non-existing server") | self.log.info("Test connecting to a non-existing server") | ||||
assert_raises_process_error( | assert_raises_process_error( | ||||
1, "Could not connect to the server", self.nodes[0].cli('-rpcport=1').echo) | 1, "Could not connect to the server", self.nodes[0].cli('-rpcport=1').echo) | ||||
self.log.info("Test connecting with non-existing RPC cookie file") | self.log.info("Test connecting with non-existing RPC cookie file") | ||||
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli( | assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli( | ||||
'-rpccookiefile=does-not-exist', '-rpcpassword=').echo) | '-rpccookiefile=does-not-exist', '-rpcpassword=').echo) | ||||
self.log.info("Test -getinfo with arguments fails") | self.log.info("Test -getinfo with arguments fails") | ||||
assert_raises_process_error( | assert_raises_process_error( | ||||
1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help) | 1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help) | ||||
self.log.info( | self.log.info( | ||||
"Test -getinfo returns expected network and blockchain info") | "Test -getinfo returns expected network and blockchain info") | ||||
if self.is_wallet_compiled(): | if self.is_wallet_compiled(): | ||||
self.nodes[0].encryptwallet(password) | self.nodes[0].encryptwallet(password) | ||||
cli_get_info = self.nodes[0].cli('-getinfo').send_cli() | cli_get_info = self.nodes[0].cli().send_cli('-getinfo') | ||||
network_info = self.nodes[0].getnetworkinfo() | network_info = self.nodes[0].getnetworkinfo() | ||||
blockchain_info = self.nodes[0].getblockchaininfo() | blockchain_info = self.nodes[0].getblockchaininfo() | ||||
assert_equal(cli_get_info['version'], network_info['version']) | assert_equal(cli_get_info['version'], network_info['version']) | ||||
assert_equal(cli_get_info['blocks'], blockchain_info['blocks']) | assert_equal(cli_get_info['blocks'], blockchain_info['blocks']) | ||||
assert_equal(cli_get_info['headers'], blockchain_info['headers']) | assert_equal(cli_get_info['headers'], blockchain_info['headers']) | ||||
assert_equal(cli_get_info['timeoffset'], network_info['timeoffset']) | assert_equal(cli_get_info['timeoffset'], network_info['timeoffset']) | ||||
assert_equal(cli_get_info['connections'], network_info['connections']) | assert_equal(cli_get_info['connections'], network_info['connections']) | ||||
assert_equal(cli_get_info['proxy'], | assert_equal(cli_get_info['proxy'], | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert 'balance' not in self.nodes[0].cli( | assert 'balance' not in self.nodes[0].cli( | ||||
'-getinfo').send_cli('-rpcwallet={}'.format(wallets[2])).keys() | '-getinfo').send_cli('-rpcwallet={}'.format(wallets[2])).keys() | ||||
else: | else: | ||||
self.log.info( | self.log.info( | ||||
"*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped") | "*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped") | ||||
# maintain block parity with the wallet_compiled conditional branch | # maintain block parity with the wallet_compiled conditional branch | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.stop_node(0) | |||||
self.log.info("Test -version with node stopped") | self.log.info("Test -version with node stopped") | ||||
cli_response = self.nodes[0].cli("-version").send_cli() | self.stop_node(0) | ||||
cli_response = self.nodes[0].cli().send_cli('-version') | |||||
assert "{} RPC client version".format( | assert "{} RPC client version".format( | ||||
self.config['environment']['PACKAGE_NAME']) in cli_response | self.config['environment']['PACKAGE_NAME']) in cli_response | ||||
self.log.info( | self.log.info( | ||||
"Test -rpcwait option waits for RPC connection instead of failing") | "Test -rpcwait option successfully waits for RPC connection") | ||||
# Start node without RPC connection. | self.nodes[0].start() # start node without RPC connection | ||||
self.nodes[0].start() | # ensure cookie file is available to avoid race condition | ||||
# Verify failure without -rpcwait. | self.nodes[0].wait_for_cookie_credentials() | ||||
assert_raises_process_error(1, | blocks = self.nodes[0].cli('-rpcwait').send_cli('getblockcount') | ||||
"Could not connect to the server", | |||||
self.nodes[0].cli('getblockcount').echo) | |||||
# Verify success using -rpcwait. | |||||
assert_equal( | |||||
BLOCKS + 1, | |||||
self.nodes[0].cli( | |||||
'-rpcwait', | |||||
'getblockcount').send_cli()) | |||||
self.nodes[0].wait_for_rpc_connection() | self.nodes[0].wait_for_rpc_connection() | ||||
assert_equal(blocks, BLOCKS + 1) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
TestBitcoinCli().main() | TestBitcoinCli().main() |