From 393971446e2ded67989da6d21dedfee2578ca9d6 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Fri, 7 Jan 2022 14:27:13 +0000 Subject: [PATCH] Add status, label and extradata to RPC display Fixes #1118. Before this commit, the json serializtion of a WalletEntry object was incorrect and missing some fields. This is now fixed, and the WalletDisplayResponse in the RPC spec .yaml file correctly reflects the fields that are returned by the JMWalletDaemon in response to the /display request. --- jmclient/jmclient/wallet-rpc-api.yaml | 6 +++++- jmclient/jmclient/wallet_utils.py | 4 +++- jmclient/test/test_wallet_rpc.py | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/jmclient/jmclient/wallet-rpc-api.yaml b/jmclient/jmclient/wallet-rpc-api.yaml index 4223d64..2078a24 100644 --- a/jmclient/jmclient/wallet-rpc-api.yaml +++ b/jmclient/jmclient/wallet-rpc-api.yaml @@ -613,7 +613,11 @@ components: type: string amount: type: string - labels: + status: + type: string + label: + type: string + extradata: type: string CreateWalletResponse: diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index 7bc0683..c701097 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -187,7 +187,9 @@ class WalletViewEntry(WalletViewBase): return {"hd_path": self.wallet_path_repr, "address": self.serialize_address(), "amount": self.serialize_amounts(), - "labels": self.serialize_extra_data()} + "status": self.serialize_status(), + "label": self.serialize_label(), + "extradata": self.serialize_extra_data()} def serialize_wallet_position(self): return self.wallet_path_repr.ljust(20) diff --git a/jmclient/test/test_wallet_rpc.py b/jmclient/test/test_wallet_rpc.py index d5aabb0..6e81ae0 100644 --- a/jmclient/test/test_wallet_rpc.py +++ b/jmclient/test/test_wallet_rpc.py @@ -267,6 +267,10 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase): "destination": "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"}).encode()) yield self.do_request(agent, b"POST", addr, body, self.process_direct_send_response) + # before querying the wallet display, set a label to check: + labeladdr = self.daemon.wallet_service.get_addr(0,0,0) + self.daemon.wallet_service.set_address_label(labeladdr, + "test-wallet-rpc-label") # force the wallet service txmonitor to wake up, to see the new # tx before querying /display: self.daemon.wallet_service.transaction_monitor() @@ -288,11 +292,20 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase): def process_wallet_display_response(self, response, code): assert code == 200 json_body = json.loads(response.decode("utf-8")) - latest_balance = float(json_body["walletinfo"]["total_balance"]) + wi = json_body["walletinfo"] + latest_balance = float(wi["total_balance"]) jlog.info("Wallet display currently shows balance: {}".format( latest_balance)) assert latest_balance > self.mean_amt * 4.0 - 1.1 assert latest_balance <= self.mean_amt * 4.0 - 1.0 + # these samplings are an attempt to ensure object structure: + wia = wi["accounts"] + # note that only certain indices are present, based on funding + # and the direct-send tx above: + assert wia[0]["branches"][0]["entries"][0]["label"] == "test-wallet-rpc-label" + assert wia[0]["branches"][0]["entries"][0]["hd_path"] == "m/84'/1'/0'/0/0" + assert wia[1]["branches"][0]["entries"][1]["status"] == "used" + assert wia[1]["branches"][0]["entries"][1]["extradata"] == "" @defer.inlineCallbacks def test_getaddress(self):