Skip to content

Commit

Permalink
ci: simplify validation
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 9, 2025
1 parent 2d2000c commit bd05b36
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 55 deletions.
29 changes: 1 addition & 28 deletions .github/workflows/vaults-and-reserve-metrics-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,8 @@ jobs:
- name: Wait for GraphQL server
run: sleep 60

- name: Test VaultManagerGovernance
- name: Validate query responses
run: ./scripts/validateData.mjs
env:
entity: vaultManagerGovernances

- name: Test VaultManagerMetrics
run: ./scripts/validateData.mjs
env:
entity: vaultManagerMetrics

- name: Test VaultManagerMetricsDaily
run: ./scripts/validateData.mjs
env:
entity: vaultManagerMetricsDailies

- name: Test ReserveMetrics
run: ./scripts/validateData.mjs
env:
entity: reserveMetrics

- name: Test ReserveAllocationMetrics
run: ./scripts/validateData.mjs
env:
entity: reserveAllocationMetrics

- name: Test ReserveAllocationMetricsDaily
run: ./scripts/validateData.mjs
env:
entity: reserveAllocationMetricsDailies

- name: Notify About Failure
if: >
Expand Down
61 changes: 34 additions & 27 deletions scripts/validateData.mjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
#! /usr/bin/env node
/* eslint-env node */
import './lockdown.mjs';

import { equal } from 'node:assert/strict';
import { getQuery, expectations } from './queries.mjs';
import { assertAllDefined } from '@agoric/internal';
import { expectations, getQuery } from './queries.mjs';

const apiUrl = 'http://localhost:3000/';
console.log(`API URL set to: ${apiUrl}`);

const { entity } = process.env;
console.log(`Entity: ${entity}`);

assertAllDefined({ entity });

try {
const graphqlQuery = { query: getQuery(entity) };
/**
* @param {string} entity
*/
const checkEntity = async (entity) => {
try {
const graphqlQuery = { query: getQuery(entity) };

const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(graphqlQuery),
});
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(graphqlQuery),
});

const jsonResponse = await response.json();
console.log('Response:', JSON.stringify(jsonResponse));
const nodes = jsonResponse?.data[entity]?.nodes;
console.log('Node:', nodes);
const jsonResponse = await response.json();
console.log('Response:', JSON.stringify(jsonResponse));
const nodes = jsonResponse?.data[entity]?.nodes;
console.log('Node:', nodes);

for (const key of Object.keys(expectations[entity])) {
console.log(`Checking ${entity} ${key}...`);
equal(nodes[0]?.[key], expectations[entity][key]), `Expected ${key} to be ${expectations[entity][key]}`;
for (const key of Object.keys(expectations[entity])) {
equal(nodes[0]?.[key], expectations[entity][key]), `Expected ${key} to be ${expectations[entity][key]}`;
}
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
} catch (error) {
console.error('Error:', error);
process.exit(1);
};

for (const entity of Object.keys(expectations)) {
console.log(`Validating ${entity}...`);
await checkEntity(entity);
console.log(`Validation successful for ${entity}.`);
}

console.log('Validation successful for all entities.');

0 comments on commit bd05b36

Please sign in to comment.