-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tweak expected reults query and add some test logging
- Loading branch information
1 parent
3a0de36
commit 14b2d9d
Showing
3 changed files
with
202 additions
and
12 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
internal/tests/testdata/operatorAvsRegistrationSnapshots/generateExpectedResults.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
COPY ( | ||
with filtered as ( | ||
select * from dbt_testnet_holesky_rewards.operator_avs_status | ||
where block_time < '2024-09-17' | ||
), | ||
marked_statuses AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
registered, | ||
block_time, | ||
block_date, | ||
LEAD(block_time) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_block_time, | ||
LEAD(registered) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_registration_status, | ||
LEAD(block_date) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_block_date, | ||
LAG(registered) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS prev_registered, | ||
LAG(block_date) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS prev_block_date | ||
FROM filtered | ||
), | ||
removed_same_day_deregistrations AS ( | ||
SELECT * from marked_statuses | ||
WHERE NOT ( | ||
(registered = TRUE AND | ||
COALESCE(next_registration_status = FALSE, false) AND | ||
COALESCE(block_date = next_block_date, false)) OR | ||
(registered = FALSE AND | ||
COALESCE(prev_registered = TRUE, false) and | ||
COALESCE(block_date = prev_block_date, false) | ||
) | ||
) | ||
), | ||
registration_periods AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
block_time AS start_time, | ||
COALESCE(next_block_time, TIMESTAMP '2024-09-01') AS end_time, | ||
registered | ||
FROM removed_same_day_deregistrations | ||
WHERE registered = TRUE | ||
), | ||
registration_windows_extra as ( | ||
SELECT | ||
operator, | ||
avs, | ||
date_trunc('day', start_time) + interval '1' day as start_time, | ||
date_trunc('day', end_time) as end_time | ||
FROM registration_periods | ||
), | ||
operator_avs_registration_windows as ( | ||
SELECT * from registration_windows_extra | ||
WHERE start_time != end_time | ||
), | ||
cleaned_records AS ( | ||
SELECT * FROM operator_avs_registration_windows | ||
WHERE start_time < end_time | ||
), | ||
final_results as ( | ||
SELECT | ||
operator, | ||
avs, | ||
day AS snapshot | ||
FROM cleaned_records | ||
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day | ||
) | ||
select * from final_results | ||
) TO STDOUT WITH DELIMITER ',' CSV HEADER; |
112 changes: 112 additions & 0 deletions
112
internal/tests/testdata/operatorRestakedStrategies/generateExpectedResults.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
copy (with ranked_records AS ( | ||
SELECT | ||
lower(operator) as operator, | ||
lower(avs) as avs, | ||
lower(strategy) as strategy, | ||
block_time, | ||
date_trunc('day', CAST(block_time as timestamp(6))) + interval '1' day as start_time, | ||
ROW_NUMBER() OVER ( | ||
PARTITION BY operator, avs, strategy, date_trunc('day', CAST(block_time as timestamp(6))) + interval '1' day | ||
ORDER BY block_time DESC | ||
) AS rn | ||
FROM public.operator_restaked_strategies | ||
WHERE avs_directory_address = lower('0x055733000064333caddbc92763c58bf0192ffebf') | ||
and block_time < '2024-09-17' | ||
), | ||
latest_records AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
start_time, | ||
block_time | ||
FROM ranked_records | ||
WHERE rn = 1 | ||
), | ||
grouped_records AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
start_time, | ||
LEAD(start_time) OVER ( | ||
PARTITION BY operator, avs, strategy | ||
ORDER BY start_time ASC | ||
) AS next_start_time | ||
FROM latest_records | ||
), | ||
parsed_ranges AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
start_time, | ||
CASE | ||
WHEN next_start_time IS NULL OR next_start_time > start_time + INTERVAL '1' DAY THEN start_time | ||
ELSE next_start_time | ||
END AS end_time | ||
FROM grouped_records | ||
), | ||
active_windows as ( | ||
SELECT * | ||
FROM parsed_ranges | ||
WHERE start_time != end_time | ||
), | ||
gaps_and_islands AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
start_time, | ||
end_time, | ||
LAG(end_time) OVER(PARTITION BY operator, avs, strategy ORDER BY start_time) as prev_end_time | ||
FROM active_windows | ||
), | ||
island_detection AS ( | ||
SELECT operator, avs, strategy, start_time, end_time, prev_end_time, | ||
CASE | ||
WHEN prev_end_time = start_time THEN 0 | ||
ELSE 1 | ||
END as new_island | ||
FROM gaps_and_islands | ||
), | ||
island_groups AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
start_time, | ||
end_time, | ||
SUM(new_island) OVER ( | ||
PARTITION BY operator, avs, strategy ORDER BY start_time | ||
) AS island_id | ||
FROM island_detection | ||
), | ||
operator_avs_strategy_windows AS ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
MIN(start_time) AS start_time, | ||
MAX(end_time) AS end_time | ||
FROM island_groups | ||
GROUP BY operator, avs, strategy, island_id | ||
ORDER BY operator, avs, strategy, start_time | ||
), | ||
cleaned_records AS ( | ||
SELECT * FROM operator_avs_strategy_windows | ||
WHERE start_time < end_time | ||
), | ||
final_results as ( | ||
SELECT | ||
operator, | ||
avs, | ||
strategy, | ||
cast(day AS DATE) AS snapshot | ||
FROM | ||
cleaned_records | ||
CROSS JOIN | ||
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day | ||
) | ||
select * from final_results | ||
) to STDOUT DELIMITER ',' CSV HEADER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters