-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prettier, lint, workflows and fixes for API
- Loading branch information
1 parent
1aa7b1d
commit 9638f82
Showing
31 changed files
with
2,795 additions
and
1,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: JS Checks | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
js-checks: | ||
uses: hemilabs/actions/.github/workflows/js-checks.yml@main | ||
with: | ||
node-versions: '["16", "18", "20", "22"]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
22 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"extends": ["bloq", "prettier"], | ||
"ignorePatterns": ["dist", "_esm/*", "_cjs/*", "_types/*"], | ||
"overrides": [ | ||
{ | ||
"extends": ["bloq/typescript", "prettier"], | ||
"files": ["src/**/*.ts"] | ||
}, | ||
{ | ||
"extends": ["bloq/markdown"], | ||
"files": ["*.md"] | ||
}, | ||
{ | ||
"extends": ["bloq/vitest", "prettier"], | ||
"files": ["*.spec.{js,ts}"] | ||
} | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"root": true, | ||
"rules": { | ||
"arrow-body-style": "off", | ||
"no-console": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"quoteProps": "consistent", | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import WebSocket, { WebSocketServer } from 'ws'; | ||
import { L2Block } from '@cryptochords/shared'; | ||
import WebSocket, { WebSocketServer } from 'ws' | ||
import { L2Block } from '@cryptochords/shared' | ||
|
||
const BroadcastToClients = (wss: WebSocketServer, l2Block: L2Block): void => { | ||
const broadcastToClients = (wss: WebSocketServer, l2Block: L2Block): void => { | ||
wss.clients.forEach((client: WebSocket) => { | ||
if (client.readyState === WebSocket.OPEN) { | ||
client.send(JSON.stringify(l2Block.toJSON())); | ||
client.send(JSON.stringify(l2Block.toJSON())) | ||
} | ||
}); | ||
}; | ||
}) | ||
} | ||
|
||
export default BroadcastToClients | ||
export default broadcastToClients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { WebSocketServer } from 'ws'; | ||
import { EventEmitter } from 'events'; | ||
import BroadcastToClients from '../helpers/BroadcastToClients'; | ||
import { TxTypesEnum } from '@cryptochords/shared'; | ||
import { PollingService } from './pollingService'; | ||
|
||
vi.mock('ws'); | ||
import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
import { WebSocketServer } from 'ws' | ||
import { EventEmitter } from 'events' | ||
import broadcastToClients from '../helpers/broadcastToClients' | ||
import { TxTypesEnum } from '@cryptochords/shared' | ||
import { PollingService } from './pollingService' | ||
|
||
vi.mock('ws') | ||
vi.mock('../helpers/BroadcastToClients', () => ({ | ||
__esModule: true, | ||
default: vi.fn(), | ||
})); | ||
})) | ||
|
||
class MockBlockRepository extends EventEmitter { | ||
execute = vi.fn(); | ||
stop = vi.fn(); | ||
execute = vi.fn() | ||
stop = vi.fn() | ||
} | ||
|
||
describe('PollingService', () => { | ||
let pollingService: PollingService; | ||
let mockBlockRepository: MockBlockRepository; | ||
let mockWss: WebSocketServer; | ||
let pollingService: PollingService | ||
let mockBlockRepository: MockBlockRepository | ||
let mockWss: WebSocketServer | ||
|
||
beforeEach(() => { | ||
mockBlockRepository = new MockBlockRepository(); | ||
mockWss = new WebSocketServer({ noServer: true }); | ||
pollingService = new PollingService(mockBlockRepository); | ||
}); | ||
mockBlockRepository = new MockBlockRepository() | ||
mockWss = new WebSocketServer({ noServer: true }) | ||
pollingService = new PollingService(mockBlockRepository) | ||
}) | ||
|
||
it('should execute and handle Block and Eth events', () => { | ||
const websocketUrl = 'ws://test.url'; | ||
const mockL2Block = { key: 'Value' }; | ||
const websocketUrl = 'ws://test.url' | ||
const mockL2Block = { key: 'Value' } | ||
|
||
pollingService.execute(mockWss, websocketUrl); | ||
pollingService.execute(mockWss, websocketUrl) | ||
|
||
expect(mockBlockRepository.execute).toHaveBeenCalledWith(websocketUrl); | ||
expect(mockBlockRepository.execute).toHaveBeenCalledWith(websocketUrl) | ||
|
||
mockBlockRepository.emit(TxTypesEnum.Block, mockL2Block); | ||
mockBlockRepository.emit(TxTypesEnum.Eth, mockL2Block); | ||
mockBlockRepository.emit(TxTypesEnum.Block, mockL2Block) | ||
mockBlockRepository.emit(TxTypesEnum.Eth, mockL2Block) | ||
|
||
expect(BroadcastToClients).toHaveBeenCalledWith(mockWss, mockL2Block); | ||
expect(BroadcastToClients).toHaveBeenCalledTimes(2); | ||
}); | ||
expect(broadcastToClients).toHaveBeenCalledWith(mockWss, mockL2Block) | ||
expect(broadcastToClients).toHaveBeenCalledTimes(2) | ||
}) | ||
|
||
it('should stop the repository on stop', () => { | ||
pollingService.stop(); | ||
expect(mockBlockRepository.stop).toHaveBeenCalled(); | ||
}); | ||
}); | ||
pollingService.stop() | ||
expect(mockBlockRepository.stop).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { WebSocketServer } from "ws"; | ||
import { BlockRepository } from "../../domain/repositories/BlockRepository"; | ||
import BroadcastToClients from "../helpers/BroadcastToClients"; | ||
import { TxTypesEnum } from "@cryptochords/shared"; | ||
import { L2Block } from "@cryptochords/shared"; | ||
import { WebSocketServer } from 'ws' | ||
import { BlockRepository } from '../../domain/repositories/BlockRepository' | ||
import broadcastToClients from '../helpers/broadcastToClients' | ||
import { TxTypesEnum } from '@cryptochords/shared' | ||
import { L2Block } from '@cryptochords/shared' | ||
export class PollingService { | ||
constructor(private blockRepository: BlockRepository) {} | ||
|
||
execute(wss: WebSocketServer, url: string): void { | ||
this.blockRepository.execute(url) | ||
|
||
this.blockRepository.on(TxTypesEnum.Block, (l2Block: L2Block) => BroadcastToClients(wss, l2Block)); | ||
this.blockRepository.on(TxTypesEnum.Eth, (l2Block: L2Block) => BroadcastToClients(wss, l2Block)); | ||
this.blockRepository.on(TxTypesEnum.Block, (l2Block: L2Block) => | ||
broadcastToClients(wss, l2Block), | ||
) | ||
this.blockRepository.on(TxTypesEnum.Eth, (l2Block: L2Block) => | ||
broadcastToClients(wss, l2Block), | ||
) | ||
} | ||
|
||
stop() { | ||
this.blockRepository.stop() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { BlockTypesEnum } from './BlockTypesEnum'; | ||
import { describe, it, expect } from 'vitest' | ||
import { BlockTypesEnum } from './BlockTypesEnum' | ||
|
||
describe('BlockTypesEnum', () => { | ||
it('should have a LEGACY type with value "0"', () => { | ||
expect(BlockTypesEnum.LEGACY).toBe('0'); | ||
}); | ||
expect(BlockTypesEnum.LEGACY).toBe('0') | ||
}) | ||
|
||
it('should have an EIP2930 type with value "1"', () => { | ||
expect(BlockTypesEnum.EIP2930).toBe('1'); | ||
}); | ||
expect(BlockTypesEnum.EIP2930).toBe('1') | ||
}) | ||
|
||
it('should have an EIP1559 type with value "2"', () => { | ||
expect(BlockTypesEnum.EIP1559).toBe('2'); | ||
}); | ||
}); | ||
expect(BlockTypesEnum.EIP1559).toBe('2') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.