Skip to content

Commit 01edc0d

Browse files
authored
Handle utxoCostPerByte vs coinsPerUtxoByte in cardano-cli chain context protocol params (#351)
* fix: use utxoCostPerByte if coinsPerUtxoByte not available in protocol parameters * test: fix test to handle changes * fix: set coins_per_utxo_byte to 0 if coinsPerUtxoByte or utxoCostPerByte not in protocol params * fix: set coins_per_utxo_byte to 0 if utxoCostPerByte is None * test: check coins_per_utxo_byte
1 parent 20e8ed7 commit 01edc0d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

integration-test/test/test_cardano_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_protocol_param(self):
4040

4141
assert protocol_param is not None
4242
assert isinstance(protocol_param, ProtocolParameters)
43+
assert protocol_param.coins_per_utxo_byte is not None
4344

4445
cost_models = protocol_param.cost_models
4546
for cost_model in cost_models.items():

pycardano/backend/cardano_cli.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,8 @@ def _get_min_utxo(self) -> int:
237237
and params["lovelacePerUTxOWord"] is not None
238238
):
239239
return params["lovelacePerUTxOWord"]
240-
elif "utxoCostPerWord" in params and params["utxoCostPerWord"] is not None:
241-
return params["utxoCostPerWord"]
242-
elif "utxoCostPerByte" in params and params["utxoCostPerByte"] is not None:
243-
return params["utxoCostPerByte"]
244-
raise ValueError("Cannot determine minUTxOValue, invalid protocol params")
240+
else:
241+
return 0
245242

246243
@staticmethod
247244
def _parse_cost_models(cli_result: JsonDict) -> Dict[str, Dict[str, int]]:
@@ -312,7 +309,9 @@ def _fetch_protocol_param(self) -> ProtocolParameters:
312309
coins_per_utxo_word=result.get(
313310
"coinsPerUtxoWord", ALONZO_COINS_PER_UTXO_WORD
314311
),
315-
coins_per_utxo_byte=result.get("coinsPerUtxoByte", 0),
312+
coins_per_utxo_byte=result["coinsPerUtxoByte"]
313+
if "coinsPerUtxoByte" in result
314+
else result.get("utxoCostPerByte", 0) or 0,
316315
cost_models=self._parse_cost_models(result),
317316
)
318317

test/pycardano/backend/test_cardano_cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,11 @@ def test_protocol_param(self, chain_context):
561561
protocol_minor_version=int(
562562
QUERY_PROTOCOL_PARAMETERS_RESULT["protocolVersion"]["minor"]
563563
),
564-
min_utxo=QUERY_PROTOCOL_PARAMETERS_RESULT["utxoCostPerByte"],
564+
min_utxo=QUERY_PROTOCOL_PARAMETERS_RESULT.get(
565+
"minUTxOValue",
566+
QUERY_PROTOCOL_PARAMETERS_RESULT.get("lovelacePerUTxOWord", 0),
567+
)
568+
or 0,
565569
min_pool_cost=QUERY_PROTOCOL_PARAMETERS_RESULT["minPoolCost"],
566570
price_mem=float(
567571
QUERY_PROTOCOL_PARAMETERS_RESULT["executionUnitPrices"][
@@ -596,7 +600,8 @@ def test_protocol_param(self, chain_context):
596600
"coinsPerUtxoWord", ALONZO_COINS_PER_UTXO_WORD
597601
),
598602
coins_per_utxo_byte=QUERY_PROTOCOL_PARAMETERS_RESULT.get(
599-
"coinsPerUtxoByte", 0
603+
"coinsPerUtxoByte",
604+
QUERY_PROTOCOL_PARAMETERS_RESULT.get("utxoCostPerByte", 0),
600605
),
601606
cost_models={
602607
l: {

0 commit comments

Comments
 (0)