Skip to content

Commit 90d7f64

Browse files
committed
unit tests
1 parent d5fd4eb commit 90d7f64

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/pycardano/test_txbuilder.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,3 +2415,54 @@ def test_token_transfer_with_change(chain_context):
24152415
change_output.amount.multi_asset[token_policy_id][token_name]
24162416
== 1876083 - 382
24172417
)
2418+
2419+
2420+
def test_spend_utxo_with_script(chain_context):
2421+
"""Test that UTxOs with scripts are added as reference scripts when added directly."""
2422+
utxo = UTxO(
2423+
TransactionInput.from_primitive(
2424+
[
2425+
"a6cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef",
2426+
0,
2427+
]
2428+
),
2429+
TransactionOutput(
2430+
Address.from_primitive(
2431+
"addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x"
2432+
),
2433+
Value(10000000),
2434+
script=PlutusV2Script(b"dummy test script"),
2435+
),
2436+
)
2437+
2438+
tx_builder = TransactionBuilder(chain_context)
2439+
tx_builder.add_input(utxo)
2440+
assert len(tx_builder._reference_scripts) == 1
2441+
2442+
2443+
def test_skip_utxo_with_script(chain_context):
2444+
"""Test that UTxOs with scripts are skipped when selecting UTxOs by address."""
2445+
addr = Address.from_primitive(
2446+
"addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x"
2447+
)
2448+
2449+
utxo = UTxO(
2450+
TransactionInput.from_primitive(
2451+
[
2452+
"a6cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef",
2453+
0,
2454+
]
2455+
),
2456+
TransactionOutput(
2457+
addr,
2458+
Value(10000000),
2459+
script=PlutusV2Script(b"dummy test script"),
2460+
),
2461+
)
2462+
2463+
with patch.object(chain_context, "utxos") as mock_utxos:
2464+
mock_utxos.return_value = [utxo]
2465+
tx_builder = TransactionBuilder(chain_context)
2466+
tx_builder.add_input_address(addr)
2467+
with pytest.raises(UTxOSelectionException):
2468+
tx_builder.build()

0 commit comments

Comments
 (0)