Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle utxoCostPerByte vs coinsPerUtxoByte in cardano-cli chain context protocol params #351

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration-test/test/test_cardano_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_protocol_param(self):

assert protocol_param is not None
assert isinstance(protocol_param, ProtocolParameters)
assert protocol_param.coins_per_utxo_byte is not None

cost_models = protocol_param.cost_models
for cost_model in cost_models.items():
Expand Down
11 changes: 5 additions & 6 deletions pycardano/backend/cardano_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,8 @@ def _get_min_utxo(self) -> int:
and params["lovelacePerUTxOWord"] is not None
):
return params["lovelacePerUTxOWord"]
elif "utxoCostPerWord" in params and params["utxoCostPerWord"] is not None:
return params["utxoCostPerWord"]
elif "utxoCostPerByte" in params and params["utxoCostPerByte"] is not None:
return params["utxoCostPerByte"]
raise ValueError("Cannot determine minUTxOValue, invalid protocol params")
else:
return 0

@staticmethod
def _parse_cost_models(cli_result: JsonDict) -> Dict[str, Dict[str, int]]:
Expand Down Expand Up @@ -312,7 +309,9 @@ def _fetch_protocol_param(self) -> ProtocolParameters:
coins_per_utxo_word=result.get(
"coinsPerUtxoWord", ALONZO_COINS_PER_UTXO_WORD
),
coins_per_utxo_byte=result.get("coinsPerUtxoByte", 0),
coins_per_utxo_byte=result["coinsPerUtxoByte"]
if "coinsPerUtxoByte" in result
else result.get("utxoCostPerByte", 0) or 0,
cost_models=self._parse_cost_models(result),
)

Expand Down
9 changes: 7 additions & 2 deletions test/pycardano/backend/test_cardano_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ def test_protocol_param(self, chain_context):
protocol_minor_version=int(
QUERY_PROTOCOL_PARAMETERS_RESULT["protocolVersion"]["minor"]
),
min_utxo=QUERY_PROTOCOL_PARAMETERS_RESULT["utxoCostPerByte"],
min_utxo=QUERY_PROTOCOL_PARAMETERS_RESULT.get(
"minUTxOValue",
QUERY_PROTOCOL_PARAMETERS_RESULT.get("lovelacePerUTxOWord", 0),
)
or 0,
min_pool_cost=QUERY_PROTOCOL_PARAMETERS_RESULT["minPoolCost"],
price_mem=float(
QUERY_PROTOCOL_PARAMETERS_RESULT["executionUnitPrices"][
Expand Down Expand Up @@ -596,7 +600,8 @@ def test_protocol_param(self, chain_context):
"coinsPerUtxoWord", ALONZO_COINS_PER_UTXO_WORD
),
coins_per_utxo_byte=QUERY_PROTOCOL_PARAMETERS_RESULT.get(
"coinsPerUtxoByte", 0
"coinsPerUtxoByte",
QUERY_PROTOCOL_PARAMETERS_RESULT.get("utxoCostPerByte", 0),
),
cost_models={
l: {
Expand Down
Loading