Skip to content

Commit

Permalink
Move all cluster_manager.get to fixtures
Browse files Browse the repository at this point in the history
So waiting for resources is not counted towards test execution time
  • Loading branch information
mkoura committed Oct 22, 2020
1 parent 567c5eb commit 70266a0
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions cardano_node_tests/tests/test_staking.py
Expand Up @@ -24,6 +24,16 @@ def temp_dir(tmp_path_factory: TempdirFactory):
yield tmp_path


@pytest.fixture
def cluster_use_pool1(cluster_manager: parallel_run.ClusterManager) -> clusterlib.ClusterLib:
return cluster_manager.get(use_resources=["node-pool1"])


@pytest.fixture
def cluster_lock_pool2(cluster_manager: parallel_run.ClusterManager) -> clusterlib.ClusterLib:
return cluster_manager.get(lock_resources=["node-pool2"])


@pytest.fixture
def pool_users(
cluster_manager: parallel_run.ClusterManager,
Expand Down Expand Up @@ -152,10 +162,11 @@ class TestDelegateAddr:
def test_delegate_using_pool_id(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
):
"""Submit registration certificate and delegate to pool using pool id."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
Expand All @@ -171,10 +182,11 @@ def test_delegate_using_pool_id(
def test_delegate_using_vkey(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
):
"""Submit registration certificate and delegate to pool using cold vkey."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
Expand All @@ -189,10 +201,11 @@ def test_delegate_using_vkey(
def test_deregister(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
):
"""Deregister stake address."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1
temp_template = helpers.get_func_name()

# submit registration certificate and delegate to pool
Expand Down Expand Up @@ -309,12 +322,13 @@ def test_addr_registration_deregistration(
def test_addr_delegation_deregistration(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
pool_users: List[clusterlib.PoolUser],
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Submit delegation and deregistration certificates in single TX."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]
Expand Down Expand Up @@ -406,11 +420,12 @@ def test_registration_cert_with_wrong_key(
def test_delegation_cert_with_wrong_key(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
pool_users: List[clusterlib.PoolUser],
):
"""Generate stake address delegation certificate using wrong key."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]
temp_template = helpers.get_func_name()
Expand Down Expand Up @@ -458,12 +473,13 @@ def test_register_addr_with_wrong_key(
def test_delegate_addr_with_wrong_key(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
pool_users: List[clusterlib.PoolUser],
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Delegate stake address using wrong key."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]
Expand Down Expand Up @@ -511,12 +527,13 @@ def test_delegate_addr_with_wrong_key(
def test_delegate_unregistered_addr(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
pool_users: List[clusterlib.PoolUser],
pool_users_disposable: List[clusterlib.PoolUser],
):
"""Delegate unregistered stake address."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

temp_template = helpers.get_func_name()
node_cold = cluster_manager.cache.addrs_data[pool_name]["cold_key_pair"]
Expand Down Expand Up @@ -581,10 +598,11 @@ class TestRewards:
def test_reward_amount(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
):
"""Check that the stake address and pool owner are receiving rewards."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

temp_template = helpers.get_func_name()
rewards_address = cluster_manager.cache.addrs_data[pool_name]["reward"].address
Expand Down Expand Up @@ -645,10 +663,11 @@ def test_reward_amount(
def test_decreasing_reward_transfered_funds(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_use_pool1: clusterlib.ClusterLib,
):
"""Check that rewards are gradually decreasing when funds are transfered."""
pool_name = "node-pool1"
cluster = cluster_manager.get(use_resources=[pool_name])
cluster = cluster_use_pool1

temp_template = helpers.get_func_name()

Expand Down Expand Up @@ -730,6 +749,7 @@ def _withdraw():
def test_no_reward_unmet_pledge1(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_lock_pool2: clusterlib.ClusterLib,
):
"""Check that the stake pool is not receiving rewards when pledge is not met.
Expand All @@ -739,7 +759,7 @@ def test_no_reward_unmet_pledge1(
Increase the needed pledge amount by changing pool parameters.
"""
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])
cluster = cluster_lock_pool2

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
Expand Down Expand Up @@ -850,6 +870,7 @@ def test_no_reward_unmet_pledge1(
def test_no_reward_unmet_pledge2(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_lock_pool2: clusterlib.ClusterLib,
):
"""Check that the stake pool is not receiving rewards when pledge is not met.
Expand All @@ -859,7 +880,7 @@ def test_no_reward_unmet_pledge2(
Withdraw part of pledge so the funds are lower than what is needed by the stake pool.
"""
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])
cluster = cluster_lock_pool2

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
Expand Down Expand Up @@ -986,14 +1007,15 @@ def test_no_reward_unmet_pledge2(
def test_no_reward_deregistered_stake_addr(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_lock_pool2: clusterlib.ClusterLib,
):
"""Check that the pool is not receiving rewards when owner's stake address is deregistered.
When the owner's stake address is deregistered (i.e. owner's stake is lower than pledge),
neither pool owners nor those who delegate to that pool receive rewards.
"""
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])
cluster = cluster_lock_pool2

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_owner = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["stake"])
Expand Down Expand Up @@ -1137,14 +1159,15 @@ def test_no_reward_deregistered_stake_addr(
def test_no_reward_deregistered_reward_addr(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_lock_pool2: clusterlib.ClusterLib,
):
"""Check that the reward address is not receiving rewards when deregistered.
The stake pool continues to operate normally and those who delegate to that pool receive
rewards.
"""
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])
cluster = cluster_lock_pool2

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_reward = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["reward"])
Expand Down Expand Up @@ -1299,14 +1322,15 @@ def test_no_reward_deregistered_reward_addr(
def test_deregister_reward_addr_retire_pool(
self,
cluster_manager: parallel_run.ClusterManager,
cluster_lock_pool2: clusterlib.ClusterLib,
):
"""Test deregistering reward address and retiring stake pool.
The pool deposit is lost when reward address is deregistered before the pool is retired.
"""
# pylint: disable=too-many-statements
pool_name = "node-pool2"
cluster = cluster_manager.get(lock_resources=[pool_name])
cluster = cluster_lock_pool2

pool_rec = cluster_manager.cache.addrs_data[pool_name]
pool_reward = clusterlib.PoolUser(payment=pool_rec["payment"], stake=pool_rec["reward"])
Expand Down

0 comments on commit 70266a0

Please sign in to comment.