mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Stratum V2 initial commit
This commit is contained in:
@@ -11,6 +11,7 @@ describe('StratumV1Service', () => {
|
||||
|
||||
let service: StratumV1Service;
|
||||
let clientService;
|
||||
let stratumV2Service;
|
||||
let consoleLogSpy: jest.SpyInstance;
|
||||
let consoleWarnSpy: jest.SpyInstance;
|
||||
|
||||
@@ -19,6 +20,10 @@ describe('StratumV1Service', () => {
|
||||
clientService = {
|
||||
deleteAll: jest.fn().mockResolvedValue(undefined)
|
||||
};
|
||||
stratumV2Service = {
|
||||
ensureInitialized: jest.fn().mockResolvedValue(undefined),
|
||||
createClient: jest.fn()
|
||||
};
|
||||
service = new StratumV1Service(
|
||||
{} as any,
|
||||
clientService,
|
||||
@@ -27,7 +32,8 @@ describe('StratumV1Service', () => {
|
||||
{} as any,
|
||||
{} as any,
|
||||
{} as any,
|
||||
{} as any
|
||||
{} as any,
|
||||
stratumV2Service as any
|
||||
);
|
||||
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
|
||||
@@ -145,6 +151,29 @@ describe('StratumV1Service', () => {
|
||||
expect((service as any).getTlsHandshakeTimeoutMs()).toBe(5000);
|
||||
});
|
||||
|
||||
it('should detect JSON-RPC as Stratum V1', () => {
|
||||
const firstChunk = Buffer.from('{"id":1,"method":"mining.subscribe","params":[]}\n');
|
||||
|
||||
expect((service as any).detectProtocol(firstChunk)).toBe('v1');
|
||||
});
|
||||
|
||||
it('should detect binary Noise traffic as Stratum V2', () => {
|
||||
const firstChunk = Buffer.concat([
|
||||
Buffer.from([0x01, 0x02, 0x03, 0x04]),
|
||||
Buffer.alloc(60, 0xaa)
|
||||
]);
|
||||
|
||||
expect((service as any).detectProtocol(firstChunk)).toBe('v2');
|
||||
});
|
||||
|
||||
it('should reject recognizable TLS client hello on the unified plain stratum port', () => {
|
||||
expect((service as any).detectProtocol(Buffer.from([0x16, 0x03, 0x01]))).toBeNull();
|
||||
});
|
||||
|
||||
it('should route binary data that only shares a TLS first byte to Stratum V2', () => {
|
||||
expect((service as any).detectProtocol(Buffer.from([0x16, 0xaa, 0xbb]))).toBe('v2');
|
||||
});
|
||||
|
||||
function restoreEnv(key: string, value: string | undefined) {
|
||||
if (value == null) {
|
||||
delete process.env[key];
|
||||
|
||||
Reference in New Issue
Block a user