Skip to content

Commit 7dbff57

Browse files
authored
Merge pull request #267 from input-output-hk/command_era_expected
refactor: update command era handling in ClusterLib
2 parents f6e9391 + e467093 commit 7dbff57

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

cardano_clusterlib/clusterlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
# pylint: disable=unused-import
77
# flake8: noqa
88
from cardano_clusterlib.clusterlib_klass import ClusterLib
9+
from cardano_clusterlib.consts import CommandEras
910
from cardano_clusterlib.consts import DEFAULT_COIN
1011
from cardano_clusterlib.consts import Eras
1112
from cardano_clusterlib.consts import MAINNET_MAGIC
1213
from cardano_clusterlib.consts import MultiSigTypeArgs
1314
from cardano_clusterlib.consts import MultiSlotTypeArgs
1415
from cardano_clusterlib.consts import Protocols
15-
from cardano_clusterlib.consts import ScriptTypes
1616
from cardano_clusterlib.consts import SLOTS_OFFSETS
17+
from cardano_clusterlib.consts import ScriptTypes
1718
from cardano_clusterlib.consts import Votes
1819
from cardano_clusterlib.coverage import record_cli_coverage
1920
from cardano_clusterlib.exceptions import CLIError

cardano_clusterlib/clusterlib_klass.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ def __init__(
5151
protocol: str = consts.Protocols.CARDANO,
5252
slots_offset: int = 0,
5353
socket_path: itp.FileType = "",
54-
command_era: str = "latest",
54+
command_era: str = consts.CommandEras.LATEST,
5555
):
5656
# pylint: disable=too-many-statements
57+
try:
58+
self.command_era = getattr(consts.CommandEras, command_era.upper())
59+
except AttributeError as excp:
60+
msg = f"Unknown command era `{command_era}`."
61+
raise exceptions.CLIError(msg) from excp
62+
5763
self.cluster_id = 0 # can be used for identifying cluster instance
5864
self.cli_coverage: dict = {}
5965
self._rand_str = helpers.get_rand_str(4)
6066
self._cli_log = ""
6167
self.protocol = protocol
62-
self.command_era = command_era.lower()
6368
self.era_in_use = (
6469
consts.Eras.__members__.get(command_era.upper()) or consts.Eras["DEFAULT"]
6570
).name.lower()
@@ -248,8 +253,7 @@ def cli(
248253

249254
if add_default_args:
250255
cli_args_strs_all.insert(0, "cardano-cli")
251-
if self.command_era:
252-
cli_args_strs_all.insert(1, self.command_era)
256+
cli_args_strs_all.insert(1, self.command_era)
253257

254258
cli_args_strs = [arg for arg in cli_args_strs_all if arg != consts.SUBCOMMAND_MARK]
255259

cardano_clusterlib/consts.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
SUBCOMMAND_MARK: tp.Final[str] = "SUBCOMMAND"
2121

2222

23+
class CommandEras:
24+
SHELLEY: tp.Final[str] = "shelley"
25+
ALLEGRA: tp.Final[str] = "allegra"
26+
MARY: tp.Final[str] = "mary"
27+
ALONZO: tp.Final[str] = "alonzo"
28+
BABBAGE: tp.Final[str] = "babbage"
29+
CONWAY: tp.Final[str] = "conway"
30+
LATEST: tp.Final[str] = "latest"
31+
32+
2333
class Protocols:
2434
CARDANO: tp.Final[str] = "cardano"
2535
SHELLEY: tp.Final[str] = "shelley"

cardano_clusterlib/stake_address_group.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ def gen_stake_addr_delegation_cert(
292292
out_file = destination_dir / f"{addr_name}_stake_deleg.cert"
293293
clusterlib_helpers._check_files_exist(out_file, clusterlib_obj=self._clusterlib_obj)
294294

295-
command_name = "delegation-certificate"
296-
if self._clusterlib_obj.command_era:
297-
command_name = "stake-delegation-certificate"
298-
299295
stake_key_args = self._get_stake_vkey_args(
300296
stake_vkey=stake_vkey,
301297
stake_vkey_file=stake_vkey_file,
@@ -311,7 +307,7 @@ def gen_stake_addr_delegation_cert(
311307
self._clusterlib_obj.cli(
312308
[
313309
"stake-address",
314-
command_name,
310+
"stake-delegation-certificate",
315311
*stake_key_args,
316312
*pool_key_args,
317313
"--out-file",

cardano_clusterlib/transaction_group.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def build_raw_tx_bare( # noqa: C901
328328
misc_args.append("--json-metadata-detailed-schema")
329329

330330
proposal_file_argname = txtools.get_proposal_file_argname(
331-
command_era=self._clusterlib_obj.command_era
331+
era_in_use=self._clusterlib_obj.era_in_use
332332
)
333333

334334
cli_args = [
@@ -726,28 +726,15 @@ def calculate_min_req_utxo(
726726
)
727727
raise AssertionError(msg)
728728

729-
era = self._clusterlib_obj.g_query.get_era().lower()
730-
era_upper = era.upper()
731-
command_era_args = []
732-
if (
733-
self._clusterlib_obj.command_era
734-
or (era_upper not in consts.Eras.__members__)
735-
or consts.Eras[era_upper].value >= consts.Eras.CONWAY.value
736-
):
737-
command_era_args = [era]
738-
739729
self._clusterlib_obj.create_pparams_file()
740730
stdout = self._clusterlib_obj.cli(
741731
[
742-
"cardano-cli",
743-
*command_era_args,
744732
"transaction",
745733
"calculate-min-required-utxo",
746734
"--protocol-params-file",
747735
str(self._clusterlib_obj.pparams_file),
748736
*txout_args,
749-
],
750-
add_default_args=False,
737+
]
751738
).stdout
752739
coin, value = stdout.decode().split()
753740
return structs.Value(value=int(value), coin=coin)
@@ -941,7 +928,7 @@ def build_tx( # noqa: C901
941928
misc_args.append("--json-metadata-detailed-schema")
942929

943930
proposal_file_argname = txtools.get_proposal_file_argname(
944-
command_era=self._clusterlib_obj.command_era
931+
era_in_use=self._clusterlib_obj.era_in_use
945932
)
946933

947934
cli_args = [

cardano_clusterlib/txtools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,11 +1283,11 @@ def _get_script_args( # noqa: C901
12831283
return grouped_args
12841284

12851285

1286-
def get_proposal_file_argname(command_era: str = "") -> str:
1286+
def get_proposal_file_argname(era_in_use: str = "") -> str:
12871287
"""Return the name of the proposal file argument."""
12881288
proposal_file_argname = (
12891289
"--proposal-file"
1290-
if (consts.Eras[(command_era or "DEFAULT").upper()].value >= consts.Eras.CONWAY.value)
1290+
if (consts.Eras[era_in_use.upper()].value >= consts.Eras.CONWAY.value)
12911291
else "--update-proposal-file"
12921292
)
12931293
return proposal_file_argname

0 commit comments

Comments
 (0)