Skip to content

Commit

Permalink
Problem: staking related cli is not supported in sdk 0.50 (#122)
Browse files Browse the repository at this point in the history
* Problem: status and staking related cli is not adjusted for sdk 0.50

Signed-off-by: mmsqe <[email protected]>
Co-authored-by: yihuang <[email protected]>
  • Loading branch information
mmsqe and yihuang authored Mar 14, 2024
1 parent 2aa4851 commit 190d993
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
7 changes: 4 additions & 3 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions pystarport/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -902,6 +902,7 @@ def query_tally(self, proposal_id):
node=self.node_rpc,
)
)
return res.get("tally") or res

def ibc_transfer(
self,
Expand Down
12 changes: 6 additions & 6 deletions pystarport/tests/test_expansion/test_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
) == {
Expand All @@ -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,
) == {
Expand All @@ -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,
)
4 changes: 4 additions & 0 deletions pystarport/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 190d993

Please sign in to comment.