Skip to content

Commit 8bee032

Browse files
authored
Merge pull request #3114 from IntersectMBO/build_method_in_test_addr_reg
refactor(tests): Refactor tests to replace `PARAM_USE_BUILD_CMD` with `PARAM_BUILD_METHOD`
2 parents d12809c + f78f4ba commit 8bee032

File tree

2 files changed

+92
-91
lines changed

2 files changed

+92
-91
lines changed

cardano_node_tests/tests/common.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
),
4040
)
4141

42+
SKIPIF_BUILD_EST_1199 = pytest.mark.skipif(
43+
issues.cli_1199.is_blocked(),
44+
reason="`build-estimate` fails to balance tx with no txouts",
45+
)
46+
4247
SKIPIF_MISMATCHED_ERAS = pytest.mark.skipif(
4348
VERSIONS.transaction_era != VERSIONS.cluster_era,
4449
reason="transaction era must be the same as node era",
@@ -101,6 +106,21 @@
101106
),
102107
)
103108

109+
PARAM_BUILD_METHOD_NO_EST = pytest.mark.parametrize(
110+
"build_method",
111+
(
112+
clusterlib_utils.BuildMethods.BUILD_RAW,
113+
pytest.param(
114+
clusterlib_utils.BuildMethods.BUILD,
115+
marks=SKIPIF_BUILD_UNUSABLE,
116+
),
117+
pytest.param(
118+
clusterlib_utils.BuildMethods.BUILD_EST,
119+
marks=SKIPIF_BUILD_EST_1199,
120+
),
121+
),
122+
)
123+
104124
PARAM_OFFLINE_BUILD_METHOD = pytest.mark.parametrize(
105125
"offline_build_method",
106126
(

cardano_node_tests/tests/test_addr_registration.py

Lines changed: 72 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TestRegisterAddr:
5555
"""Tests for stake address registration and deregistration."""
5656

5757
@allure.link(helpers.get_vcs_link())
58-
@common.PARAM_USE_BUILD_CMD
58+
@common.PARAM_BUILD_METHOD_NO_EST
5959
@pytest.mark.smoke
6060
@pytest.mark.testnets
6161
@pytest.mark.dbsync
@@ -64,7 +64,7 @@ def test_deregister_registered(
6464
cluster: clusterlib.ClusterLib,
6565
pool_users: list[clusterlib.PoolUser],
6666
pool_users_disposable: list[clusterlib.PoolUser],
67-
use_build_cmd: bool,
67+
build_method: str,
6868
):
6969
"""Deregister a registered stake address.
7070
@@ -96,26 +96,14 @@ def test_deregister_registered(
9696
signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file],
9797
)
9898

99-
if use_build_cmd:
100-
tx_raw_output_reg = cluster.g_transaction.build_tx(
101-
src_address=user_payment.address,
102-
tx_name=f"{temp_template}_reg",
103-
tx_files=tx_files_reg,
104-
fee_buffer=2_000_000,
105-
witness_override=len(tx_files_reg.signing_key_files),
106-
)
107-
tx_signed = cluster.g_transaction.sign_tx(
108-
tx_body_file=tx_raw_output_reg.out_file,
109-
signing_key_files=tx_files_reg.signing_key_files,
110-
tx_name=f"{temp_template}_reg",
111-
)
112-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_reg.txins)
113-
else:
114-
tx_raw_output_reg = cluster.g_transaction.send_tx(
115-
src_address=user_payment.address,
116-
tx_name=f"{temp_template}_reg",
117-
tx_files=tx_files_reg,
118-
)
99+
tx_output_reg = clusterlib_utils.build_and_submit_tx(
100+
cluster_obj=cluster,
101+
name_template=f"{temp_template}_reg",
102+
src_address=user_payment.address,
103+
tx_files=tx_files_reg,
104+
build_method=build_method,
105+
witness_override=len(tx_files_reg.signing_key_files),
106+
)
119107

120108
assert cluster.g_query.get_stake_addr_info(user_registered.stake.address).address, (
121109
f"Stake address is NOT registered: {user_registered.stake.address}"
@@ -134,35 +122,19 @@ def test_deregister_registered(
134122
signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file],
135123
)
136124

137-
if use_build_cmd:
138-
139-
def _build_dereg() -> clusterlib.TxRawOutput:
140-
return cluster.g_transaction.build_tx(
141-
src_address=user_payment.address,
142-
tx_name=f"{temp_template}_dereg",
143-
tx_files=tx_files_dereg,
144-
fee_buffer=2_000_000,
145-
witness_override=len(tx_files_dereg.signing_key_files),
146-
)
147-
148-
tx_raw_output_dereg: clusterlib.TxRawOutput = common.match_blocker(func=_build_dereg)
149-
tx_signed = cluster.g_transaction.sign_tx(
150-
tx_body_file=tx_raw_output_dereg.out_file,
151-
signing_key_files=tx_files_dereg.signing_key_files,
152-
tx_name=f"{temp_template}_dereg",
153-
)
154-
try:
155-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_dereg.txins)
156-
except clusterlib.CLIError as exc:
157-
if "ValueNotConservedUTxO" in str(exc):
158-
issues.cli_942.finish_test()
159-
raise
160-
else:
161-
tx_raw_output_dereg = cluster.g_transaction.send_tx(
125+
try:
126+
tx_output_dereg = clusterlib_utils.build_and_submit_tx(
127+
cluster_obj=cluster,
128+
name_template=f"{temp_template}_dereg",
162129
src_address=user_payment.address,
163-
tx_name=f"{temp_template}_dereg",
164130
tx_files=tx_files_dereg,
131+
build_method=build_method,
132+
witness_override=len(tx_files_dereg.signing_key_files),
165133
)
134+
except clusterlib.CLIError as exc:
135+
if "ValueNotConservedUTxO" in str(exc):
136+
issues.cli_942.finish_test()
137+
raise
166138

167139
assert not cluster.g_query.get_stake_addr_info(user_registered.stake.address).address, (
168140
f"Stake address is registered: {user_registered.stake.address}"
@@ -171,24 +143,22 @@ def _build_dereg() -> clusterlib.TxRawOutput:
171143
# Check that the balance for source address was correctly updated
172144
assert (
173145
cluster.g_query.get_address_balance(user_payment.address)
174-
== src_init_balance - tx_raw_output_reg.fee - tx_raw_output_dereg.fee
146+
== src_init_balance - tx_output_reg.fee - tx_output_dereg.fee
175147
), f"Incorrect balance for source address `{user_payment.address}`"
176148

177149
# Check records in db-sync
178-
tx_db_record_reg = dbsync_utils.check_tx(
179-
cluster_obj=cluster, tx_raw_output=tx_raw_output_reg
180-
)
150+
tx_db_record_reg = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output_reg)
181151
if tx_db_record_reg:
182152
assert user_registered.stake.address in tx_db_record_reg.stake_registration
183153

184154
tx_db_record_dereg = dbsync_utils.check_tx(
185-
cluster_obj=cluster, tx_raw_output=tx_raw_output_dereg
155+
cluster_obj=cluster, tx_raw_output=tx_output_dereg
186156
)
187157
if tx_db_record_dereg:
188158
assert user_registered.stake.address in tx_db_record_dereg.stake_deregistration
189159

190160
@allure.link(helpers.get_vcs_link())
191-
@common.PARAM_USE_BUILD_CMD
161+
@common.PARAM_BUILD_METHOD_NO_EST
192162
@pytest.mark.smoke
193163
@pytest.mark.testnets
194164
@pytest.mark.dbsync
@@ -197,7 +167,7 @@ def test_addr_registration_deregistration(
197167
cluster: clusterlib.ClusterLib,
198168
pool_users: list[clusterlib.PoolUser],
199169
pool_users_disposable: list[clusterlib.PoolUser],
200-
use_build_cmd: bool,
170+
build_method: str,
201171
):
202172
"""Submit registration and deregistration certificates in single TX.
203173
@@ -240,28 +210,15 @@ def test_addr_registration_deregistration(
240210
signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file],
241211
)
242212

243-
if use_build_cmd:
244-
tx_raw_output = cluster.g_transaction.build_tx(
245-
src_address=user_payment.address,
246-
tx_name=f"{temp_template}_reg_dereg",
247-
tx_files=tx_files,
248-
fee_buffer=2_000_000,
249-
deposit=0,
250-
witness_override=len(tx_files.signing_key_files),
251-
)
252-
tx_signed = cluster.g_transaction.sign_tx(
253-
tx_body_file=tx_raw_output.out_file,
254-
signing_key_files=tx_files.signing_key_files,
255-
tx_name=f"{temp_template}_reg_dereg",
256-
)
257-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
258-
else:
259-
tx_raw_output = cluster.g_transaction.send_tx(
260-
src_address=user_payment.address,
261-
tx_name=f"{temp_template}_reg_dereg",
262-
tx_files=tx_files,
263-
deposit=0,
264-
)
213+
tx_output = clusterlib_utils.build_and_submit_tx(
214+
cluster_obj=cluster,
215+
name_template=f"{temp_template}_reg_dereg",
216+
src_address=user_payment.address,
217+
tx_files=tx_files,
218+
build_method=build_method,
219+
deposit=0,
220+
witness_override=len(tx_files.signing_key_files),
221+
)
265222

266223
# Check that the stake address is not registered
267224
assert not cluster.g_query.get_stake_addr_info(user_registered.stake.address).address, (
@@ -272,10 +229,10 @@ def test_addr_registration_deregistration(
272229
# was not needed
273230
assert (
274231
cluster.g_query.get_address_balance(user_payment.address)
275-
== src_init_balance - tx_raw_output.fee
232+
== src_init_balance - tx_output.fee
276233
), f"Incorrect balance for source address `{user_payment.address}`"
277234

278-
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
235+
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output)
279236
if tx_db_record:
280237
assert user_registered.stake.address in tx_db_record.stake_registration
281238
assert user_registered.stake.address in tx_db_record.stake_deregistration
@@ -380,7 +337,7 @@ def test_addr_registration_certificate_order(
380337
assert user_registered.stake.address in tx_db_record.stake_deregistration
381338

382339
@allure.link(helpers.get_vcs_link())
383-
@common.PARAM_USE_BUILD_CMD
340+
@common.PARAM_BUILD_METHOD_NO_EST
384341
@pytest.mark.parametrize("key_type", ("stake", "payment"))
385342
@pytest.mark.smoke
386343
@pytest.mark.testnets
@@ -389,7 +346,7 @@ def test_multisig_deregister_registered(
389346
self,
390347
cluster: clusterlib.ClusterLib,
391348
pool_users: list[clusterlib.PoolUser],
392-
use_build_cmd: bool,
349+
build_method: str,
393350
key_type: str,
394351
):
395352
"""Deregister a registered multisig stake address.
@@ -454,15 +411,16 @@ def test_multisig_deregister_registered(
454411
def _submit_tx(
455412
name_template: str, complex_certs: list[clusterlib.ComplexCert]
456413
) -> clusterlib.TxRawOutput:
457-
if use_build_cmd:
414+
if build_method == clusterlib_utils.BuildMethods.BUILD:
458415
tx_output = cluster.g_transaction.build_tx(
459416
src_address=payment_addr.address,
460417
tx_name=name_template,
461418
complex_certs=complex_certs,
462419
fee_buffer=2_000_000,
463420
witness_override=witness_len,
464421
)
465-
else:
422+
423+
elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW:
466424
fee = cluster.g_transaction.calculate_tx_fee(
467425
src_address=payment_addr.address,
468426
tx_name=name_template,
@@ -475,6 +433,13 @@ def _submit_tx(
475433
complex_certs=complex_certs,
476434
fee=fee,
477435
)
436+
elif build_method == clusterlib_utils.BuildMethods.BUILD_EST:
437+
tx_output = cluster.g_transaction.build_estimate_tx(
438+
src_address=payment_addr.address,
439+
tx_name=name_template,
440+
complex_certs=complex_certs,
441+
witness_count_add=witness_len,
442+
)
478443

479444
# Create witness file for each key
480445
witness_files = [
@@ -610,15 +575,15 @@ def test_register_addr_with_wrong_key(
610575
assert "MissingVKeyWitnessesUTXOW" in err_msg, err_msg
611576

612577
@allure.link(helpers.get_vcs_link())
613-
@common.PARAM_USE_BUILD_CMD
578+
@common.PARAM_BUILD_METHOD_NO_EST
614579
@pytest.mark.smoke
615580
@pytest.mark.testnets
616581
def test_deregister_not_registered_addr(
617582
self,
618583
cluster: clusterlib.ClusterLib,
619584
pool_users: list[clusterlib.PoolUser],
620585
pool_users_disposable: list[clusterlib.PoolUser],
621-
use_build_cmd: bool,
586+
build_method: str,
622587
):
623588
"""Deregister not registered stake address."""
624589
temp_template = common.get_test_id(cluster)
@@ -638,7 +603,7 @@ def test_deregister_not_registered_addr(
638603
)
639604

640605
with pytest.raises(clusterlib.CLIError) as excinfo:
641-
if use_build_cmd:
606+
if build_method == clusterlib_utils.BuildMethods.BUILD_RAW:
642607

643608
def _build_dereg() -> clusterlib.TxRawOutput:
644609
return cluster.g_transaction.build_tx(
@@ -656,25 +621,33 @@ def _build_dereg() -> clusterlib.TxRawOutput:
656621
tx_name=f"{temp_template}_dereg_fail",
657622
)
658623
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
659-
else:
624+
elif build_method == clusterlib_utils.BuildMethods.BUILD:
660625
cluster.g_transaction.send_tx(
661626
src_address=user_payment.address,
662627
tx_name=f"{temp_template}_dereg_fail",
663628
tx_files=tx_files,
664629
)
630+
elif build_method == clusterlib_utils.BuildMethods.BUILD_EST:
631+
cluster.g_transaction.build_estimate_tx(
632+
src_address=user_payment.address,
633+
tx_name=f"{temp_template}_dereg_fail",
634+
tx_files=tx_files,
635+
witness_count_add=len(tx_files.signing_key_files),
636+
)
637+
665638
err_msg = str(excinfo.value)
666639
assert "StakeKeyNotRegisteredDELEG" in err_msg, err_msg
667640

668641
@allure.link(helpers.get_vcs_link())
669-
@common.PARAM_USE_BUILD_CMD
642+
@common.PARAM_BUILD_METHOD_NO_EST
670643
@pytest.mark.parametrize("issue", ("missing_script", "missing_skey"))
671644
@pytest.mark.smoke
672645
@pytest.mark.testnets
673646
def test_incomplete_multisig(
674647
self,
675648
cluster: clusterlib.ClusterLib,
676649
pool_users: list[clusterlib.PoolUser],
677-
use_build_cmd: bool,
650+
build_method: str,
678651
issue: str,
679652
):
680653
"""Try to register a multisig stake address while missing either a script or an skey.
@@ -724,7 +697,7 @@ def _submit_tx(
724697
) -> clusterlib.TxRawOutput:
725698
witness_len = len(signing_key_files)
726699

727-
if use_build_cmd:
700+
if build_method == clusterlib_utils.BuildMethods.BUILD:
728701
tx_output = cluster.g_transaction.build_tx(
729702
src_address=payment_addr.address,
730703
tx_name=name_template,
@@ -733,7 +706,7 @@ def _submit_tx(
733706
fee_buffer=2_000_000,
734707
witness_override=witness_len,
735708
)
736-
else:
709+
elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW:
737710
fee = cluster.g_transaction.calculate_tx_fee(
738711
src_address=payment_addr.address,
739712
tx_name=name_template,
@@ -748,6 +721,14 @@ def _submit_tx(
748721
complex_certs=complex_certs,
749722
fee=fee,
750723
)
724+
elif build_method == clusterlib_utils.BuildMethods.BUILD_EST:
725+
tx_output = cluster.g_transaction.build_estimate_tx(
726+
src_address=payment_addr.address,
727+
tx_name=name_template,
728+
tx_files=tx_files,
729+
complex_certs=complex_certs,
730+
witness_count_add=witness_len,
731+
)
751732

752733
# Create witness file for each key
753734
witness_files = [

0 commit comments

Comments
 (0)