diff --git a/jest.config.ts b/jest.config.ts index b481147..b9a5ad4 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,4 +1,6 @@ import type { Config } from 'jest' +import { pathsToModuleNameMapper } from 'ts-jest' +import { compilerOptions } from './tsconfig.base.json' const config: Config = { preset: 'ts-jest', @@ -19,6 +21,10 @@ const config: Config = { statements: 43, }, }, + moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { + prefix: '/src', + }), + passWithNoTests: true, } export default config diff --git a/package.json b/package.json index b6e4c52..172df5d 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "packageManager": "pnpm@9.1.0", "dependencies": { - "@lifi/types": "^15.16.1", + "@lifi/types": "^16.5.0", "@types/memoizee": "^0.4.11", "axios": "^1.7.7", "ethers": "^6.13.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c3edc2..4faeec3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@lifi/types': - specifier: ^15.16.1 - version: 15.16.1 + specifier: ^16.5.0 + version: 16.5.0 '@types/memoizee': specifier: ^0.4.11 version: 0.4.11 @@ -797,8 +797,8 @@ packages: '@jridgewell/sourcemap-codec': 1.5.0 dev: true - /@lifi/types@15.16.1: - resolution: {integrity: sha512-OyMfTm5dfjGJwS9pl7gnmu6weCc8bg8iGobvAPbmfwKYfJ358sYgulbrhwQcvcVonrJhGVbU8faSED7byDYHQg==} + /@lifi/types@16.5.0: + resolution: {integrity: sha512-DqDNnVZiyOrtFdn3Jlloni5J2QDnVfHiS5n3bD9qX9l2ISrgp7YBTJRfNGucHfStvegSNSyuG0/THJ4Kh4f08A==} dev: false /@noble/curves@1.2.0: diff --git a/src/common/index.ts b/src/common/index.ts index 9411421..e83763c 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,4 +1,4 @@ -export type LifiError = { message: string; code: number } +type LifiError = { message: string; code: number } export const LifiError = ({ message, code, @@ -9,5 +9,7 @@ export const LifiError = ({ message, code, }) +export const isLifiError = (err: any): err is LifiError => + 'code' in err && 'message' in err export const getErrorMessage = (err: any) => 'message' in err ? String(err.message) : 'Unknown error' diff --git a/src/tenderly/tenderly.api.ts b/src/tenderly/tenderly.api.ts index 737d139..7606a97 100644 --- a/src/tenderly/tenderly.api.ts +++ b/src/tenderly/tenderly.api.ts @@ -2,7 +2,7 @@ import { ChainId, ErrorCode } from '@lifi/types' import { HttpResponse, http } from '@tenderlysim/http' import { logger } from '@tenderlysim/logger' -import { LifiError, getErrorMessage } from '@tenderlysim/common' +import { LifiError, getErrorMessage, isLifiError } from '@tenderlysim/common' import { TENDERLY_BASE_URL, @@ -105,22 +105,18 @@ const validateTransactionDetailsResponse = ( response: HttpResponse ) => { if (response.status === 401) { - const unauthorizedError = LifiError({ + throw LifiError({ message: 'Get transaction information call is Unauthorized', code: ErrorCode.UnauthorizedError, }) - - return unauthorizedError } if (response.status == 404) { - return LifiError({ + throw LifiError({ message: 'The tx was not found by Tenderly', code: ErrorCode.NotFoundError, }) } - - return response } export const getTransactionDetails = @@ -142,9 +138,7 @@ export const getTransactionDetails = { headers: TENDERLY_REQUEST_HEADERS(tenderlyConfig.accessKey) } ) - const validatedResponse = validateTransactionDetailsResponse(response) - - if (validatedResponse instanceof LifiError) throw validatedResponse + validateTransactionDetailsResponse(response) return response.data } catch (error) { @@ -153,6 +147,7 @@ export const getTransactionDetails = error )}` ) + if (isLifiError(error)) throw error throw LifiError({ message: 'The getTransactionDetails call failed', code: ErrorCode.ThirdPartyError, diff --git a/src/tenderly/tenderly.config.ts b/src/tenderly/tenderly.config.ts index 6c5daf9..06f42cf 100644 --- a/src/tenderly/tenderly.config.ts +++ b/src/tenderly/tenderly.config.ts @@ -31,7 +31,6 @@ export const TENDERLY_CHAINS: number[] = [ // Gold - 4653 ChainId.IMX, // Immutable - 13371 // Kinto - 7887 - // Lisk - 1135 ChainId.MOD, // Mode - 34443 ChainId.OPT, // Optimistic Ethereum - 10 ChainId.POL, // Polygon - 137 @@ -40,7 +39,6 @@ export const TENDERLY_CHAINS: number[] = [ // Soneium Minato - 1946 ChainId.TAI, // Taiko Mainnet - 167000 // Unreal - 18233 - // World Chain - 480 ChainId.AVA, // Avalanche C-Chain - 43114 ChainId.BSC, // BNB - 56 ChainId.FTM, // Fantom - 250 @@ -51,6 +49,8 @@ export const TENDERLY_CHAINS: number[] = [ ChainId.MOO, // Moonbeam - 1284 ChainId.MOR, // Moonriver - 1285 ChainId.RSK, // RSK - 30 + ChainId.WCC, // WorldChain - 480 + ChainId.LSK, // Lisk - 1135 // Sei Pacific-1 - 1329 // ZetaChain - 7000 // Zora - 7777777 diff --git a/src/tenderly/tenderly.int.spec.ts b/src/tenderly/tenderly.int.spec.ts index c7519b3..889f2dd 100644 --- a/src/tenderly/tenderly.int.spec.ts +++ b/src/tenderly/tenderly.int.spec.ts @@ -2,28 +2,26 @@ import { ChainId } from '@lifi/types' import { getTransactionDetails } from './tenderly.api' -beforeAll(() => { - jest.mock('@tenderlysim/http', () => { - return { - http: () => ({ - get: (url: string) => { - if ( - url.includes( - '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0' - ) - ) { - return { data: { error_message: 'execution error' } } - } else if ( - url.includes( - '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d41d0' - ) - ) { - return { code: 404 } - } - }, - }), - } - }) +jest.mock('@tenderlysim/http', () => { + return { + http: () => ({ + get: (url: string) => { + if ( + url.includes( + '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0' + ) + ) { + return { data: { error_message: 'execution error' } } + } else if ( + url.includes( + '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d41d0' + ) + ) { + return { status: 404 } + } + }, + }), + } }) describe('Tenderly', () => { @@ -37,11 +35,12 @@ describe('Tenderly', () => { expect(result.error_message).toEqual('execution error') }) + const unRealChainId = 99999 const failedRequestCases = [ { value: { hash: '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0', - chain: ChainId.AUR, + chain: unRealChainId, }, expected: 'The requested tx chain is not supported by Tenderly', },