Skip to content

Commit

Permalink
Merge pull request #1212 from mkoura/use_utxo_helpers
Browse files Browse the repository at this point in the history
Use UTxO helper functions
  • Loading branch information
mkoura committed Jun 29, 2022
2 parents f7f3fa1 + 5cef945 commit 5ae338c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 70 deletions.
58 changes: 22 additions & 36 deletions cardano_node_tests/tests/test_plutus_v2_spend_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,13 @@ def test_txout_locking(
)

# check that script address UTxO was spent
script_utxo = f"{script_utxos[0].utxo_hash}#{script_utxos[0].utxo_ix}"
assert not cluster.get_utxo(
txin=script_utxo
), f"Script address UTxO was not spent `{script_utxo}`"
utxo=script_utxos[0]
), f"Script address UTxO was not spent `{script_utxos}`"

# check that reference UTxO was NOT spent
assert not reference_utxo or cluster.get_utxo(
txin=f"{reference_utxo.utxo_hash}#{reference_utxo.utxo_ix}"
utxo=reference_utxo
), "Reference input was spent"

# check expected fees
Expand Down Expand Up @@ -746,11 +745,9 @@ def test_reference_multiple_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
def test_reference_same_script(
Expand Down Expand Up @@ -888,11 +885,9 @@ def test_reference_same_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
def test_mix_reference_attached_script(
Expand Down Expand Up @@ -1034,11 +1029,9 @@ def test_mix_reference_attached_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize("script_type", ("simple", "plutus_v1", "plutus_v2"))
Expand Down Expand Up @@ -1613,12 +1606,9 @@ def test_use_reference_input(
)

# check that the reference input was not spent
reference_input_utxo = cluster.get_utxo(
txin=f"{reference_input[0].utxo_hash}#{reference_input[0].utxo_ix}"
)

reference_input_utxo = cluster.get_utxo(utxo=reference_input[0])
assert (
reference_input_utxo[0].amount == reference_input_amount
clusterlib.calculate_utxos_balance(utxos=reference_input_utxo) == reference_input_amount
), f"The reference input was spent `{reference_input_utxo}`"

# TODO check command 'transaction view' bug on cardano-node 4045
Expand Down Expand Up @@ -1709,10 +1699,10 @@ def test_same_input_as_reference_input(
)

# check that the input used also as reference was spent
reference_txin = f"{reference_input[0].utxo_hash}#{reference_input[0].utxo_ix}"
reference_input_utxo = cluster.get_utxo(txin=reference_txin)

assert not reference_input_utxo, f"The reference input was not spent `{reference_txin}`"
reference_input_utxo = cluster.get_utxo(utxo=reference_input[0])
assert (
not reference_input_utxo
), f"The reference input was not spent `{reference_input_utxo}`"

# TODO check command 'transaction view' bug on cardano-node 4045

Expand Down Expand Up @@ -1762,8 +1752,6 @@ def test_reference_spent_output(
amount=reference_input_amount,
)

reference_utxo = f"{reference_input[0].utxo_hash}#{reference_input[0].utxo_ix}"

# spend the output that will be used as reference input

tx_output_spend_reference_input = cluster.build_tx(
Expand All @@ -1781,9 +1769,10 @@ def test_reference_spent_output(
cluster.submit_tx(tx_file=tx_signed, txins=tx_output_spend_reference_input.txins)

# check that the input used also as reference was spent
reference_input_utxo = cluster.get_utxo(txin=reference_utxo)

assert not reference_input_utxo, f"The reference input was not spent `{reference_utxo}`"
reference_input_utxo = cluster.get_utxo(utxo=reference_input[0])
assert (
not reference_input_utxo
), f"The reference input was not spent `{reference_input_utxo}`"

# spend the "locked" UTxO

Expand Down Expand Up @@ -2136,14 +2125,11 @@ def test_collateral_with_tokens(
return_col_utxos = cluster.get_utxo(txin=f"{txid_redeem}#2")
assert return_col_utxos, "Return collateral UTxO was not created"

return_col_utxos_lovelace = [
u for u in return_col_utxos if u.coin == clusterlib.DEFAULT_COIN
]
assert (
return_col_utxos_lovelace[0].amount == return_collateral_amount
clusterlib.calculate_utxos_balance(utxos=return_col_utxos) == return_collateral_amount
), f"Incorrect balance for collateral return address `{dst_addr.address}`"

return_col_utxos_token = [u for u in return_col_utxos if u.coin == tokens_rec[0].coin]
assert (
return_col_utxos_token[0].amount == tokens_rec[0].amount
clusterlib.calculate_utxos_balance(utxos=return_col_utxos, coin=tokens_rec[0].coin)
== tokens_rec[0].amount
), f"Incorrect token balance for collateral return address `{dst_addr.address}`"
46 changes: 15 additions & 31 deletions cardano_node_tests/tests/test_plutus_v2_spend_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,13 @@ def test_txout_locking(
), f"Incorrect balance for destination address `{payment_addrs[1].address}`"

# check that script address UTxO was spent
script_utxo = f"{script_utxos[0].utxo_hash}#{script_utxos[0].utxo_ix}"
assert not cluster.get_utxo(
txin=script_utxo
), f"Script address UTxO was not spent `{script_utxo}`"
utxo=script_utxos[0]
), f"Script address UTxO was not spent `{script_utxos[0]}`"

# check that reference UTxO was NOT spent
assert not reference_utxo or cluster.get_utxo(
txin=f"{reference_utxo.utxo_hash}#{reference_utxo.utxo_ix}"
utxo=reference_utxo
), "Reference input was spent"


Expand Down Expand Up @@ -740,11 +739,9 @@ def test_reference_multiple_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
def test_reference_same_script(
Expand Down Expand Up @@ -881,11 +878,9 @@ def test_reference_same_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
def test_mix_reference_attached_script(
Expand Down Expand Up @@ -1026,11 +1021,9 @@ def test_mix_reference_attached_script(
)

# check that script address UTxOs were spent
script_utxo1 = f"{script_utxos1[0].utxo_hash}#{script_utxos1[0].utxo_ix}"
script_utxo2 = f"{script_utxos2[0].utxo_hash}#{script_utxos2[0].utxo_ix}"
assert not (
cluster.get_utxo(txin=script_utxo1) or cluster.get_utxo(txin=script_utxo2)
), f"Script address UTxOs were NOT spent - `{script_utxo1}` and `{script_utxo2}`"
cluster.get_utxo(utxo=script_utxos1[0]) or cluster.get_utxo(utxo=script_utxos2[0])
), f"Script address UTxOs were NOT spent - `{script_utxos1}` and `{script_utxos2}`"

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize("script_type", ("simple", "plutus_v1", "plutus_v2"))
Expand Down Expand Up @@ -1626,12 +1619,9 @@ def test_use_reference_input(
)

# check that the reference input was not spent
reference_input_utxo = cluster.get_utxo(
txin=f"{reference_input[0].utxo_hash}#{reference_input[0].utxo_ix}"
)

reference_input_utxo = cluster.get_utxo(utxo=reference_input[0])
assert (
reference_input_utxo[0].amount == amount
clusterlib.calculate_utxos_balance(utxos=reference_input_utxo) == amount
), f"The reference input was spent `{reference_input_utxo}`"

@allure.link(helpers.get_vcs_link())
Expand Down Expand Up @@ -1718,10 +1708,7 @@ def test_same_input_as_reference_input(
)

# check that the reference input was spent
reference_input_utxo = cluster.get_utxo(
txin=f"{reference_input[0].utxo_hash}#{reference_input[0].utxo_ix}"
)

reference_input_utxo = cluster.get_utxo(utxo=reference_input[0])
assert (
not reference_input_utxo
), f"The reference input was not spent `{reference_input_utxo}`"
Expand Down Expand Up @@ -2167,14 +2154,11 @@ def test_collateral_with_tokens(
return_col_utxos = cluster.get_utxo(txin=f"{txid_redeem}#{len(txouts_redeem)}")
assert return_col_utxos, "Return collateral UTxO was not created"

return_col_utxos_lovelace = [
u for u in return_col_utxos if u.coin == clusterlib.DEFAULT_COIN
]
assert (
return_col_utxos_lovelace[0].amount == return_collateral_amount
clusterlib.calculate_utxos_balance(utxos=return_col_utxos) == return_collateral_amount
), f"Incorrect balance for collateral return address `{dst_addr.address}`"

return_col_utxos_token = [u for u in return_col_utxos if u.coin == tokens_rec[0].coin]
assert (
return_col_utxos_token[0].amount == tokens_rec[0].amount
clusterlib.calculate_utxos_balance(utxos=return_col_utxos, coin=tokens_rec[0].coin)
== tokens_rec[0].amount
), f"Incorrect token balance for collateral return address `{dst_addr.address}`"
4 changes: 2 additions & 2 deletions nix/cardano-clusterlib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

buildPythonPackage rec {
pname = "cardano-clusterlib";
version = "0.3.0rc5";
version = "0.3.0rc6";
src = fetchPypi {
inherit pname version;
sha256 = "6RN/OvapNejKCl5y5h5Gr57g3Xkq2PI1IC0hLNNnZw8=";
sha256 = "r3kWeQn7LZ2adaI7/a8Lc0txjMi9KhEINqh0t0qmCWs=";
};
doCheck = false;
nativeBuildInputs = [ setuptools_scm ];
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ setup_requires =
setuptools_scm
install_requires =
allure-pytest
cardano-clusterlib >= 0.3.0rc5,<0.4.0
cardano-clusterlib >= 0.3.0rc6,<0.4.0
cbor2
filelock
hypothesis
Expand Down

0 comments on commit 5ae338c

Please sign in to comment.