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

#32-unit-tests-contract-service #38

Merged
merged 1 commit into from
Jun 18, 2023
Merged
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
36 changes: 36 additions & 0 deletions src/services/contract.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ConfigService } from './config.service';
import { Test, TestingModule } from '@nestjs/testing';
import { ContractService } from './contract.service';

describe('ContractService', () => {
let contractService: ContractService;
let configService: ConfigService;
let moduleRef:TestingModule;
beforeAll(async () => {
//mock conifg service
const configServiceMock = {
get: (key: string) => {
return "random string"
},
getCreds: () => {
return {
key: 'something',
secret: 'secret',
passphrase: 'passphrase'
}
}
};
moduleRef = await Test.createTestingModule({
providers: [ConfigService],
}).overrideProvider(ConfigService)
.useValue(configServiceMock).compile();
});

it('should console.log that rpc provider or private key is incorrect', async () => {
const consoleLogSpy = jest.spyOn(console, 'log');
configService = moduleRef.get<ConfigService>(ConfigService);
contractService = new ContractService(configService);
expect(consoleLogSpy).toHaveBeenCalledWith('Please provide valid private key and rpc provider in config.json file');
});

});
18 changes: 13 additions & 5 deletions src/services/polymarket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ type FeeResponse = { side: 'taker' | 'maker', fee: number };
@Injectable()
export class PolymarketService {
clobClient: ClobClient;
signer: ethers.Wallet;

constructor(private configService: ConfigService) {
const provider = new ethers.providers.JsonRpcProvider(
this.configService.get("rpcProvider")
);
const signer = new ethers.Wallet(
this.configService.get("privateKey"),
provider
);
try {
this.signer = new ethers.Wallet(
this.configService.get("privateKey"),
provider
);
} catch (error) {
console.log(
"Please provide valid private key and rpc provider in config.json file"
);
}

creds = this.configService.getCreds();
this.clobClient = new ClobClient(
CLOB_API_ENDPOINT,
Chain.POLYGON,
signer,
this.signer,
creds
);
}
Expand Down