Skip to content

Commit

Permalink
chore: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys committed Dec 2, 2024
1 parent ed699ff commit 93adb36
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 197 deletions.
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { v4 as uuidv4 } from 'uuid';
import type {
StarkScanTransaction,
StarkScanTransactionsResponse,
} from '../chain/data-client/starkscan';
} from '../chain/data-client/starkscan.type';
import { FeeToken } from '../types/snapApi';
import type {
AccContract,
Expand Down
11 changes: 6 additions & 5 deletions packages/starknet-snap/src/chain/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Json } from '@metamask/snaps-sdk';
import { logger } from 'ethers';
import type { Struct } from 'superstruct';
import { mask } from 'superstruct';

import { logger } from '../utils/logger';

export enum HttpMethod {
Get = 'GET',
Post = 'POST',
Expand Down Expand Up @@ -31,7 +32,7 @@ export abstract class ApiClient {
* @param response - The HTTP response to verify and convert.
* @returns A promise that resolves to the API response.
*/
protected async getResponse<ApiResponse>(
protected async parseResponse<ApiResponse>(
response: HttpResponse,
): Promise<ApiResponse> {
try {
Expand Down Expand Up @@ -79,15 +80,15 @@ export abstract class ApiClient {
}

/**
* An internal method used to submit the API request.
* An internal method used to send a HTTP request.
*
* @param params - The request parameters.
* @param [params.requestName] - The name of the request (optional).
* @param params.request - The `HttpRequest` object.
* @param params.responseStruct - The superstruct used to verify the API response.
* @returns A promise that resolves to a JSON object.
*/
protected async submitHttpRequest<ApiResponse>({
protected async sendHttpRequest<ApiResponse>({
requestName = '',
request,
responseStruct,
Expand All @@ -109,7 +110,7 @@ export abstract class ApiClient {

const httpResponse = await fetch(request.url, fetchRequest);

const jsonResponse = await this.getResponse<ApiResponse>(httpResponse);
const jsonResponse = await this.parseResponse<ApiResponse>(httpResponse);

logger.debug(`${logPrefix} response:`, JSON.stringify(jsonResponse));

Expand Down
Loading

0 comments on commit 93adb36

Please sign in to comment.