Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace send_funds with send_tx #2814

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 46 additions & 48 deletions cardano_node_tests/tests/test_native_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,40 +1734,40 @@ def test_transfer_tokens(
src_address = new_token.token_mint_addr.address
dst_address = payment_addrs[2].address

ma_destinations = [
ma_txouts = [
clusterlib.TxOut(address=dst_address, amount=amount, coin=new_token.token),
]

# Destinations with both native token and Lovelace (it doesn't matter on the amounts) for
# calculating minimum required Lovelace value for tx output
calc_destinations = [
*ma_destinations,
calc_txouts = [
*ma_txouts,
clusterlib.TxOut(address=dst_address, amount=2_000_000),
]

min_value = cluster.g_transaction.calculate_min_req_utxo(txouts=calc_destinations)
min_value = cluster.g_transaction.calculate_min_req_utxo(txouts=calc_txouts)
assert min_value.coin.lower() in (clusterlib.DEFAULT_COIN, "coin")
assert min_value.value, "No Lovelace required for `min-ada-value`"
amount_lovelace = min_value.value

destinations = [
*ma_destinations,
txouts = [
*ma_txouts,
clusterlib.TxOut(address=dst_address, amount=amount_lovelace),
]

tx_files = clusterlib.TxFiles(signing_key_files=[new_token.token_mint_addr.skey_file])

if use_build_cmd:
# TODO: add ADA txout for change address - see node issue #3057
destinations.append(clusterlib.TxOut(address=src_address, amount=2_000_000))
txouts.append(clusterlib.TxOut(address=src_address, amount=2_000_000))

if VERSIONS.transaction_era == VERSIONS.ALONZO:
err_str = ""
try:
cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -1782,16 +1782,16 @@ def test_transfer_tokens(
min_reported_utxo = _min_reported_utxo.group(1)
amount_lovelace = int(min_reported_utxo)

destinations = [
*ma_destinations,
txouts = [
*ma_txouts,
clusterlib.TxOut(address=dst_address, amount=amount_lovelace),
clusterlib.TxOut(address=src_address, amount=2_000_000),
]

tx_raw_output = cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -1802,10 +1802,10 @@ def test_transfer_tokens(
)
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
else:
tx_raw_output = cluster.g_transaction.send_funds(
tx_raw_output = cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
)

Expand Down Expand Up @@ -1880,44 +1880,44 @@ def test_transfer_multiple_tokens(
dst_address1 = payment_addrs[1].address
dst_address2 = payment_addrs[2].address

ma_destinations_address1 = []
ma_destinations_address2 = []
ma_txouts_address1 = []
ma_txouts_address2 = []
for t in new_tokens:
ma_destinations_address1.append(
ma_txouts_address1.append(
clusterlib.TxOut(address=dst_address1, amount=amount, coin=t.token)
)
ma_destinations_address2.append(
ma_txouts_address2.append(
clusterlib.TxOut(address=dst_address2, amount=amount, coin=t.token)
)

# Destinations with both native token and Lovelace (it doesn't matter on the amounts) for
# calculating minimum required Lovelace value for tx output
calc_destinations_address1 = [
*ma_destinations_address1,
calc_txouts_address1 = [
*ma_txouts_address1,
clusterlib.TxOut(address=dst_address1, amount=2_000_000),
]
calc_destinations_address2 = [
*ma_destinations_address2,
calc_txouts_address2 = [
*ma_txouts_address2,
clusterlib.TxOut(address=dst_address2, amount=2_000_000),
]

min_value_address1 = cluster.g_transaction.calculate_min_req_utxo(
txouts=calc_destinations_address1
txouts=calc_txouts_address1
)
assert min_value_address1.coin.lower() in (clusterlib.DEFAULT_COIN, "coin")
assert min_value_address1.value, "No Lovelace required for `min-ada-value`"
amount_lovelace_address1 = min_value_address1.value

min_value_address2 = cluster.g_transaction.calculate_min_req_utxo(
txouts=calc_destinations_address2
txouts=calc_txouts_address2
)
assert min_value_address2.value, "No Lovelace required for `min-ada-value`"
amount_lovelace_address2 = min_value_address2.value

destinations = [
*ma_destinations_address1,
txouts = [
*ma_txouts_address1,
clusterlib.TxOut(address=dst_address1, amount=amount_lovelace_address1),
*ma_destinations_address2,
*ma_txouts_address2,
clusterlib.TxOut(address=dst_address2, amount=amount_lovelace_address2),
]

Expand All @@ -1927,7 +1927,7 @@ def test_transfer_multiple_tokens(

if use_build_cmd:
# TODO: add ADA txout for change address
destinations.append(clusterlib.TxOut(address=src_address, amount=4_000_000))
txouts.append(clusterlib.TxOut(address=src_address, amount=4_000_000))

# TODO: see node issue #4297
if VERSIONS.transaction_era == VERSIONS.ALONZO:
Expand All @@ -1936,7 +1936,7 @@ def test_transfer_multiple_tokens(
cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -1951,18 +1951,18 @@ def test_transfer_multiple_tokens(
min_reported_utxo = _min_reported_utxo.group(1)
amount_lovelace_address1 = amount_lovelace_address2 = int(min_reported_utxo)

destinations = [
*ma_destinations_address1,
txouts = [
*ma_txouts_address1,
clusterlib.TxOut(address=dst_address1, amount=amount_lovelace_address1),
*ma_destinations_address2,
*ma_txouts_address2,
clusterlib.TxOut(address=dst_address2, amount=amount_lovelace_address2),
clusterlib.TxOut(address=src_address, amount=4_000_000),
]

tx_raw_output = cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -1973,10 +1973,10 @@ def test_transfer_multiple_tokens(
)
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
else:
tx_raw_output = cluster.g_transaction.send_funds(
tx_raw_output = cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
)

Expand Down Expand Up @@ -2043,19 +2043,19 @@ def test_transfer_no_ada(
src_address = new_token.token_mint_addr.address
dst_address = payment_addrs[2].address

destinations = [clusterlib.TxOut(address=dst_address, amount=amount, coin=new_token.token)]
txouts = [clusterlib.TxOut(address=dst_address, amount=amount, coin=new_token.token)]
tx_files = clusterlib.TxFiles(signing_key_files=[new_token.token_mint_addr.skey_file])

if use_build_cmd:
expected_error = "Minimum required UTxO:"
# TODO: add ADA txout for change address
destinations.append(clusterlib.TxOut(address=src_address, amount=3500_000))
txouts.append(clusterlib.TxOut(address=src_address, amount=3500_000))

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -2064,10 +2064,10 @@ def test_transfer_no_ada(
expected_error = "OutputTooSmallUTxO"

try:
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
)
except clusterlib.CLIError as err:
Expand Down Expand Up @@ -2098,14 +2098,14 @@ def test_transfer_invalid_token_amount(
src_address = new_token.token_mint_addr.address
dst_address = payment_addrs[2].address

ma_destinations = [
ma_txouts = [
clusterlib.TxOut(address=dst_address, amount=token_amount, coin=new_token.token),
]

min_amount_lovelace = 4_000_000

destinations = [
*ma_destinations,
txouts = [
*ma_txouts,
clusterlib.TxOut(address=dst_address, amount=min_amount_lovelace),
]

Expand All @@ -2114,16 +2114,14 @@ def test_transfer_invalid_token_amount(
if use_build_cmd:
with pytest.raises(clusterlib.CLIError) as excinfo:
# Add ADA txout for change address - see node issue #3057
destinations.append(
clusterlib.TxOut(address=src_address, amount=min_amount_lovelace)
)
txouts.append(clusterlib.TxOut(address=src_address, amount=min_amount_lovelace))

try:
logging.disable(logging.ERROR)
cluster.g_transaction.build_tx(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
fee_buffer=2_000_000,
tx_files=tx_files,
)
Expand All @@ -2140,9 +2138,9 @@ def test_transfer_invalid_token_amount(
with pytest.raises(clusterlib.CLIError) as excinfo:
try:
logging.disable(logging.ERROR)
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
txouts=txouts,
tx_name=temp_template,
tx_files=tx_files,
fee=80_000,
Expand Down
12 changes: 6 additions & 6 deletions cardano_node_tests/tests/test_staking_no_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ def test_no_reward_unmet_pledge2(
pledge_amount = loaded_data.pool_pledge // 2

# Withdraw part of the pledge
destinations = [
txouts = [
clusterlib.TxOut(address=delegation_out.pool_user.payment.address, amount=pledge_amount)
]
tx_files = clusterlib.TxFiles(signing_key_files=[pool_owner.payment.skey_file])
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=pool_owner.payment.address,
destinations=destinations,
tx_name=f"{temp_template}_withdraw_pledge",
txouts=txouts,
tx_files=tx_files,
)

Expand Down Expand Up @@ -325,18 +325,18 @@ def test_no_reward_unmet_pledge2(
)

# Return pledge
destinations = [
txouts = [
clusterlib.TxOut(
address=pool_owner.payment.address, amount=pledge_amount + 100_000_000
)
]
tx_files = clusterlib.TxFiles(
signing_key_files=[delegation_out.pool_user.payment.skey_file]
)
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=delegation_out.pool_user.payment.address,
destinations=destinations,
tx_name=f"{temp_template}_return_pledge",
txouts=txouts,
tx_files=tx_files,
)

Expand Down
22 changes: 11 additions & 11 deletions cardano_node_tests/tests/test_tx_fees.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ def test_negative_fee(
src_address = payment_addrs[0].address
dst_address = payment_addrs[1].address

destinations = [clusterlib.TxOut(address=dst_address, amount=10)]
txouts = [clusterlib.TxOut(address=dst_address, amount=10)]
tx_files = clusterlib.TxFiles(signing_key_files=[payment_addrs[0].skey_file])

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
fee=fee,
)
Expand All @@ -119,7 +119,7 @@ def test_smaller_fee(
src_address = payment_addrs[0].address
dst_address = payment_addrs[1].address

destinations = [clusterlib.TxOut(address=dst_address, amount=10)]
txouts = [clusterlib.TxOut(address=dst_address, amount=10)]
tx_files = clusterlib.TxFiles(signing_key_files=[payment_addrs[0].skey_file])

fee = 0.0
Expand All @@ -128,17 +128,17 @@ def test_smaller_fee(
cluster.g_transaction.calculate_tx_fee(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
tx_files=tx_files,
)
/ fee_change
)

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.send_funds(
cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
fee=int(fee),
)
Expand All @@ -161,22 +161,22 @@ def test_expected_or_higher_fee(
src_address = payment_addrs[0].address
dst_address = payment_addrs[1].address

destinations = [clusterlib.TxOut(address=dst_address, amount=amount)]
txouts = [clusterlib.TxOut(address=dst_address, amount=amount)]
tx_files = clusterlib.TxFiles(signing_key_files=[payment_addrs[0].skey_file])
fee = (
cluster.g_transaction.calculate_tx_fee(
src_address=src_address,
tx_name=temp_template,
txouts=destinations,
txouts=txouts,
tx_files=tx_files,
)
+ fee_add
)

tx_raw_output = cluster.g_transaction.send_funds(
tx_raw_output = cluster.g_transaction.send_tx(
src_address=src_address,
destinations=destinations,
tx_name=temp_template,
txouts=txouts,
tx_files=tx_files,
fee=fee,
)
Expand Down
Loading
Loading