Skip to content

Commit 7d1aa02

Browse files
committed
feat(tests): add multisig deregistration test
Add a new test `test_multisig_deregister_registered` to verify registration and deregistration of a multisig stake address. The test includes steps to create a multisig script, register the stake address, and then deregister it, ensuring the address is no longer registered. Also, includes optional checks for records in db-sync.
1 parent 05e7dfa commit 7d1aa02

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

cardano_node_tests/tests/test_addr_registration.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,170 @@ def test_addr_registration_certificate_order(
383383
assert user_registered.stake.address in tx_db_record.stake_registration
384384
assert user_registered.stake.address in tx_db_record.stake_deregistration
385385

386+
@allure.link(helpers.get_vcs_link())
387+
@common.PARAM_USE_BUILD_CMD
388+
@pytest.mark.parametrize("key_type", ("stake", "payment"))
389+
@pytest.mark.smoke
390+
@pytest.mark.testnets
391+
@pytest.mark.dbsync
392+
def test_multisig_deregister_registered(
393+
self,
394+
cluster: clusterlib.ClusterLib,
395+
pool_users: list[clusterlib.PoolUser],
396+
use_build_cmd: bool,
397+
key_type: str,
398+
):
399+
"""Deregister a registered multisig stake address.
400+
401+
* Create a multisig script to be used as stake credentials
402+
* Create stake address registration certificate
403+
* Create a Tx for the registration certificate
404+
* Incrementally sign the Tx and submit the registration certificate
405+
* Check that the address is registered
406+
* Create stake address deregistration certificate
407+
* Create a Tx for the deregistration certificate
408+
* Incrementally sign the Tx and submit the deregistration certificate
409+
* Check that the address is no longer registered
410+
* (optional) check records in db-sync
411+
"""
412+
temp_template = common.get_test_id(cluster)
413+
payment_addr = pool_users[0].payment
414+
415+
# Create a multisig script to be used as stake credentials
416+
if key_type == "stake":
417+
stake_key_recs = [
418+
cluster.g_stake_address.gen_stake_key_pair(key_name=f"{temp_template}_sig_{i}")
419+
for i in range(1, 6)
420+
]
421+
multisig_script = clusterlib_utils.build_stake_multisig_script(
422+
cluster_obj=cluster,
423+
script_name=temp_template,
424+
script_type_arg=clusterlib.MultiSigTypeArgs.ALL,
425+
stake_vkey_files=[r.vkey_file for r in stake_key_recs],
426+
)
427+
else:
428+
stake_key_recs = [
429+
cluster.g_address.gen_payment_key_pair(key_name=f"{temp_template}_sig_{i}")
430+
for i in range(1, 6)
431+
]
432+
multisig_script = cluster.g_transaction.build_multisig_script(
433+
script_name=temp_template,
434+
script_type_arg=clusterlib.MultiSigTypeArgs.ALL,
435+
payment_vkey_files=[r.vkey_file for r in stake_key_recs],
436+
)
437+
438+
stake_address = cluster.g_stake_address.gen_stake_addr(
439+
addr_name=temp_template, stake_script_file=multisig_script
440+
)
441+
442+
# Create stake address registration cert
443+
address_deposit = common.get_conway_address_deposit(cluster_obj=cluster)
444+
445+
stake_addr_reg_cert_file = cluster.g_stake_address.gen_stake_addr_registration_cert(
446+
addr_name=f"{temp_template}_addr0",
447+
deposit_amt=address_deposit,
448+
stake_script_file=multisig_script,
449+
)
450+
reg_cert_script = clusterlib.ComplexCert(
451+
certificate_file=stake_addr_reg_cert_file,
452+
script_file=multisig_script,
453+
)
454+
455+
signing_key_files = [payment_addr.skey_file, *[r.skey_file for r in stake_key_recs]]
456+
witness_len = len(signing_key_files)
457+
458+
def _submit_tx(
459+
name_template: str, complex_certs: list[clusterlib.ComplexCert]
460+
) -> clusterlib.TxRawOutput:
461+
if use_build_cmd:
462+
tx_output = cluster.g_transaction.build_tx(
463+
src_address=payment_addr.address,
464+
tx_name=name_template,
465+
complex_certs=complex_certs,
466+
fee_buffer=2_000_000,
467+
witness_override=witness_len,
468+
)
469+
else:
470+
fee = cluster.g_transaction.calculate_tx_fee(
471+
src_address=payment_addr.address,
472+
tx_name=name_template,
473+
complex_certs=complex_certs,
474+
witness_count_add=witness_len,
475+
)
476+
tx_output = cluster.g_transaction.build_raw_tx(
477+
src_address=payment_addr.address,
478+
tx_name=name_template,
479+
complex_certs=complex_certs,
480+
fee=fee,
481+
)
482+
483+
# Create witness file for each key
484+
witness_files = [
485+
cluster.g_transaction.witness_tx(
486+
tx_body_file=tx_output.out_file,
487+
witness_name=f"{name_template}_skey{idx}",
488+
signing_key_files=[skey],
489+
)
490+
for idx, skey in enumerate(signing_key_files, start=1)
491+
]
492+
493+
# Sign TX using witness files
494+
tx_witnessed_file = cluster.g_transaction.assemble_tx(
495+
tx_body_file=tx_output.out_file,
496+
witness_files=witness_files,
497+
tx_name=name_template,
498+
)
499+
500+
# Submit signed TX
501+
cluster.g_transaction.submit_tx(tx_file=tx_witnessed_file, txins=tx_output.txins)
502+
503+
return tx_output
504+
505+
# Build a Tx with the registration certificate
506+
src_init_balance = cluster.g_query.get_address_balance(payment_addr.address)
507+
508+
tx_output_reg = _submit_tx(
509+
name_template=f"{temp_template}_reg", complex_certs=[reg_cert_script]
510+
)
511+
512+
# Check that the stake address is registered
513+
stake_addr_info = cluster.g_query.get_stake_addr_info(stake_address)
514+
assert stake_addr_info, f"Stake address is not registered: {stake_address}"
515+
516+
# Create stake address deregistration cert
517+
stake_addr_dereg_cert_file = cluster.g_stake_address.gen_stake_addr_deregistration_cert(
518+
addr_name=f"{temp_template}_addr0",
519+
deposit_amt=address_deposit,
520+
stake_script_file=multisig_script,
521+
)
522+
dereg_cert_script = clusterlib.ComplexCert(
523+
certificate_file=stake_addr_dereg_cert_file,
524+
script_file=multisig_script,
525+
)
526+
527+
# Build a Tx with the deregistration certificate
528+
tx_output_dereg = _submit_tx(
529+
name_template=f"{temp_template}_dereg", complex_certs=[dereg_cert_script]
530+
)
531+
532+
# Check that the balance for source address was correctly updated and that key deposit
533+
# was needed
534+
assert (
535+
cluster.g_query.get_address_balance(payment_addr.address)
536+
== src_init_balance - tx_output_reg.fee - tx_output_dereg.fee
537+
), f"Incorrect balance for source address `{payment_addr.address}`"
538+
539+
# Check records in db-sync
540+
tx_db_record_reg = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output_reg)
541+
if tx_db_record_reg:
542+
assert stake_address in tx_db_record_reg.stake_registration
543+
544+
tx_db_record_dereg = dbsync_utils.check_tx(
545+
cluster_obj=cluster, tx_raw_output=tx_output_dereg
546+
)
547+
if tx_db_record_dereg:
548+
assert stake_address in tx_db_record_dereg.stake_deregistration
549+
386550

387551
class TestNegative:
388552
"""Tests that are expected to fail."""

0 commit comments

Comments
 (0)