An 3897/streamline tests (#180)

This commit is contained in:
Jack Forgash 2023-09-05 16:44:38 -06:00 committed by GitHub
parent f3f362ef54
commit d8c023ba46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 269 additions and 0 deletions

View File

@ -13,6 +13,8 @@
{{ create_udf_bulk_grpc() }}
{{ create_udf_api() }}
{{ run_create_udf_array_disjunctive_union() }}
{% endset %}
{% do run_query(sql) %}
{{- fsc_utils.create_udfs() -}}

View File

@ -0,0 +1,10 @@
{% macro run_create_udf_array_disjunctive_union() %}
{% set func_sql %}
CREATE
OR REPLACE FUNCTION {{ target.database }}.silver.udf_array_disjunctive_union(
a1 ARRAY,
a2 ARRAY
) returns ARRAY LANGUAGE javascript AS 'return [...A1.filter(e => !A2.includes(e)),...A2.filter(e => !A1.includes(e))]';
{% endset %}
{% do run_query(func_sql) %}
{% endmacro %}

View File

@ -0,0 +1,45 @@
{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH streamline_blocks AS (
SELECT
*
FROM
{{ ref('silver__streamline_blocks') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
),
determine_prior_block AS (
SELECT
block_height,
block_id,
parent_id,
LAG(block_id) over (
ORDER BY
block_height
) AS prev_block_id,
LAG(block_height) over (
ORDER BY
block_height
) AS prev_block_height
FROM
streamline_blocks
)
SELECT
*
FROM
determine_prior_block
WHERE
prev_block_id != parent_id
ORDER BY
1

View File

@ -0,0 +1,70 @@
{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH collections_expected AS (
SELECT
block_height,
collection_count,
ARRAY_AGG(
VALUE :collection_id :: STRING
) AS collections_expected
FROM
{{ ref('silver__streamline_blocks') }},
LATERAL FLATTEN(collection_guarantees) {% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1,
2
),
collections_actual AS (
SELECT
block_number AS block_height,
COUNT(
DISTINCT collection_id
) AS collection_count,
ARRAY_AGG(collection_id) AS collections_actual
FROM
{{ ref('silver__streamline_collections') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1
)
SELECT
e.block_height,
e.collection_count AS expected,
COALESCE(
A.collection_count,
0
) AS actual,
expected - actual AS difference,
SILVER.UDF_ARRAY_DISJUNCTIVE_UNION(
e.collections_expected,
COALESCE(
A.collections_actual,
ARRAY_CONSTRUCT()
)
) AS missing_collections
FROM
collections_expected e
LEFT JOIN collections_actual A USING(block_height)
WHERE
expected != actual
ORDER BY
1

View File

@ -0,0 +1,71 @@
{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH results_expected AS (
SELECT
block_number AS block_height,
SUM(tx_count) AS txs_count,
ARRAY_AGG(collection_id) AS collections_expected,
array_union_agg(transaction_ids) AS txs_expected
FROM
{{ ref('silver__streamline_collections') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1
),
results_actual AS (
SELECT
block_number AS block_height,
COUNT(
DISTINCT tx_id
) AS txs_count,
ARRAY_AGG(
DISTINCT tx_id
) AS txs_actual
FROM
{{ ref('silver__streamline_transaction_results') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1
)
SELECT
e.block_height,
e.txs_count AS expected,
COALESCE(
A.txs_count,
0
) AS actual,
expected - actual AS difference,
SILVER.UDF_ARRAY_DISJUNCTIVE_UNION(
e.txs_expected,
COALESCE(
A.txs_actual,
array_construct()
)
) AS txs_missing
FROM
results_expected e
LEFT JOIN results_actual A USING(block_height)
WHERE
expected != actual
ORDER BY
1

View File

@ -0,0 +1,71 @@
{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH transactions_expected AS (
SELECT
block_number AS block_height,
SUM(tx_count) AS txs_count,
ARRAY_AGG(collection_id) AS collections_expected,
ARRAY_UNION_AGG(transaction_ids) AS txs_expected
FROM
{{ ref('silver__streamline_collections') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1
),
transactions_actual AS (
SELECT
block_number AS block_height,
COUNT(
DISTINCT tx_id
) AS txs_count,
ARRAY_AGG(
DISTINCT tx_id
) AS txs_actual
FROM
{{ ref('silver__streamline_transactions') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('start_height') }}
AND {{ var('end_height') }}
{% endif %}
GROUP BY
1
)
SELECT
e.block_height,
e.txs_count AS expected,
COALESCE(
A.txs_count,
0
) AS actual,
expected - actual AS difference,
SILVER.UDF_ARRAY_DISJUNCTIVE_UNION(
e.txs_expected,
COALESCE(
A.txs_actual,
array_construct()
)
) AS txs_missing
FROM
transactions_expected e
LEFT JOIN transactions_actual A USING(block_height)
WHERE
expected != actual
ORDER BY
1