-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEST_CONTRACT_INVOCATIONS.sql
More file actions
206 lines (174 loc) · 6.37 KB
/
TEST_CONTRACT_INVOCATIONS.sql
File metadata and controls
206 lines (174 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
-- Test Contract Invocation Extraction & Transformation
-- Run these queries after deployment to verify data flow
-- ============================================================================
-- BRONZE LAYER TESTS (PostgreSQL Hot Buffer)
-- ============================================================================
-- Test 1: Verify new columns exist in Bronze
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'operations_row_v2'
AND column_name IN ('transaction_index', 'soroban_arguments_json')
ORDER BY column_name;
-- Expected: 2 rows showing both columns exist
-- Test 2: Check if Bronze has contract invocations with new fields populated
SELECT
ledger_sequence,
transaction_index,
operation_index,
transaction_hash,
type,
soroban_contract_id,
soroban_function,
LENGTH(soroban_arguments_json) as args_json_length,
transaction_successful
FROM operations_row_v2
WHERE type = 24 -- InvokeHostFunction
AND soroban_contract_id IS NOT NULL
AND soroban_function IS NOT NULL
AND soroban_arguments_json IS NOT NULL
ORDER BY ledger_sequence DESC
LIMIT 10;
-- Expected: Recent contract invocations with populated arguments_json
-- Test 3: Count total contract invocations with complete data
SELECT
COUNT(*) as total_invocations,
COUNT(DISTINCT soroban_contract_id) as unique_contracts,
COUNT(DISTINCT soroban_function) as unique_functions,
MIN(ledger_sequence) as earliest_ledger,
MAX(ledger_sequence) as latest_ledger
FROM operations_row_v2
WHERE type = 24
AND soroban_contract_id IS NOT NULL
AND soroban_function IS NOT NULL
AND soroban_arguments_json IS NOT NULL;
-- Expected: Counts of contract invocations
-- Test 4: Inspect a sample contract invocation argument structure
SELECT
ledger_sequence,
transaction_hash,
soroban_contract_id,
soroban_function,
soroban_arguments_json,
transaction_successful
FROM operations_row_v2
WHERE type = 24
AND soroban_contract_id IS NOT NULL
AND soroban_function IS NOT NULL
AND soroban_arguments_json IS NOT NULL
ORDER BY ledger_sequence DESC
LIMIT 1;
-- Expected: Full contract invocation record with JSON arguments
-- Test 5: Verify TOID components are present
SELECT
ledger_sequence,
transaction_index,
operation_index,
-- Compute TOID (requires bit shifting - PostgreSQL syntax)
(ledger_sequence::BIGINT << 32) | (transaction_index::BIGINT << 12) | operation_index::BIGINT as toid,
transaction_hash,
soroban_contract_id,
soroban_function
FROM operations_row_v2
WHERE type = 24
AND transaction_index IS NOT NULL
AND soroban_contract_id IS NOT NULL
ORDER BY ledger_sequence DESC
LIMIT 5;
-- Expected: Contract invocations with computed TOID values
-- ============================================================================
-- SILVER LAYER TESTS (PostgreSQL Silver Hot)
-- ============================================================================
-- Run these queries against the silver_hot database
-- Test 6: Verify contract_invocations_raw table exists
SELECT
table_name,
(SELECT COUNT(*) FROM information_schema.columns WHERE table_name = 'contract_invocations_raw') as column_count
FROM information_schema.tables
WHERE table_name = 'contract_invocations_raw';
-- Expected: 1 row showing table exists with 12 columns
-- Test 7: Check Silver contract invocations count
SELECT
COUNT(*) as total_invocations,
COUNT(DISTINCT contract_id) as unique_contracts,
COUNT(DISTINCT function_name) as unique_functions,
MIN(ledger_sequence) as earliest_ledger,
MAX(ledger_sequence) as latest_ledger,
MIN(closed_at) as earliest_time,
MAX(closed_at) as latest_time
FROM contract_invocations_raw;
-- Expected: Counts matching or close to Bronze (depending on transformer progress)
-- Test 8: Sample recent contract invocations from Silver
SELECT
ledger_sequence,
transaction_index,
operation_index,
(ledger_sequence::BIGINT << 32) | (transaction_index::BIGINT << 12) | operation_index::BIGINT as toid,
transaction_hash,
contract_id,
function_name,
LENGTH(arguments_json) as args_length,
successful,
closed_at
FROM contract_invocations_raw
ORDER BY ledger_sequence DESC, transaction_index DESC, operation_index DESC
LIMIT 10;
-- Expected: Recent contract invocations with TOID
-- Test 9: Verify specific contract invocations (filter by contract_id)
SELECT
ledger_sequence,
function_name,
arguments_json,
successful,
closed_at
FROM contract_invocations_raw
WHERE contract_id = 'YOUR_CONTRACT_ID_HERE' -- Replace with actual contract ID
ORDER BY ledger_sequence DESC
LIMIT 10;
-- Expected: Invocations for specific contract
-- Test 10: Check transformation latency (Bronze vs Silver)
SELECT
'Bronze' as layer,
MAX(ledger_sequence) as max_ledger
FROM operations_row_v2
WHERE type = 24 AND soroban_contract_id IS NOT NULL
UNION ALL
SELECT
'Silver' as layer,
MAX(ledger_sequence) as max_ledger
FROM contract_invocations_raw;
-- Expected: Silver should be close to Bronze (< 10 ledgers behind)
-- ============================================================================
-- ARGUMENT PARSING TEST
-- ============================================================================
-- Test 11: Parse JSON arguments (example for Stellarcarbon)
SELECT
ledger_sequence,
contract_id,
function_name,
arguments_json,
-- Extract first 3 arguments (adjust for your contract)
arguments_json::jsonb->0 as arg0,
arguments_json::jsonb->1 as arg1,
arguments_json::jsonb->2 as arg2,
successful
FROM contract_invocations_raw
WHERE function_name = 'transfer' -- Or your function name
AND jsonb_array_length(arguments_json::jsonb) >= 3
ORDER BY ledger_sequence DESC
LIMIT 5;
-- Expected: Parsed arguments showing ScVal structure
-- ============================================================================
-- PERFORMANCE TEST
-- ============================================================================
-- Test 12: Check index usage on contract_id
EXPLAIN ANALYZE
SELECT COUNT(*)
FROM contract_invocations_raw
WHERE contract_id = 'YOUR_CONTRACT_ID_HERE';
-- Expected: Should use idx_contract_invocations_contract_id (Index Scan)
-- Test 13: Check index usage on function_name
EXPLAIN ANALYZE
SELECT COUNT(*)
FROM contract_invocations_raw
WHERE function_name = 'transfer';
-- Expected: Should use idx_contract_invocations_function (Index Scan)