def payment_addrs( self, cluster_manager: parallel_run.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create 2 new payment addresses.""" data_key = id(TestFee) cached_value = cluster_manager.cache.test_data.get(data_key) if cached_value: return cached_value # type: ignore addrs = clusterlib_utils.create_payment_addr_records( f"addr_test_fee_ci{cluster_manager.cluster_instance}_0", f"addr_test_fee_ci{cluster_manager.cluster_instance}_1", cluster_obj=cluster, ) cluster_manager.cache.test_data[data_key] = addrs # fund source addresses clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) return addrs
def payment_addr( self, cluster_manager: cluster_management.ClusterManager, cluster_update_proposal: clusterlib.ClusterLib, ) -> clusterlib.AddressRecord: """Create new payment address.""" cluster = cluster_update_proposal with cluster_manager.cache_fixture() as fixture_cache: if fixture_cache.value: return fixture_cache.value # type: ignore addr = clusterlib_utils.create_payment_addr_records( f"addr_test_update_proposal_ci{cluster_manager.cluster_instance_num}_0", cluster_obj=cluster, )[0] fixture_cache.value = addr # fund source addresses clusterlib_utils.fund_from_faucet( addr, cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) return addr
def payment_addr( self, cluster_manager: parallel_run.ClusterManager, cluster_update_proposal: clusterlib.ClusterLib, ) -> clusterlib.AddressRecord: """Create new payment address.""" data_key = id(TestBasic) cached_value = cluster_manager.cache.test_data.get(data_key) if cached_value: return cached_value # type: ignore cluster = cluster_update_proposal addr = clusterlib_utils.create_payment_addr_records( f"addr_test_basic_update_proposal_ci{cluster_manager.cluster_instance}_0", cluster_obj=cluster, )[0] cluster_manager.cache.test_data[data_key] = addr # fund source addresses clusterlib_utils.fund_from_faucet( addr, cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) return addr
def payment_addrs( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create 2 new payment addresses.""" with cluster_manager.cache_fixture() as fixture_cache: if fixture_cache.value: return fixture_cache.value # type: ignore addrs = clusterlib_utils.create_payment_addr_records( f"addr_test_fee_ci{cluster_manager.cluster_instance}_0", f"addr_test_fee_ci{cluster_manager.cluster_instance}_1", cluster_obj=cluster, ) fixture_cache.value = addrs # fund source addresses clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) return addrs
def issuers_addrs( cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create new issuers addresses.""" with cluster_manager.cache_fixture() as fixture_cache: if fixture_cache.value: return fixture_cache.value # type: ignore addrs = clusterlib_utils.create_payment_addr_records( *[ f"token_minting_ci{cluster_manager.cluster_instance}_{i}" for i in range(3) ], cluster_obj=cluster, ) fixture_cache.value = addrs # fund source addresses clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], amount=900_000_000, ) return addrs
def payment_addrs( self, cluster_manager: parallel_run.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create new payment addresses.""" data_key = id(TestTimeLocking) cached_value = cluster_manager.cache.test_data.get(data_key) if cached_value: return cached_value # type: ignore addrs = clusterlib_utils.create_payment_addr_records( *[ f"multi_addr_time_locking_ci{cluster_manager.cluster_instance}_{i}" for i in range(20) ], cluster_obj=cluster, ) cluster_manager.cache.test_data[data_key] = addrs # fund source addresses clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], amount=20_000_000, ) return addrs
def payment_addrs( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create 2 new payment addresses.""" if cluster.use_cddl: pytest.skip("runs only when `cluster.use_cddl == False`") with cluster_manager.cache_fixture() as fixture_cache: if fixture_cache.value: return fixture_cache.value # type: ignore addrs = clusterlib_utils.create_payment_addr_records( f"addr_shelley_cddl_ci{cluster_manager.cluster_instance_num}_0", f"addr_shelley_cddl_ci{cluster_manager.cluster_instance_num}_1", cluster_obj=cluster, ) fixture_cache.value = addrs # fund source addresses clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) return addrs
def payment_addrs( cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, ) -> List[clusterlib.AddressRecord]: """Create new payment addresses.""" test_id = common.get_test_id(cluster) addrs = clusterlib_utils.create_payment_addr_records( *[f"{test_id}_payment_addr_{i}" for i in range(2)], cluster_obj=cluster, ) # fund source address clusterlib_utils.fund_from_faucet( addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], amount=3_000_000_000, ) return addrs
def test_deregister( self, cluster_manager: cluster_management.ClusterManager, cluster_and_pool: Tuple[clusterlib.ClusterLib, str], ): """Deregister stake address. * create two payment addresses that share single stake address * register and delegate the stake address to pool * attempt to deregister the stake address - deregistration is expected to fail because there are rewards in the stake address * withdraw rewards to payment address and deregister stake address * check that the key deposit was returned and rewards withdrawn * check that the stake address is no longer delegated * (optional) check records in db-sync """ cluster, pool_id = cluster_and_pool temp_template = common.get_test_id(cluster) # create two payment addresses that share single stake address (just to test that # delegation works as expected even under such circumstances) stake_addr_rec = clusterlib_utils.create_stake_addr_records( f"{temp_template}_addr0", cluster_obj=cluster)[0] payment_addr_recs = clusterlib_utils.create_payment_addr_records( f"{temp_template}_addr0", f"{temp_template}_addr1", cluster_obj=cluster, stake_vkey_file=stake_addr_rec.vkey_file, ) # fund payment address clusterlib_utils.fund_from_faucet( *payment_addr_recs, cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], ) pool_user = clusterlib.PoolUser(payment=payment_addr_recs[1], stake=stake_addr_rec) clusterlib_utils.wait_for_epoch_interval(cluster_obj=cluster, start=5, stop=-20) init_epoch = cluster.get_epoch() # submit registration certificate and delegate to pool delegation_out = delegation.delegate_stake_addr( cluster_obj=cluster, addrs_data=cluster_manager.cache.addrs_data, temp_template=temp_template, pool_user=pool_user, pool_id=pool_id, ) assert ( cluster.get_epoch() == init_epoch ), "Delegation took longer than expected and would affect other checks" tx_db_deleg = dbsync_utils.check_tx( cluster_obj=cluster, tx_raw_output=delegation_out.tx_raw_output) if tx_db_deleg: # check in db-sync that both payment addresses share single stake address assert (dbsync_utils.get_utxo( address=payment_addr_recs[0].address).stake_address == stake_addr_rec.address) assert (dbsync_utils.get_utxo( address=payment_addr_recs[1].address).stake_address == stake_addr_rec.address) delegation.db_check_delegation( pool_user=delegation_out.pool_user, db_record=tx_db_deleg, deleg_epoch=init_epoch, pool_id=delegation_out.pool_id, ) src_address = delegation_out.pool_user.payment.address LOGGER.info("Waiting 4 epochs for first reward.") cluster.wait_for_new_epoch(new_epochs=4, padding_seconds=10) if not cluster.get_stake_addr_info( delegation_out.pool_user.stake.address).reward_account_balance: pytest.skip( f"User of pool '{pool_id}' hasn't received any rewards, cannot continue." ) # make sure we have enough time to finish deregistration in one epoch clusterlib_utils.wait_for_epoch_interval(cluster_obj=cluster, start=5, stop=-40) # files for deregistering stake address stake_addr_dereg_cert = cluster.gen_stake_addr_deregistration_cert( addr_name=f"{temp_template}_addr0", stake_vkey_file=delegation_out.pool_user.stake.vkey_file, ) tx_files_deregister = clusterlib.TxFiles( certificate_files=[stake_addr_dereg_cert], signing_key_files=[ delegation_out.pool_user.payment.skey_file, delegation_out.pool_user.stake.skey_file, ], ) # attempt to deregister the stake address - deregistration is expected to fail # because there are rewards in the stake address with pytest.raises(clusterlib.CLIError) as excinfo: cluster.send_tx( src_address=src_address, tx_name=f"{temp_template}_dereg_fail", tx_files=tx_files_deregister, ) assert "StakeKeyNonZeroAccountBalanceDELEG" in str(excinfo.value) src_payment_balance = cluster.get_address_balance(src_address) reward_balance = cluster.get_stake_addr_info( delegation_out.pool_user.stake.address).reward_account_balance # withdraw rewards to payment address, deregister stake address tx_raw_deregister_output = cluster.send_tx( src_address=src_address, tx_name=f"{temp_template}_dereg_withdraw", tx_files=tx_files_deregister, withdrawals=[ clusterlib.TxOut( address=delegation_out.pool_user.stake.address, amount=-1) ], ) # check that the key deposit was returned and rewards withdrawn assert ( cluster.get_address_balance(src_address) == src_payment_balance - tx_raw_deregister_output.fee + reward_balance + cluster.get_address_deposit() ), f"Incorrect balance for source address `{src_address}`" # check that the stake address is no longer delegated stake_addr_info = cluster.get_stake_addr_info( delegation_out.pool_user.stake.address) assert (not stake_addr_info.delegation ), f"Stake address is still delegated: {stake_addr_info}" tx_db_dereg = dbsync_utils.check_tx( cluster_obj=cluster, tx_raw_output=tx_raw_deregister_output) if tx_db_dereg: assert delegation_out.pool_user.stake.address in tx_db_dereg.stake_deregistration assert ( cluster.get_address_balance(src_address) == dbsync_utils.get_utxo(address=src_address).amount_sum ), f"Unexpected balance for source address `{src_address}` in db-sync"
addrs_data: dict, temp_template: str, pool_user: Optional[clusterlib.PoolUser] = None, pool_id: str = "", cold_vkey: Optional[Path] = None, amount: int = 100_000_000, use_build_cmd: bool = False, ) -> DelegationOut: """Submit registration certificate and delegate to pool.""" # create key pairs and addresses if not pool_user: stake_addr_rec = clusterlib_utils.create_stake_addr_records( f"{temp_template}_addr0", cluster_obj=cluster_obj)[0] payment_addr_rec = clusterlib_utils.create_payment_addr_records( f"{temp_template}_addr0", cluster_obj=cluster_obj, stake_vkey_file=stake_addr_rec.vkey_file, )[0] pool_user = clusterlib.PoolUser(payment=payment_addr_rec, stake=stake_addr_rec) # fund payment address clusterlib_utils.fund_from_faucet( pool_user.payment, cluster_obj=cluster_obj, faucet_data=addrs_data["user1"], amount=amount, ) # create stake address registration cert if address is not already registered
def test_pretty_utxo( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib ): """Check that pretty printed `query utxo` output looks as expected.""" temp_template = common.get_test_id(cluster) amount1 = 2_000_000 amount2 = 2_500_000 # create source and destination payment addresses payment_addrs = clusterlib_utils.create_payment_addr_records( f"{temp_template}_src", f"{temp_template}_dst", cluster_obj=cluster, ) # fund source addresses clusterlib_utils.fund_from_faucet( payment_addrs[0], cluster_obj=cluster, faucet_data=cluster_manager.cache.addrs_data["user1"], amount=amount1 + amount2 + 10_000_000, ) src_address = payment_addrs[0].address dst_address = payment_addrs[1].address txouts = [ clusterlib.TxOut(address=dst_address, amount=amount1), clusterlib.TxOut(address=dst_address, amount=amount2), ] tx_files = clusterlib.TxFiles(signing_key_files=[payment_addrs[0].skey_file]) tx_raw_output = cluster.send_tx( src_address=src_address, tx_name=temp_template, txouts=txouts, tx_files=tx_files, join_txouts=False, ) utxo_out = ( cluster.cli( [ "query", "utxo", "--address", dst_address, *cluster.magic_args, ] ) .stdout.decode("utf-8") .split() ) txid = cluster.get_txid(tx_body_file=tx_raw_output.out_file) expected_out = [ "TxHash", "TxIx", "Amount", "--------------------------------------------------------------------------------" "------", txid, "0", str(amount1), "lovelace", "+", "TxOutDatumNone", txid, "1", str(amount2), "lovelace", "+", "TxOutDatumNone", ] assert utxo_out == expected_out