Skip to content

Commit

Permalink
[Bug fix] Allow minting script to be added without redeemer (Python-C…
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls authored Jun 28, 2023
1 parent bc02bd6 commit ac06321
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pycardano/txbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions test/pycardano/test_txbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ac06321

Please sign in to comment.