Skip to content

Commit

Permalink
Merge pull request #141 from mkoura/temp_template_inspection
Browse files Browse the repository at this point in the history
Use inspection to get temp_template value
  • Loading branch information
mkoura committed Sep 24, 2020
2 parents 47d8aa1 + f3e3ccc commit cb65342
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cardano_node_tests/tests/test_multisig.py
Expand Up @@ -57,7 +57,7 @@ def test_multisig_all(
self, cluster: clusterlib.ClusterLib, payment_addrs: List[clusterlib.AddressRecord]
):
"""Send funds to and from script address using the "all" script."""
temp_template = "test_multisig_all"
temp_template = helpers.get_func_name()

payment_vkey_files = [p.vkey_file for p in payment_addrs]
payment_skey_files = [p.skey_file for p in payment_addrs]
Expand Down
36 changes: 18 additions & 18 deletions cardano_node_tests/tests/test_pools.py
Expand Up @@ -299,7 +299,7 @@ def test_stake_pool_metadata(
temp_dir: Path,
):
"""Create and register a stake pool with metadata."""
temp_template = "test_stake_pool_metadata"
temp_template = helpers.get_func_name()

pool_name = "cardano-node-tests"
pool_metadata = {
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_stake_pool_metadata_not_avail(
temp_dir: Path,
):
"""Create and register a stake pool with metadata file not available."""
temp_template = "test_stake_pool_metadata_not_avail"
temp_template = helpers.get_func_name()

pool_name = f"pool_{clusterlib.get_rand_str(8)}"
pool_metadata = {
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_create_stake_pool(
no_of_addr: int,
):
"""Create and register a stake pool."""
temp_template = f"test_stake_pool_{no_of_addr}owners"
temp_template = f"{helpers.get_func_name()}_{no_of_addr}owners"

pool_data = clusterlib.PoolData(
pool_name=f"poolX_{no_of_addr}",
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_deregister_stake_pool(
no_of_addr: int,
):
"""Deregister stake pool."""
temp_template = f"test_deregister_stake_pool_{no_of_addr}owners"
temp_template = f"{helpers.get_func_name()}_{no_of_addr}owners"

pool_metadata = {
"name": "QA E2E test",
Expand Down Expand Up @@ -542,7 +542,7 @@ def test_reregister_stake_pool(
temp_dir: Path,
):
"""Re-register stake pool."""
temp_template = "test_reregister_stake_pool"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "QA E2E test",
Expand Down Expand Up @@ -658,7 +658,7 @@ def test_update_stake_pool_metadata(
no_of_addr: int,
):
"""Update stake pool metadata."""
temp_template = f"test_update_stake_pool_metadata_{no_of_addr}owners"
temp_template = f"{helpers.get_func_name()}_{no_of_addr}owners"

pool_metadata = {
"name": "QA E2E test",
Expand Down Expand Up @@ -744,7 +744,7 @@ def test_update_stake_pool_parameters(
no_of_addr: int,
):
"""Update stake pool parameters."""
temp_template = f"test_update_stake_pool_{no_of_addr}owners"
temp_template = f"{helpers.get_func_name()}_{no_of_addr}owners"

pool_metadata = {
"name": "QA E2E test",
Expand Down Expand Up @@ -813,7 +813,7 @@ def test_sign_in_multiple_stages(
cluster: clusterlib.ClusterLib,
):
"""Create and register a stake pool with TX signed in multiple stages."""
temp_template = "test_sign_in_multiple_stages"
temp_template = helpers.get_func_name()

pool_data = clusterlib.PoolData(
pool_name=f"pool_{clusterlib.get_rand_str()}",
Expand Down Expand Up @@ -930,7 +930,7 @@ def pool_owners(

cluster = cluster_mincost
rand_str = clusterlib.get_rand_str()
temp_template = f"test_pool_cost_class_{rand_str}"
temp_template = f"{helpers.get_func_name()}_{rand_str}"

pool_owners = helpers.create_pool_users(
cluster_obj=cluster,
Expand Down Expand Up @@ -993,7 +993,7 @@ def test_stake_pool_cost(
"""Create and register a stake pool with pool cost >= 'minPoolCost'."""
cluster = cluster_mincost
rand_str = clusterlib.get_rand_str()
temp_template = f"test_stake_pool_cost_{rand_str}"
temp_template = f"{helpers.get_func_name()}_{rand_str}"

pool_data = clusterlib.PoolData(
pool_name=f"pool_{rand_str}",
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def test_stake_pool_metadata_no_name(
temp_dir: Path,
):
"""Test pool metadata that is missing the 'name' key."""
temp_template = "test_stake_pool_metadata_no_name"
temp_template = helpers.get_func_name()

pool_metadata = {
"description": "cardano-node-tests E2E tests",
Expand All @@ -1279,7 +1279,7 @@ def test_stake_pool_metadata_no_description(
temp_dir: Path,
):
"""Test pool metadata that is missing the 'description' key."""
temp_template = "test_stake_pool_metadata_no_description"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "cardano-node-tests",
Expand All @@ -1301,7 +1301,7 @@ def test_stake_pool_metadata_no_ticker(
temp_dir: Path,
):
"""Test pool metadata that is missing the 'ticker' key."""
temp_template = "test_stake_pool_metadata_no_ticker"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "cardano-node-tests",
Expand All @@ -1323,7 +1323,7 @@ def test_stake_pool_metadata_no_homepage(
temp_dir: Path,
):
"""Test pool metadata that is missing the 'homepage' key."""
temp_template = "test_stake_pool_metadata_no_homepage"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "cardano-node-tests",
Expand All @@ -1348,7 +1348,7 @@ def test_stake_pool_metadata_long_name(
pool_name: str,
):
"""Test pool metadata with the 'name' value longer than allowed."""
temp_template = "test_stake_pool_metadata_long_name"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": pool_name,
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def test_stake_pool_metadata_long_description(
pool_description: str,
):
"""Test pool metadata with the 'description' value longer than allowed."""
temp_template = "test_stake_pool_metadata_long_description"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "cardano-node-tests",
Expand Down Expand Up @@ -1410,7 +1410,7 @@ def test_stake_pool_metadata_long_ticker(
"""Test pool metadata with the 'ticker' value longer than allowed."""
hypothesis.assume(not (3 <= len(pool_ticker) <= 5))

temp_template = "test_stake_pool_metadata_long_ticker"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "cardano-node-tests",
Expand All @@ -1436,7 +1436,7 @@ def test_stake_pool_metadata_long_homepage(
pool_homepage: str,
):
"""Test pool metadata with the 'homepage' value longer than allowed."""
temp_template = "test_stake_pool_metadata_long_homepage"
temp_template = helpers.get_func_name()

pool_metadata = {
"name": "CND",
Expand Down
35 changes: 16 additions & 19 deletions cardano_node_tests/tests/test_staking.py
Expand Up @@ -164,8 +164,7 @@ def test_delegate_using_pool_id(
"""Submit registration certificate and delegate to pool using pool id."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_delegate_using_addr"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
_delegate_stake_addr(
Expand All @@ -184,8 +183,7 @@ def test_delegate_using_vkey(
"""Submit registration certificate and delegate to pool using cold vkey."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_delegate_using_cert"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
_delegate_stake_addr(
Expand All @@ -203,8 +201,7 @@ def test_deregister(
"""De-register stake address."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_deregister_addr"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
pool_user = _delegate_stake_addr(
Expand Down Expand Up @@ -274,7 +271,7 @@ def test_addr_registration_deregistration(
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Submit registration and deregistration certificates in single TX."""
temp_template = "test_addr_registration_deregistration"
temp_template = helpers.get_func_name()

user_registered = pool_users_disposable[0]
user_payment = pool_users[0].payment
Expand Down Expand Up @@ -315,7 +312,7 @@ def test_addr_delegation_deregistration(
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_addr_delegation_deregistration"
temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]

user_registered = pool_users_disposable[0]
Expand Down Expand Up @@ -384,7 +381,7 @@ def test_registration_cert_with_wrong_key(
pool_users: List[clusterlib.PoolUser],
):
"""Generate stake address registration certificate using wrong key."""
temp_template = "test_registration_cert_with_wrong_key"
temp_template = helpers.get_func_name()

# create stake address registration cert, use wrong stake vkey
with pytest.raises(clusterlib.CLIError) as excinfo:
Expand All @@ -404,7 +401,7 @@ def test_delegation_cert_with_wrong_key(
cluster = cluster_manager.get(use_resources=[pool_name])

node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]
temp_template = "test_delegation_cert_with_wrong_key"
temp_template = helpers.get_func_name()

# create stake address delegation cert, use wrong stake vkey
with pytest.raises(clusterlib.CLIError) as excinfo:
Expand All @@ -423,7 +420,7 @@ def test_register_addr_with_wrong_key(
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Register stake address using wrong key."""
temp_template = "test_register_addr_with_wrong_key"
temp_template = helpers.get_func_name()

user_registered = pool_users_disposable[0]
user_payment = pool_users[0].payment
Expand Down Expand Up @@ -454,7 +451,7 @@ def test_delegate_addr_with_wrong_key(
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_delegate_addr_with_wrong_key"
temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]

user_registered = pool_users_disposable[0]
Expand Down Expand Up @@ -501,7 +498,7 @@ def test_delegate_unregistered_addr(
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_delegate_unregistered_addr"
temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]

user_registered = pool_users_disposable[0]
Expand Down Expand Up @@ -532,7 +529,7 @@ def test_unregister_not_registered_addr(
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Unregistered not registered stake address."""
temp_template = "test_unregister_not_registered_addr"
temp_template = helpers.get_func_name()

user_registered = pool_users_disposable[0]
user_payment = pool_users[0].payment
Expand Down Expand Up @@ -561,7 +558,7 @@ def test_reward_amount(
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])

temp_template = "test_reward_amount"
temp_template = helpers.get_func_name()
rewards_address = cluster_manager.cache.addrs_data[pool_name]["reward"].address

init_epoch = cluster.get_last_block_epoch()
Expand Down Expand Up @@ -631,7 +628,7 @@ def test_no_reward_unmet_pledge(

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
temp_template = "test_no_reward_unmet_pledge"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
pool_user = _delegate_stake_addr(
Expand Down Expand Up @@ -747,7 +744,7 @@ def test_no_reward_unmet_pledge2(

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
temp_template = "test_no_reward_unmet_pledge"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
pool_user = _delegate_stake_addr(
Expand Down Expand Up @@ -877,7 +874,7 @@ def test_no_reward_unregistered_stake_addr(

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
temp_template = "test_no_reward_unregistered_stake_addr"
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
pool_user = _delegate_stake_addr(
Expand Down Expand Up @@ -1019,9 +1016,9 @@ def test_no_reward_unregistered_reward_addr(
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])

temp_template = "test_no_reward_stake_unregistered"
pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_reward = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["reward"])
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
pool_user = _delegate_stake_addr(
Expand Down
6 changes: 3 additions & 3 deletions cardano_node_tests/tests/test_transaction_fees.py
Expand Up @@ -289,7 +289,7 @@ def test_pool_registration_fees(
):
"""Test pool registration fees."""
no_of_addr, expected_fee = addr_fee
temp_template = f"test_pool_fees_{no_of_addr}owners"
temp_template = f"{helpers.get_func_name()}_{no_of_addr}owners"

pool_metadata = {
"name": "QA E2E test",
Expand Down Expand Up @@ -394,7 +394,7 @@ def test_addr_registration_fees(
):
"""Test stake address registration fees."""
no_of_addr, expected_fee = addr_fee
temp_template = "test_addr_registration_fees"
temp_template = helpers.get_func_name()
src_address = pool_users[0].payment.address
selected_users = pool_users[:no_of_addr]

Expand Down Expand Up @@ -428,7 +428,7 @@ def test_addr_deregistration_fees(
):
"""Test stake address deregistration fees."""
no_of_addr, expected_fee = addr_fee
temp_template = "test_addr_deregistration_fees"
temp_template = helpers.get_func_name()
src_address = pool_users[0].payment.address
selected_users = pool_users[:no_of_addr]

Expand Down
6 changes: 6 additions & 0 deletions cardano_node_tests/utils/helpers.py
Expand Up @@ -86,6 +86,12 @@ def get_vcs_link() -> str:
return url


def get_func_name() -> str:
"""Return calling function name."""
func_name = inspect.currentframe().f_back.f_code.co_name # type: ignore
return func_name


def get_id_for_mktemp(file_path: str) -> str:
"""Return an id for mktemp based on file path."""
fpart = file_path[file_path.rfind("/") + 1 :].replace(".", "_")
Expand Down

0 comments on commit cb65342

Please sign in to comment.