From ac063214e13cdac275d75687db8de8463df9c3af Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 27 Jun 2023 17:02:05 -0700 Subject: [PATCH] [Bug fix] Allow minting script to be added without redeemer (#257) --- pycardano/txbuilder.py | 3 ++- test/pycardano/test_txbuilder.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pycardano/txbuilder.py b/pycardano/txbuilder.py index b2292e20..9aac15a3 100644 --- a/pycardano/txbuilder.py +++ b/pycardano/txbuilder.py @@ -752,7 +752,8 @@ def _set_redeemer_index(self): ) for script, redeemer in self._minting_script_to_redeemers: - redeemer.index = sorted_mint_policies.index(script_hash(script)) + if redeemer is not None: + redeemer.index = sorted_mint_policies.index(script_hash(script)) self.redeemers.sort(key=lambda r: r.index) diff --git a/test/pycardano/test_txbuilder.py b/test/pycardano/test_txbuilder.py index 862c75dd..a8902a94 100644 --- a/test/pycardano/test_txbuilder.py +++ b/test/pycardano/test_txbuilder.py @@ -858,6 +858,28 @@ def test_add_minting_script(chain_context): assert [plutus_script] == witness.plutus_v1_script +def test_add_minting_script_only(chain_context): + tx_builder = TransactionBuilder(chain_context) + tx_in1 = TransactionInput.from_primitive( + ["18cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef", 0] + ) + plutus_script = PlutusV1Script(b"dummy test script") + script_hash = plutus_script_hash(plutus_script) + script_address = Address(script_hash) + utxo1 = UTxO(tx_in1, TransactionOutput(script_address, 10000000)) + mint = MultiAsset.from_primitive({script_hash.payload: {b"TestToken": 1}}) + tx_builder.mint = mint + tx_builder.add_input(utxo1) + tx_builder.add_minting_script(plutus_script) + receiver = Address.from_primitive( + "addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x" + ) + tx_builder.add_output(TransactionOutput(receiver, Value(5000000, mint))) + tx_body = tx_builder.build(change_address=receiver) + witness = tx_builder.build_witness_set() + assert [plutus_script] == witness.plutus_v1_script + + def test_add_minting_script_wrong_redeemer_type(chain_context): tx_builder = TransactionBuilder(chain_context) plutus_script = PlutusV1Script(b"dummy test script")