diff --git a/CodaClient.py b/CodaClient.py index 62e0164..ed13294 100644 --- a/CodaClient.py +++ b/CodaClient.py @@ -15,7 +15,7 @@ def __init__( websocket_protocol: str = "ws", graphql_host: str = "localhost", graphql_path: str = "/graphql", - graphql_port: int = 8080, + graphql_port: int = 8304, ): self.endpoint = "{}://{}:{}{}".format(graphql_protocol, graphql_host, graphql_port, graphql_path) self.websocket_endpoint = "{}://{}:{}{}".format(websocket_protocol, graphql_host, graphql_port, graphql_path) @@ -112,7 +112,7 @@ def get_daemon_status(self) -> dict: query { daemonStatus { numAccounts - blockCount + blockchainLength uptimeSecs ledgerMerkleRoot stagedLedgerHash @@ -170,8 +170,8 @@ def get_wallets(self) -> dict: res = self._send_query(query) return res["data"] - def get_balance(self, pk: str) -> dict: - """Gets the balance for the specified Public Key. + def get_wallet(self, pk: str) -> dict: + """Gets the wallet for the specified Public Key. Arguments: pk {str} -- A Public Key corresponding to a currently installed wallet. @@ -180,8 +180,20 @@ def get_balance(self, pk: str) -> dict: dict -- Returns the "data" field of the JSON Response as a Dict. """ query = ''' - query($publicKey:String!){ - balance(publicKey:$publicKey) + query($publicKey:PublicKey!){ + wallet(publicKey:$publicKey) { + publicKey + balance { + total + unknown + } + nonce + receiptChainHash + delegate + votingFor + stakingActive + privateKeyPath + } } ''' variables = { diff --git a/setup.py b/setup.py index 06d7fd2..5315356 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='CodaClient', - version='0.0.3', + version='0.0.4', python_requires='>=3.5', description='A Python wrapper around the Coda Daemon GraphQL API.', github='http://github.com/CodaProtocol/coda-python', diff --git a/tests/snapshots/snap_test_client.py b/tests/snapshots/snap_test_client.py index 8b3e98e..6aeea27 100644 --- a/tests/snapshots/snap_test_client.py +++ b/tests/snapshots/snap_test_client.py @@ -10,11 +10,11 @@ snapshots['TestCodaClient.test_get_daemon_status 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { - 'query': 'query { daemonStatus { numAccounts blockCount uptimeSecs ledgerMerkleRoot stagedLedgerHash stateHash peers userCommandsSent runSnarkWorker proposePubkeys consensusTimeNow consensusTimeBestTip consensusMechanism consensusConfiguration { delta k c cTimesK slotsPerEpoch slotDuration epochDuration acceptableNetworkDelay } } }' + 'query': 'query { daemonStatus { numAccounts blockchainLength uptimeSecs ledgerMerkleRoot stagedLedgerHash stateHash peers userCommandsSent runSnarkWorker proposePubkeys consensusTimeNow consensusTimeBestTip consensusMechanism consensusConfiguration { delta k c cTimesK slotsPerEpoch slotDuration epochDuration acceptableNetworkDelay } } }' } } ,) @@ -23,7 +23,7 @@ snapshots['TestCodaClient.test_get_daemon_version 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -36,7 +36,7 @@ snapshots['TestCodaClient.test_get_wallets 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -46,26 +46,10 @@ ,) ] -snapshots['TestCodaClient.test_get_balance 1'] = [ - ( - ( - 'http://localhost:8080/graphql' - ,), - { - 'json': { - 'query': 'query($publicKey:String!){ balance(publicKey:$publicKey) }', - 'variables': { - 'publicKey': 'pk' - } - } - } - ,) -] - snapshots['TestCodaClient.test_get_current_snark_worker 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -78,7 +62,7 @@ snapshots['TestCodaClient.test_get_sync_status 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -91,7 +75,7 @@ snapshots['TestCodaClient.test_set_current_snark_worker 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -104,7 +88,7 @@ snapshots['TestCodaClient.test_create_wallet_with_args 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -121,7 +105,7 @@ snapshots['TestCodaClient.test_create_wallet_no_args 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -138,7 +122,7 @@ snapshots['TestCodaClient.test_send_payment 1'] = [ ( ( - 'http://localhost:8080/graphql' + 'http://localhost:8304/graphql' ,), { 'json': { @@ -154,3 +138,19 @@ } ,) ] + +snapshots['TestCodaClient.test_get_wallet 1'] = [ + ( + ( + 'http://localhost:8304/graphql' + ,), + { + 'json': { + 'query': 'query($publicKey:PublicKey!){ wallet(publicKey:$publicKey) { publicKey balance { total unknown } nonce receiptChainHash delegate votingFor stakingActive privateKeyPath } }', + 'variables': { + 'publicKey': 'pk' + } + } + } + ,) +] diff --git a/tests/test_client.py b/tests/test_client.py index 9ae3a81..a99d570 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -52,11 +52,11 @@ def test_get_wallets(self, mock_post, snapshot): client.get_wallets() snapshot.assert_match(mock_post.call_args_list) - def test_get_balance(self, mock_post, snapshot): + def test_get_wallet(self, mock_post, snapshot): mock_post.return_value = self._mock_response(json_data={"data": "foo"}) client = Client() - client.get_balance("pk") + client.get_wallet("pk") snapshot.assert_match(mock_post.call_args_list) def test_get_current_snark_worker(self, mock_post, snapshot):