Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed Nov 13, 2024
1 parent 2d7217e commit 6bd80bb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppService } from './app.service';
import { RabbitMQModule } from './rabbitmq.module';
import { RpcModule } from './rpc.module';

describe('AppService', () => {
let service: AppService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [RabbitMQModule],
imports: [RabbitMQModule, RpcModule],
providers: [AppService],
}).compile();

Expand Down
71 changes: 71 additions & 0 deletions src/rpc.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// src/rpc.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import { RpcService } from './rpc.service';
import { mainnet, sepolia, arbitrumSepolia } from 'viem/chains';

describe('RpcService', () => {
let rpcService: RpcService;
// let configService: ConfigService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
RpcService,
{
provide: ConfigService,
useValue: {
get: jest.fn((key: string) => {
if (key === 'rpc.alchemyApiKey') {
return 'test-alchemy-api-key';
}
if (key === 'rpc.infuraApiKey') {
return 'test-infura-api-key';
}
return null;
}),
},
},
],
}).compile();

rpcService = module.get<RpcService>(RpcService);
// configService = module.get<ConfigService>(ConfigService);
});

describe('onModuleInit', () => {
it('should initialize transport configuration correctly', async () => {
await rpcService.onModuleInit();

// Check that transport is configured correctly for mainnet
const mainnetTransport = rpcService['transport'][mainnet.id];
expect(mainnetTransport).toBeDefined();

// Check that transport is configured correctly for sepolia
const sepoliaTransport = rpcService['transport'][sepolia.id];
expect(sepoliaTransport).toBeDefined();

// Check that transport is configured correctly for arbitrumSepolia
const arbitrumTransport = rpcService['transport'][arbitrumSepolia.id];
expect(arbitrumTransport).toBeDefined();
});
});

describe('getTransport', () => {
beforeEach(async () => {
// Ensure transport is initialized before testing getTransport
await rpcService.onModuleInit();
});

it('should return the transport for a valid chain ID', () => {
const transport = rpcService.getTransport(mainnet.id);
expect(transport).toBeDefined();
});

it('should throw an error if the transport for a chain ID is not configured', () => {
expect(() => rpcService.getTransport(999)).toThrow(
'Transport not configured for chain 999.',
);
});
});
});

0 comments on commit 6bd80bb

Please sign in to comment.