Skip to content

Commit

Permalink
Implemented githubactions to test firehose and substreams endpoints (#23
Browse files Browse the repository at this point in the history
)

* Implemented githubactions to test firehose and substreams endpoints

* import fix

* fix import

* changed github action to pull request only
  • Loading branch information
SoA432 authored Sep 18, 2024
1 parent 0ae615f commit d844de9
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/grpcurl-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Run grpcurl commands on pull request

on:
pull_request:
branches:
- '**'

jobs:
run-grpcurl:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.18'

- name: Install grpcurl
run: |
sudo apt-get update
sudo apt-get install -y curl
curl -sSL https://github.com/fullstorydev/grpcurl/releases/download/v1.8.7/grpcurl_1.8.7_linux_x86_64.tar.gz | sudo tar -xz -C /usr/local/bin
- name: Run grpcurl for substreams services
run: node scripts/run-grpcurl-substreams.js

- name: Check for grpcurl errors
if: failure()
run: |
echo "There were grpcurl errors, blocking the pull request."
exit 1
- name: Run grpcurl for firehose services
run: node scripts/run-grpcurl-firehose.js

- name: Check for grpcurl errors
if: failure()
run: |
echo "There were grpcurl errors, blocking the pull request."
exit 1
8 changes: 8 additions & 0 deletions scripts/known-issues-chains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const affectedChains = [
{
id: 'cosmoshub',
affected_services: ['firehose'],
},
];

module.exports = { affectedChains };
65 changes: 65 additions & 0 deletions scripts/run-grpcurl-firehose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const { affectedChains } = require('./known-issues-chains');
const filePath = path.resolve(__dirname, '../data/chains/V2/chains.json');
const chains = JSON.parse(
fs.readFileSync(filePath, 'utf8'),
);

function runGrpcurl(chainId, serviceName) {
return new Promise((resolve, reject) => {
const command = `grpcurl ${chainId}.${serviceName}.pinax.network:443 sf.${serviceName}.v2.EndpointInfo/Info`;
console.log(`Executing: ${command}`);

exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
reject(new Error(`Command failed: ${command}`));
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
}
console.log(`Response: ${stdout}`);
resolve(`Success: ${command}`);
});
});
}

async function run() {
try {
for (const chain of chains) {
const firehoseService = chain.supported_services.firehose;

if (
affectedChains.some(
(affectedChain) =>
affectedChain.id === chain.id &&
affectedChain.affected_services.includes('firehose'),
)
) {
console.log(
`${chain.id} is affected by known issues. Endpoint: ${chain.id}.firehose.pinax.network`,
);
return;
}
if (
firehoseService &&
firehoseService.deprecated_at === null &&
(firehoseService.beta_released_at || firehoseService.full_released_at)
) {
console.log(
`Running grpcurl for substreams service on chain ${chain.id}`,
);
await runGrpcurl(chain.id, 'firehose');
}
}
console.log('All grpcurl commands executed successfully.');
} catch (error) {
console.error('Error during grpcurl execution:', error.message);
process.exit(1);
}
}

run();
66 changes: 66 additions & 0 deletions scripts/run-grpcurl-substreams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const { affectedChains } = require('./known-issues-chains');
const filePath = path.resolve(__dirname, '../data/chains/V2/chains.json');
const chains = JSON.parse(
fs.readFileSync(filePath, 'utf8'),
);
function runGrpcurl(chainId, serviceName) {
return new Promise((resolve, reject) => {
const command = `grpcurl ${chainId}.${serviceName}.pinax.network:443 sf.${serviceName}.rpc.v2.EndpointInfo/Info`;
console.log(`Executing: ${command}`);

exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
reject(new Error(`Command failed: ${command}`));
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
}
console.log(`Response: ${stdout}`);
resolve(`Success: ${command}`);
});
});
}

async function run() {
try {
for (const chain of chains) {
const substreamsService = chain.supported_services.substreams;

if (
affectedChains.some(
(affectedChain) =>
affectedChain.id === chain.id &&
affectedChain.affected_services.includes('substreams'),
)
) {
console.log(
`${chain.id} is affected by known issues. Endpoint: ${chain.id}.substreams.pinax.network`,
);
return;
}

if (
substreamsService &&
substreamsService.deprecated_at === null &&
(substreamsService.beta_released_at ||
substreamsService.full_released_at)
) {
console.log(
`Running grpcurl for substreams service on chain ${chain.id}`,
);
await runGrpcurl(chain.id, 'substreams');
}
}
console.log('All grpcurl commands executed successfully.');
} catch (error) {
console.error('Error during grpcurl execution:', error.message);
process.exit(1);
}
}

run();

0 comments on commit d844de9

Please sign in to comment.