def __init__(self, host=None, port=None, network=None): if network: assert not host and not port, 'Specify either a server name, or a host & port' host, port = bootstrap.server_from_name(network) else: assert host and port, "Must specify either a server name, or a host & port" self.tokens = TokenApi(host, port) self.contracts = ContractsApi(host, port) self.tx = TransactionApi(host, port) self.server = ServerApi(host, port) # Check that ledger version is compatible with API version check_version_compatibility(self.server.version(), __compatible__)
def test_server_from_name(self, mock_split, mock_address, mock_valid, mock_servers): # Test that all steps called with expected arguments network = 'def' mock_servers.side_effect = ['servers'] mock_valid.side_effect = [True] mock_address.side_effect = ['address'] mock_split.side_effect = [('protocol', 'host', 1234)] host, port = server_from_name(network) mock_servers.assert_called_once_with(True) mock_valid.assert_called_once_with('servers', network) mock_address.assert_called_once_with(network) mock_split.assert_called_once_with('address') self.assertEqual(host, 'protocol://host') self.assertEqual(port, 1234)
def __init__(self, host=None, port=None, network=None): if network: assert not host and not port, 'Specify either a server name, or a host & port' host, port = bootstrap.server_from_name(network) else: assert host and port, "Must specify either a server name, or a host & port" self.tokens = TokenApi(host, port) self.contracts = ContractsApi(host, port) self.tx = TransactionApi(host, port) self.server = ServerApi(host, port) # Check that ledger version is compatible with API version server_version = self.server.version().lstrip('v') if server_version.startswith('Unknown version with hash'): logging.warning('Using development version') elif not all(semver.match(server_version, c) for c in __compatible__): raise IncompatibleLedgerVersion( "Ledger version running on server is not compatible with this API" + "\nServer version: {} \nExpected version: {}".format( server_version, ', '.join(__compatible__)))