Skip to content

Commit e74bb8d

Browse files
authored
Merge pull request #3118 from IntersectMBO/build_method_delegation_test
This PR refactors test_delegation to align with the new build Method
2 parents ea6d322 + 98a5063 commit e74bb8d

File tree

2 files changed

+54
-101
lines changed

2 files changed

+54
-101
lines changed

cardano_node_tests/tests/delegation.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def delegate_stake_addr(
152152
pool_id: str = "",
153153
cold_vkey: pl.Path | None = None,
154154
amount: int = 100_000_000,
155-
use_build_cmd: bool = False,
155+
build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW,
156156
) -> DelegationOut:
157157
"""Submit registration certificate and delegate a stake address to a pool."""
158158
# Create key pairs and addresses
@@ -214,30 +214,20 @@ def delegate_stake_addr(
214214
signing_key_files=[pool_user.payment.skey_file, pool_user.stake.skey_file],
215215
)
216216

217-
if use_build_cmd:
218-
tx_raw_output = cluster_obj.g_transaction.build_tx(
219-
src_address=src_address,
220-
tx_name=f"{temp_template}_reg_deleg",
221-
tx_files=tx_files,
222-
fee_buffer=2_000_000,
223-
witness_override=len(tx_files.signing_key_files),
224-
)
225-
tx_signed = cluster_obj.g_transaction.sign_tx(
226-
tx_body_file=tx_raw_output.out_file,
227-
signing_key_files=tx_files.signing_key_files,
228-
tx_name=f"{temp_template}_reg_deleg",
229-
)
230-
cluster_obj.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
231-
else:
232-
tx_raw_output = cluster_obj.g_transaction.send_tx(
233-
src_address=src_address, tx_name=f"{temp_template}_reg_deleg", tx_files=tx_files
234-
)
217+
tx_output = clusterlib_utils.build_and_submit_tx(
218+
cluster_obj=cluster_obj,
219+
name_template=f"{temp_template}_reg_deleg",
220+
src_address=src_address,
221+
tx_files=tx_files,
222+
build_method=build_method,
223+
witness_override=len(tx_files.signing_key_files),
224+
)
235225

236226
# Check that the balance for source address was correctly updated
237227
deposit = cluster_obj.g_query.get_address_deposit() if stake_addr_reg_cert_file else 0
238228
assert (
239229
cluster_obj.g_query.get_address_balance(src_address)
240-
== src_init_balance - deposit - tx_raw_output.fee
230+
== src_init_balance - deposit - tx_output.fee
241231
), f"Incorrect balance for source address `{src_address}`"
242232

243233
# Check that the stake address was delegated
@@ -246,7 +236,7 @@ def delegate_stake_addr(
246236
assert stake_addr_info.delegation == pool_id, "Stake address delegated to wrong pool"
247237
assert stake_addr_info.vote_delegation == "alwaysAbstain"
248238

249-
return DelegationOut(pool_user=pool_user, pool_id=pool_id, tx_raw_output=tx_raw_output)
239+
return DelegationOut(pool_user=pool_user, pool_id=pool_id, tx_raw_output=tx_output)
250240

251241

252242
def delegate_multisig_stake_addr(

cardano_node_tests/tests/test_delegation.py

Lines changed: 43 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ class TestDelegateAddr:
132132
"""Tests for stake address delegation."""
133133

134134
@allure.link(helpers.get_vcs_link())
135-
@common.PARAM_USE_BUILD_CMD
135+
@common.PARAM_BUILD_METHOD_NO_EST
136136
@pytest.mark.dbsync
137137
@pytest.mark.smoke
138138
@pytest.mark.testnets
139139
def test_delegate_using_pool_id(
140140
self,
141141
cluster_manager: cluster_management.ClusterManager,
142142
cluster_and_pool: tuple[clusterlib.ClusterLib, str],
143-
use_build_cmd: bool,
143+
build_method: str,
144144
):
145145
"""Submit registration certificate and delegate to pool using pool id.
146146
@@ -162,7 +162,7 @@ def test_delegate_using_pool_id(
162162
addrs_data=cluster_manager.cache.addrs_data,
163163
temp_template=temp_template,
164164
pool_id=pool_id,
165-
use_build_cmd=use_build_cmd,
165+
build_method=build_method,
166166
)
167167

168168
tx_db_record = dbsync_utils.check_tx(
@@ -176,14 +176,14 @@ def test_delegate_using_pool_id(
176176
)
177177

178178
@allure.link(helpers.get_vcs_link())
179-
@common.PARAM_USE_BUILD_CMD
179+
@common.PARAM_BUILD_METHOD_NO_EST
180180
@pytest.mark.dbsync
181181
@pytest.mark.smoke
182182
def test_delegate_using_vkey(
183183
self,
184184
cluster_manager: cluster_management.ClusterManager,
185185
cluster_use_pool: tuple[clusterlib.ClusterLib, str],
186-
use_build_cmd: bool,
186+
build_method: str,
187187
):
188188
"""Submit registration certificate and delegate to pool using cold vkey.
189189
@@ -206,7 +206,7 @@ def test_delegate_using_vkey(
206206
addrs_data=cluster_manager.cache.addrs_data,
207207
temp_template=temp_template,
208208
cold_vkey=node_cold.vkey_file,
209-
use_build_cmd=use_build_cmd,
209+
build_method=build_method,
210210
)
211211

212212
tx_db_record = dbsync_utils.check_tx(
@@ -852,7 +852,7 @@ def test_undelegate(
852852
assert still_rewards_epoch in db_reward_epochs
853853

854854
@allure.link(helpers.get_vcs_link())
855-
@common.PARAM_USE_BUILD_CMD
855+
@common.PARAM_BUILD_METHOD_NO_EST
856856
@pytest.mark.dbsync
857857
@pytest.mark.parametrize(
858858
"stake_cert",
@@ -866,7 +866,7 @@ def test_addr_delegation_deregistration(
866866
pool_users_cluster_and_pool: list[clusterlib.PoolUser],
867867
pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser],
868868
stake_cert: str,
869-
use_build_cmd: bool,
869+
build_method: str,
870870
):
871871
"""Submit delegation and deregistration certificates in single TX.
872872
@@ -956,38 +956,23 @@ def test_addr_delegation_deregistration(
956956
signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file],
957957
)
958958

959-
if use_build_cmd:
960-
961-
def _build_deleg_dereg() -> clusterlib.TxRawOutput:
962-
return cluster.g_transaction.build_tx(
963-
src_address=user_payment.address,
964-
tx_name=f"{temp_template}_deleg_dereg",
965-
tx_files=tx_files,
966-
fee_buffer=2_000_000,
967-
witness_override=len(tx_files.signing_key_files),
968-
)
969-
970-
tx_raw_output_deleg: clusterlib.TxRawOutput = common.match_blocker(
971-
func=_build_deleg_dereg
972-
)
973-
tx_signed = cluster.g_transaction.sign_tx(
974-
tx_body_file=tx_raw_output_deleg.out_file,
975-
signing_key_files=tx_files.signing_key_files,
976-
tx_name=f"{temp_template}_deleg_dereg",
977-
)
978-
try:
979-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_deleg.txins)
980-
except clusterlib.CLIError as exc:
981-
if "ValueNotConservedUTxO" in str(exc):
982-
issues.cli_942.finish_test()
983-
raise
984-
else:
985-
tx_raw_output_deleg = cluster.g_transaction.send_tx(
959+
def _build_and_submit() -> clusterlib.TxRawOutput:
960+
return clusterlib_utils.build_and_submit_tx(
961+
cluster_obj=cluster,
962+
name_template=f"{temp_template}_deleg_dereg",
986963
src_address=user_payment.address,
987-
tx_name=f"{temp_template}_deleg_dereg",
988964
tx_files=tx_files,
965+
build_method=build_method,
966+
witness_override=len(tx_files.signing_key_files),
989967
)
990968

969+
try:
970+
tx_raw_output_deleg = common.match_blocker(func=_build_and_submit)
971+
except clusterlib.CLIError as exc:
972+
if "ValueNotConservedUTxO" in str(exc):
973+
issues.cli_942.finish_test()
974+
raise
975+
991976
# Check that the balance for source address was correctly updated and that the key
992977
# deposit was returned
993978
assert (
@@ -1092,15 +1077,15 @@ def test_delegate_addr_with_wrong_key(
10921077
assert "MissingVKeyWitnessesUTXOW" in err_msg, err_msg
10931078

10941079
@allure.link(helpers.get_vcs_link())
1095-
@common.PARAM_USE_BUILD_CMD
1080+
@common.PARAM_BUILD_METHOD_NO_EST
10961081
@pytest.mark.smoke
10971082
@pytest.mark.testnets
10981083
def test_delegate_unknown_addr(
10991084
self,
11001085
cluster_and_pool: tuple[clusterlib.ClusterLib, str],
11011086
pool_users_cluster_and_pool: list[clusterlib.PoolUser],
11021087
pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser],
1103-
use_build_cmd: bool,
1088+
build_method: str,
11041089
):
11051090
"""Try to delegate unknown stake address.
11061091
@@ -1127,41 +1112,30 @@ def test_delegate_unknown_addr(
11271112
)
11281113

11291114
with pytest.raises(clusterlib.CLIError) as excinfo:
1130-
if use_build_cmd:
1131-
tx_raw_output = cluster.g_transaction.build_tx(
1132-
src_address=user_payment.address,
1133-
tx_name=f"{temp_template}_deleg_unknown",
1134-
tx_files=tx_files,
1135-
fee_buffer=2_000_000,
1136-
witness_override=len(tx_files.signing_key_files),
1137-
)
1138-
tx_signed = cluster.g_transaction.sign_tx(
1139-
tx_body_file=tx_raw_output.out_file,
1140-
signing_key_files=tx_files.signing_key_files,
1141-
tx_name=f"{temp_template}_deleg_unknown",
1142-
)
1143-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
1144-
else:
1145-
cluster.g_transaction.send_tx(
1146-
src_address=user_payment.address,
1147-
tx_name=f"{temp_template}_deleg_unknown",
1148-
tx_files=tx_files,
1149-
)
1115+
clusterlib_utils.build_and_submit_tx(
1116+
cluster_obj=cluster,
1117+
name_template=f"{temp_template}_deleg_unknown",
1118+
src_address=user_payment.address,
1119+
tx_files=tx_files,
1120+
build_method=build_method,
1121+
witness_override=len(tx_files.signing_key_files),
1122+
)
1123+
11501124
err_msg = str(excinfo.value)
11511125
assert (
11521126
"StakeDelegationImpossibleDELEG" in err_msg or "StakeKeyNotRegisteredDELEG" in err_msg
11531127
), err_msg
11541128

11551129
@allure.link(helpers.get_vcs_link())
1156-
@common.PARAM_USE_BUILD_CMD
1130+
@common.PARAM_BUILD_METHOD_NO_EST
11571131
@pytest.mark.smoke
11581132
@pytest.mark.testnets
11591133
def test_delegate_deregistered_addr(
11601134
self,
11611135
cluster_and_pool: tuple[clusterlib.ClusterLib, str],
11621136
pool_users_cluster_and_pool: list[clusterlib.PoolUser],
11631137
pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser],
1164-
use_build_cmd: bool,
1138+
build_method: str,
11651139
):
11661140
"""Try to delegate deregistered stake address.
11671141
@@ -1207,26 +1181,15 @@ def test_delegate_deregistered_addr(
12071181
)
12081182

12091183
with pytest.raises(clusterlib.CLIError) as excinfo:
1210-
if use_build_cmd:
1211-
tx_raw_output = cluster.g_transaction.build_tx(
1212-
src_address=user_payment.address,
1213-
tx_name=f"{temp_template}_deleg_dereg",
1214-
tx_files=tx_files,
1215-
fee_buffer=2_000_000,
1216-
witness_override=len(tx_files.signing_key_files),
1217-
)
1218-
tx_signed = cluster.g_transaction.sign_tx(
1219-
tx_body_file=tx_raw_output.out_file,
1220-
signing_key_files=tx_files.signing_key_files,
1221-
tx_name=f"{temp_template}_deleg_dereg",
1222-
)
1223-
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins)
1224-
else:
1225-
cluster.g_transaction.send_tx(
1226-
src_address=user_payment.address,
1227-
tx_name=f"{temp_template}_deleg_dereg",
1228-
tx_files=tx_files,
1229-
)
1184+
clusterlib_utils.build_and_submit_tx(
1185+
cluster_obj=cluster,
1186+
name_template=f"{temp_template}_deleg_dereg",
1187+
src_address=user_payment.address,
1188+
tx_files=tx_files,
1189+
build_method=build_method,
1190+
witness_override=len(tx_files.signing_key_files),
1191+
)
1192+
12301193
err_msg = str(excinfo.value)
12311194
assert (
12321195
"StakeDelegationImpossibleDELEG" in err_msg or "StakeKeyNotRegisteredDELEG" in err_msg

0 commit comments

Comments
 (0)