|
1 | 1 | from dataclasses import replace
|
2 | 2 | from test.pycardano.test_key import SK
|
3 | 3 | from test.pycardano.util import chain_context
|
| 4 | +from unittest.mock import patch |
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 |
|
@@ -924,3 +925,82 @@ def test_tx_builder_merge_change_to_zero_amount_output(chain_context):
|
924 | 925 | }
|
925 | 926 |
|
926 | 927 | assert expected == tx_body.to_primitive()
|
| 928 | + |
| 929 | + |
| 930 | +def test_tx_builder_small_utxo_input(chain_context): |
| 931 | + with patch.object(chain_context, "utxos") as mock_utxos: |
| 932 | + mock_utxos.return_value = [ |
| 933 | + UTxO( |
| 934 | + TransactionInput.from_primitive( |
| 935 | + [ |
| 936 | + "41cb004bec7051621b19b46aea28f0657a586a05ce2013152ea9b9f1a5614cc7", |
| 937 | + 1, |
| 938 | + ] |
| 939 | + ), |
| 940 | + TransactionOutput.from_primitive( |
| 941 | + [ |
| 942 | + "addr1qytqt3v9ej3kzefxcy8f59h9atf2knracnj5snkgtaea6p4r8g3mu652945v3gldw7v88dn5lrfudx0un540ak9qt2kqhfjl0d", |
| 943 | + 2991353, |
| 944 | + ] |
| 945 | + ), |
| 946 | + ) |
| 947 | + ] |
| 948 | + builder = TransactionBuilder(chain_context) |
| 949 | + address = Address.from_primitive( |
| 950 | + "addr1qytqt3v9ej3kzefxcy8f59h9atf2knracnj5snkgtaea6p4r8g3mu652945v3gldw7v88dn5lrfudx0un540ak9qt2kqhfjl0d" |
| 951 | + ) |
| 952 | + builder.add_input_address(address) |
| 953 | + |
| 954 | + builder.add_output( |
| 955 | + TransactionOutput( |
| 956 | + Address.from_primitive( |
| 957 | + "addr1qyady0evsaxqsfmz0z8rvmq62fmuas5w8n4m8z6qcm4wrt3e8dlsen8n464ucw69acfgdxgguscgfl5we3rwts4s57ashysyee" |
| 958 | + ), |
| 959 | + Value.from_primitive( |
| 960 | + [ |
| 961 | + 1000000, |
| 962 | + ] |
| 963 | + ), |
| 964 | + ) |
| 965 | + ) |
| 966 | + signed_tx = builder.build(change_address=address) |
| 967 | + |
| 968 | + |
| 969 | +def test_tx_builder_merge_change_to_output_3(chain_context): |
| 970 | + with patch.object(chain_context, "utxos") as mock_utxos: |
| 971 | + mock_utxos.return_value = [ |
| 972 | + UTxO( |
| 973 | + TransactionInput.from_primitive( |
| 974 | + [ |
| 975 | + "41cb004bec7051621b19b46aea28f0657a586a05ce2013152ea9b9f1a5614cc7", |
| 976 | + 1, |
| 977 | + ] |
| 978 | + ), |
| 979 | + TransactionOutput.from_primitive( |
| 980 | + [ |
| 981 | + "addr1qytqt3v9ej3kzefxcy8f59h9atf2knracnj5snkgtaea6p4r8g3mu652945v3gldw7v88dn5lrfudx0un540ak9qt2kqhfjl0d", |
| 982 | + 2991353, |
| 983 | + ] |
| 984 | + ), |
| 985 | + ) |
| 986 | + ] |
| 987 | + builder = TransactionBuilder(chain_context) |
| 988 | + address = Address.from_primitive( |
| 989 | + "addr1qytqt3v9ej3kzefxcy8f59h9atf2knracnj5snkgtaea6p4r8g3mu652945v3gldw7v88dn5lrfudx0un540ak9qt2kqhfjl0d" |
| 990 | + ) |
| 991 | + builder.add_input_address(address) |
| 992 | + |
| 993 | + builder.add_output( |
| 994 | + TransactionOutput( |
| 995 | + Address.from_primitive( |
| 996 | + "addr1qytqt3v9ej3kzefxcy8f59h9atf2knracnj5snkgtaea6p4r8g3mu652945v3gldw7v88dn5lrfudx0un540ak9qt2kqhfjl0d" |
| 997 | + ), |
| 998 | + Value.from_primitive( |
| 999 | + [ |
| 1000 | + 1000000, |
| 1001 | + ] |
| 1002 | + ), |
| 1003 | + ) |
| 1004 | + ) |
| 1005 | + tx = builder.build(change_address=address, merge_change=True) |
| 1006 | + assert len(tx.outputs) == 1 |
0 commit comments