Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for fun #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/test
/bins
/build
/dist
Expand All @@ -7,4 +6,4 @@
.github

*.log
*.bak
*.bak
15 changes: 15 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ jobs:
node-version: 20.x
- name: Check with Prettier
run: npx prettier --check --ignore-path .prettierignore '**/*.(yml|js|ts)'

test:
name: "Run Tests"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
15 changes: 15 additions & 0 deletions .github/workflows/verify-compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ jobs:

- name: Verify TypeScript compilation
run: npm run build

test:
name: "Run Tests"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/scripts
/test
/bins
/build
/docker
Expand All @@ -10,4 +9,4 @@
.github

*.log
*.bak
*.bak
7 changes: 6 additions & 1 deletion src/tools/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
default: false,
description: "listen to finalized only",
},
blocks: {
type: "number",
description: "Number of blocks to monitor",
default: Infinity,
},
})
.check(function (argv) {
if (!argv.url && !argv.networks) {
Expand All @@ -36,7 +41,7 @@

const main = async () => {
if (argv.networks) {
argv.networks.map((network) => getMonitoredApiFor({ network, finalized: argv.finalized }));
argv.networks.map((network) => getMonitoredApiFor({ network, finalized: argv.finalized, blocks: argv.blocks }));

Check failure on line 44 in src/tools/monitor.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ network: string; finalized: boolean; blocks: number; }' is not assignable to parameter of type 'Argv'.

Check failure on line 44 in src/tools/monitor.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ network: string; finalized: boolean; blocks: number; }' is not assignable to parameter of type 'Argv'.
} else {
getMonitoredApiFor(argv);
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ export const listenBlocks = async (
api: ApiPromise,
finalized: boolean,
callBack: (blockDetails: RealtimeBlockDetails) => Promise<void>,
blocksToMonitor: number = Infinity
) => {
let latestBlockTime = 0;
let blockCount = 0;
try {
latestBlockTime = (
await api.query.timestamp.now.at((await api.rpc.chain.getBlock()).block.header.parentHash)
Expand All @@ -398,6 +400,10 @@ export const listenBlocks = async (
elapsedMilliSecs: blockDetails.blockTime - latestBlockTime,
});
latestBlockTime = blockDetails.blockTime;
blockCount++;
if (blockCount >= blocksToMonitor) {
unsubHeads();
}
});
return unsubHeads;
};
Expand Down
12 changes: 12 additions & 0 deletions test/monitor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { exec } from 'child_process';

describe('Monitor Script', () => {
test('should run without errors', (done) => {
exec('node dist/monitor.cjs --networks moonriver', (error, stdout, stderr) => {
expect(error).toBeNull();
expect(stderr).toBe('');
expect(stdout).toContain('Monitoring');
done();
});
});
});
7 changes: 7 additions & 0 deletions test/sample.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from '../src/utils/functions';

describe('Sample Test', () => {
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
});
Loading