diff --git a/cardano_node_tests/tests/test_dbsync.py b/cardano_node_tests/tests/test_dbsync.py index 5224ffe73..7f4d3c839 100644 --- a/cardano_node_tests/tests/test_dbsync.py +++ b/cardano_node_tests/tests/test_dbsync.py @@ -41,8 +41,10 @@ class TestDBSync: "epoch", "epoch_param", "epoch_stake", + "epoch_stake_progress", "epoch_sync_time", "extra_key_witness", + "extra_migrations", "ma_tx_mint", "ma_tx_out", "meta", diff --git a/cardano_node_tests/tests/test_pools.py b/cardano_node_tests/tests/test_pools.py index 7a41a456a..13f5e4e66 100644 --- a/cardano_node_tests/tests/test_pools.py +++ b/cardano_node_tests/tests/test_pools.py @@ -703,7 +703,7 @@ def _query_func(): ledger_pool_data=pool_params, pool_id=pool_creation_out.stake_pool_id ) - dbsync_utils.retry_query(query_func=_query_func, timeout=120) + dbsync_utils.retry_query(query_func=_query_func, timeout=300) @allure.link(helpers.get_vcs_link()) @common.PARAM_USE_BUILD_CMD @@ -781,7 +781,7 @@ def _query_func(): ledger_pool_data=pool_params, pool_id=pool_creation_out.stake_pool_id ) - dbsync_utils.retry_query(query_func=_query_func, timeout=120) + dbsync_utils.retry_query(query_func=_query_func, timeout=300) @allure.link(helpers.get_vcs_link()) @common.PARAM_USE_BUILD_CMD diff --git a/cardano_node_tests/utils/dbsync_queries.py b/cardano_node_tests/utils/dbsync_queries.py index b5559e6cb..0bcd67412 100644 --- a/cardano_node_tests/utils/dbsync_queries.py +++ b/cardano_node_tests/utils/dbsync_queries.py @@ -251,7 +251,7 @@ class RewardDBRow: amount: decimal.Decimal earned_epoch: int spendable_epoch: int - pool_id: str + pool_id: tp.Optional[str] = "" @dataclasses.dataclass(frozen=True) @@ -723,8 +723,25 @@ def query_address_reward( "FROM reward " "INNER JOIN stake_address ON reward.addr_id = stake_address.id " "LEFT JOIN pool_hash ON pool_hash.id = reward.pool_id " - "WHERE (stake_address.view = %s) AND (reward.spendable_epoch BETWEEN %s AND %s) " - "ORDER BY reward.id;" + "WHERE (stake_address.view = %s) AND (reward.spendable_epoch BETWEEN %s AND %s) ;" + ) + + with execute(query=query, vars=(address, epoch_from, epoch_to)) as cur: + while (result := cur.fetchone()) is not None: + yield RewardDBRow(*result) + + +def query_address_instant_reward( + address: str, epoch_from: int = 0, epoch_to: int = 99999999 +) -> tp.Generator[RewardDBRow, None, None]: + """Query instant reward records for stake address in db-sync.""" + query = ( + "SELECT" + " stake_address.view, instant_reward.type, instant_reward.amount, " + " instant_reward.earned_epoch, instant_reward.spendable_epoch " + "FROM instant_reward " + "INNER JOIN stake_address ON instant_reward.addr_id = stake_address.id " + "WHERE (stake_address.view = %s) AND (instant_reward.spendable_epoch BETWEEN %s AND %s) ;" ) with execute(query=query, vars=(address, epoch_from, epoch_to)) as cur: diff --git a/cardano_node_tests/utils/dbsync_utils.py b/cardano_node_tests/utils/dbsync_utils.py index e7e4d9adf..721f63a40 100644 --- a/cardano_node_tests/utils/dbsync_utils.py +++ b/cardano_node_tests/utils/dbsync_utils.py @@ -36,6 +36,19 @@ def get_address_reward( pool_id=db_row.pool_id or "", ) ) + + for db_row in dbsync_queries.query_address_instant_reward( + address=address, epoch_from=epoch_from, epoch_to=epoch_to + ): + rewards.append( + dbsync_types.RewardEpochRecord( + amount=int(db_row.amount), + earned_epoch=db_row.earned_epoch, + spendable_epoch=db_row.spendable_epoch, + type=db_row.type, + pool_id=db_row.pool_id or "", + ) + ) if not rewards: return dbsync_types.RewardRecord(address=address, reward_sum=0, rewards=[]) @@ -718,7 +731,8 @@ def check_pool_off_chain_fetch_error( metadata_url = (ledger_pool_data.get("metadata") or {}).get("url") or "" assert ( - f'Connection failure when fetching metadata from "{metadata_url}"' in fetch_error_str + f'Connection failure error when fetching metadata from PoolUrl "{metadata_url}"' + in fetch_error_str ), f"The error is not the expected one: {fetch_error_str}" return db_pool_off_chain_fetch_error[0]