diff --git a/CHANGELOG.md b/CHANGELOG.md index d7d3cde..b7bbde5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [#115](https://github.com/crypto-com/pystarport/pull/115) avoid cli redundant migrated key log in stdout. - [#117](https://github.com/crypto-com/pystarport/pull/117) make event_query_tx_for optional. - [#121](https://github.com/crypto-com/pystarport/pull/121) Support sdk 0.50 +- [#122](https://github.com/crypto-com/pystarport/pull/122) Adjust status and staking related cli for sdk 0.50 *Feb 7, 2023* diff --git a/pystarport/cluster.py b/pystarport/cluster.py index 93114d3..eebe671 100644 --- a/pystarport/cluster.py +++ b/pystarport/cluster.py @@ -27,7 +27,7 @@ from .cosmoscli import ChainCommand, CosmosCLI, ModuleAccount, module_address from .expansion import expand_jsonnet, expand_yaml from .ledger import ZEMU_BUTTON_PORT, ZEMU_HOST -from .utils import format_doc_string, interact, write_ini +from .utils import format_doc_string, get_sync_info, interact, write_ini COMMON_PROG_OPTIONS = { # redirect to supervisord's stdout, easier to collect all logs @@ -235,7 +235,7 @@ def create_node( def custom_edit_tm(doc): if statesync: - info = self.status()["SyncInfo"] + info = get_sync_info(self.status()) doc["statesync"].update( { "enable": True, @@ -621,7 +621,8 @@ def query_proposals(self, depositor=None, limit=None, status=None, voter=None, i return self.cosmos_cli(i).query_proposals(depositor, limit, status, voter) def query_proposal(self, proposal_id, i=0): - return self.cosmos_cli(i).query_proposal(proposal_id) + res = self.cosmos_cli(i).query_proposal(proposal_id) + return res.get("proposal") or res def query_tally(self, proposal_id, i=0): return self.cosmos_cli(i).query_tally(proposal_id) diff --git a/pystarport/cosmoscli.py b/pystarport/cosmoscli.py index 23b7c5b..45e6453 100644 --- a/pystarport/cosmoscli.py +++ b/pystarport/cosmoscli.py @@ -11,7 +11,7 @@ from .app import CHAIN from .ledger import ZEMU_BUTTON_PORT, ZEMU_HOST, LedgerButton -from .utils import build_cli_args_safe, format_doc_string, interact +from .utils import build_cli_args_safe, format_doc_string, get_sync_info, interact class ModuleAccount(enum.Enum): @@ -203,10 +203,10 @@ def status(self): return json.loads(self.raw("status", node=self.node_rpc)) def block_height(self): - return int(self.status()["SyncInfo"]["latest_block_height"]) + return int(get_sync_info(self.status())["latest_block_height"]) def block_time(self): - return isoparse(self.status()["SyncInfo"]["latest_block_time"]) + return isoparse(get_sync_info(self.status())["latest_block_time"]) def balances(self, addr, height=0): return json.loads( @@ -337,11 +337,10 @@ def staking_params(self): ) def staking_pool(self, bonded=True): - return int( - json.loads( - self.raw("query", "staking", "pool", output="json", node=self.node_rpc) - )["bonded_tokens" if bonded else "not_bonded_tokens"] - ) + res = self.raw("query", "staking", "pool", output="json", node=self.node_rpc) + res = json.loads(res) + res = res.get("pool") or res + return int(res["bonded_tokens" if bonded else "not_bonded_tokens"]) def transfer( self, @@ -880,7 +879,7 @@ def query_proposals(self, depositor=None, limit=None, status=None, voter=None): ) def query_proposal(self, proposal_id): - return json.loads( + res = json.loads( self.raw( "query", "gov", @@ -890,9 +889,10 @@ def query_proposal(self, proposal_id): node=self.node_rpc, ) ) + return res.get("proposal") or res def query_tally(self, proposal_id): - return json.loads( + res = json.loads( self.raw( "query", "gov", @@ -902,6 +902,7 @@ def query_tally(self, proposal_id): node=self.node_rpc, ) ) + return res.get("tally") or res def ibc_transfer( self, diff --git a/pystarport/tests/test_expansion/test_expansion.py b/pystarport/tests/test_expansion/test_expansion.py index 128345e..0abd2aa 100644 --- a/pystarport/tests/test_expansion/test_expansion.py +++ b/pystarport/tests/test_expansion/test_expansion.py @@ -22,15 +22,15 @@ def test_expansion(type, func): cronos_has_dotenv = parent / ("cronos_has_dotenv" + type) cronos_no_dotenv = parent / ("cronos_no_dotenv" + type) cronos_has_posix_no_dotenv = parent / ("cronos_no_dotenv" + type) - baseConfig = _get_base_config() + base_config = _get_base_config() # `expand_yaml` is backward compatible, not expanded, and no diff config = func(cronos_no_dotenv, None) - assert baseConfig == config + assert base_config == config # `expand_yaml` is expanded but no diff config = func(cronos_has_dotenv, None) assert not DeepDiff( - baseConfig, + base_config, config, ignore_order=True, ) @@ -39,7 +39,7 @@ def test_expansion(type, func): dotenv = "dotenv1" config = func(cronos_has_dotenv, dotenv) assert DeepDiff( - baseConfig, + base_config, config, ignore_order=True, ) == { @@ -57,7 +57,7 @@ def test_expansion(type, func): dotenv = os.path.abspath("test_expansion/dotenv1") config = func(cronos_has_dotenv, dotenv) assert DeepDiff( - baseConfig, + base_config, config, ignore_order=True, ) == { @@ -75,7 +75,7 @@ def test_expansion(type, func): dotenv = os.path.abspath("test_expansion/dotenv") config = func(cronos_has_posix_no_dotenv, dotenv) assert not DeepDiff( - baseConfig, + base_config, config, ignore_order=True, ) diff --git a/pystarport/utils.py b/pystarport/utils.py index 070f2e2..aca5ed9 100644 --- a/pystarport/utils.py +++ b/pystarport/utils.py @@ -61,3 +61,7 @@ def decorator(target): return target return decorator + + +def get_sync_info(s): + return s.get("SyncInfo") or s.get("sync_info")