Skip to content

Commit

Permalink
Update tests for db-sync 13.2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturWieczorek committed Feb 7, 2024
1 parent 2047788 commit 7e578d0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cardano_node_tests/tests/test_dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cardano_node_tests/tests/test_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions cardano_node_tests/utils/dbsync_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion cardano_node_tests/utils/dbsync_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ 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=[])

Expand Down Expand Up @@ -718,7 +730,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]
Expand Down

0 comments on commit 7e578d0

Please sign in to comment.