Skip to content

Commit

Permalink
test build command with automatic collateral values and default chang…
Browse files Browse the repository at this point in the history
…e address
  • Loading branch information
saratomaz committed Jul 27, 2022
1 parent f47962d commit 782a292
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cardano_node_tests/tests/test_plutus_v2_spend_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,10 @@ def test_with_total_return_collateral(
assert plutus_op.datum_file
assert plutus_op.redeemer_cbor_file

protocol_params = cluster.get_protocol_params()

redeem_cost = plutus_common.compute_cost(
execution_cost=plutus_op.execution_cost, protocol_params=cluster.get_protocol_params()
execution_cost=plutus_op.execution_cost, protocol_params=protocol_params
)

# fund the script address and create a UTxO for collateral
Expand All @@ -2254,6 +2256,7 @@ def test_with_total_return_collateral(
collateral_amount=amount_for_collateral,
)

payment_init_balance = cluster.get_address_balance(payment_addr.address)
dst_init_balance = cluster.get_address_balance(dst_addr.address)

# spend the "locked" UTxO
Expand All @@ -2280,17 +2283,30 @@ def test_with_total_return_collateral(
dst_balance == dst_init_balance - redeem_cost.collateral
), f"Collateral was NOT spent from `{dst_addr.address}` correctly"

if use_return_collateral:
if use_return_collateral or not use_total_collateral:
txid_redeem = cluster.get_txid(tx_body_file=tx_output_redeem.out_file)
return_col_utxos = cluster.get_utxo(
txin=f"{txid_redeem}#{len(tx_output_redeem.txouts) + 1}"
)
assert return_col_utxos, "Return collateral UTxO was not created"

assert (
clusterlib.calculate_utxos_balance(utxos=return_col_utxos)
== return_collateral_amount
), f"Incorrect balance for collateral return address `{dst_addr.address}`"
change_amount = clusterlib.calculate_utxos_balance(utxos=return_col_utxos)

if use_return_collateral:
assert (
change_amount == return_collateral_amount
), f"Incorrect balance for collateral return address `{dst_addr.address}`"
else:
# check that the collateral amount charged is according to 'collateralPercentage'
collateral_charged = amount_for_collateral - change_amount
assert collateral_charged == round(
tx_output_redeem.fee * protocol_params["collateralPercentage"] / 100
), "The collateral amount charged is not the expected"

payment_balance = cluster.get_address_balance(payment_addr.address)
assert payment_balance == payment_init_balance + clusterlib.calculate_utxos_balance(
utxos=return_col_utxos
), f"Incorrect balance for change address `{payment_addr.address}`"

@allure.link(helpers.get_vcs_link())
def test_collateral_with_tokens(
Expand Down

0 comments on commit 782a292

Please sign in to comment.