From 308e5098374af3429c4900ee8a324922a3a12f24 Mon Sep 17 00:00:00 2001 From: b4rtaz Date: Fri, 18 Nov 2022 12:46:39 +0100 Subject: [PATCH 1/2] merge. --- .../mocks/endpoints/endpointWeights.ts | 60 +++-- .../integration/mocks/endpoints/getBlock.ts | 68 +++-- .../mocks/endpoints/getContractEvents.ts | 75 +++--- .../mocks/endpoints/getContractLogs.ts | 96 +++---- .../mocks/endpoints/getDateToBlock.ts | 52 ++-- .../mocks/endpoints/getPairAddress.ts | 78 +++--- .../mocks/endpoints/getPairReserves.ts | 49 ++-- .../mocks/endpoints/getTransaction.ts | 68 ++--- .../mocks/endpoints/getWalletTransactions.ts | 88 +++++-- .../mocks/endpoints/resolveAddress.ts | 52 ++-- .../mocks/endpoints/resolveDomain.ts | 53 ++-- .../mocks/endpoints/runContractFunction.ts | 72 ++++-- .../mocks/endpoints/uploadFolder.ts | 51 ++-- .../mocks/endpoints/web3ApiVersion.ts | 26 +- .../evmApi/integration/mocks/mockServer.ts | 30 ++- .../mocks/response/errorResponse.ts | 4 + packages/evmApi/integration/setup.ts | 26 +- .../integration/test/endpointWeights.test.ts | 27 +- .../evmApi/integration/test/getBlock.test.ts | 13 +- .../test/getContractEvents.test.ts | 19 +- .../integration/test/getContractLogs.test.ts | 12 +- .../integration/test/getDateToBlock.test.ts | 24 +- .../integration/test/getPairAddress.test.ts | 32 +-- .../integration/test/getPairReserves.test.ts | 18 +- .../integration/test/getTransaction.test.ts | 13 +- .../test/getWalletTransactions.test.ts | 27 +- .../integration/test/resolveAddress.test.ts | 10 +- .../integration/test/resolveDomain.test.ts | 10 +- .../test/runContractFunction.test.ts | 239 +----------------- .../integration/test/uploadFolder.test.ts | 15 +- .../integration/test/web3ApiVersion.test.ts | 10 +- yarn.lock | 26 -- 32 files changed, 665 insertions(+), 778 deletions(-) create mode 100644 packages/evmApi/integration/mocks/response/errorResponse.ts diff --git a/packages/evmApi/integration/mocks/endpoints/endpointWeights.ts b/packages/evmApi/integration/mocks/endpoints/endpointWeights.ts index a5a9ceeb11..9333b4ab47 100644 --- a/packages/evmApi/integration/mocks/endpoints/endpointWeights.ts +++ b/packages/evmApi/integration/mocks/endpoints/endpointWeights.ts @@ -1,26 +1,38 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -// TODO: we need to fix this test. -const mockEndpointWeightss = 'getBlock'; +const response = [ + { + endpoint: 'getBlock', + path: '/block/{block_number_or_hash}', + price: 5, + rateLimitCost: 5, + }, + { + endpoint: 'getContractEvents', + path: '/{address}/events', + price: 2, + rateLimitCost: 2, + }, + { + endpoint: 'getTransactions', + path: '/transaction/{transaction_hash}', + price: 1, + rateLimitCost: 1, + }, + // ... +]; -export const mockEndpointWeights = rest.get(`${EVM_API_ROOT}/info/endpointWeights`, (req, res, ctx) => { - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockEndpointWeightss; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - endpoint: value, - }), - ); -}); +export const mockEndpointWeights = MockScenarios.create( + { + name: 'mockEndpointWeights', + getParams: () => ({}), + url: '/info/endpointWeights', + method: 'get', + }, + [ + { + condition: {}, + response: response as never, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getBlock.ts b/packages/evmApi/integration/mocks/endpoints/getBlock.ts index 52c7b703f5..e80cc4c6ad 100644 --- a/packages/evmApi/integration/mocks/endpoints/getBlock.ts +++ b/packages/evmApi/integration/mocks/endpoints/getBlock.ts @@ -1,26 +1,40 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; -export const mockGetBlock = rest.get(`${EVM_API_ROOT}/block/:block_number_or_hash`, (req, res, ctx) => { - const blockNumberOrHash = req.params.block_number_or_hash as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - if (blockNumberOrHash === '404') { - return res(ctx.status(404)); - } - - if (blockNumberOrHash === '200404') { - return res(ctx.status(200), ctx.json({})); - } - - if (blockNumberOrHash === '15416422') { - return res( - ctx.status(200), - ctx.json({ +export const mockGetBlock = MockScenarios.create( + { + name: 'mockGetBlock', + getParams: (req) => ({ + chain: req.url.searchParams.get('chain'), + block_number_or_hash: req.params.block_number_or_hash, + subdomain: req.url.searchParams.get('subdomain'), + }), + url: '/block/:block_number_or_hash', + method: 'get', + }, + [ + { + condition: { + block_number_or_hash: '200404', + chain: '0x5', + }, + response: createErrorResponse('null'), + responseStatus: 404, + }, + { + condition: { + block_number_or_hash: '404', + chain: '0x5', + }, + response: createErrorResponse('Block not found'), + responseStatus: 404, + }, + { + condition: { + block_number_or_hash: '15416422', + chain: '0x5', + }, + response: { timestamp: '2022-08-26T16:29:16.000Z', number: '15416422', hash: '0xea1f77d395510ac0ef2db2aed828caf92d2c7ba4ce5632ab23b5f7078a5d6a49', @@ -63,9 +77,7 @@ export const mockGetBlock = rest.get(`${EVM_API_ROOT}/block/:block_number_or_has transfer_index: [15416422, 185], }, ], - }), - ); - } - - throw new Error('getBlock: Not supported scenario'); -}); + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getContractEvents.ts b/packages/evmApi/integration/mocks/endpoints/getContractEvents.ts index 18c05a0933..c2a73b4028 100644 --- a/packages/evmApi/integration/mocks/endpoints/getContractEvents.ts +++ b/packages/evmApi/integration/mocks/endpoints/getContractEvents.ts @@ -1,5 +1,4 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; const createResponse = (address: string) => ({ total: 12, @@ -22,49 +21,33 @@ const createResponse = (address: string) => ({ ], }); -const scenarios = [ +export const mockGetContractEvents = MockScenarios.create( { - condition: { - chain: '0x89', - address: '0x2953399124f0cbb46d2cbacd8a89cf0599974963', - topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', - fromBlock: '14327217', - toBlock: '14327217', - fromDate: '2022-03-05T13:45:42.000Z', - toDate: '2022-03-05T13:45:42.000Z', - }, - response: createResponse('0x2953399124f0cbb46d2cbacd8a89cf0599974963'), - responseStatus: 200, + name: 'mockGetContractEvents', + method: 'post', + getParams: (req) => ({ + address: req.params.address, + chain: req.url.searchParams.get('chain'), + topic: req.url.searchParams.get('topic'), + from_block: req.url.searchParams.get('from_block'), + to_block: req.url.searchParams.get('to_block'), + from_date: req.url.searchParams.get('from_date'), + to_date: req.url.searchParams.get('to_date'), + }), + url: '/:address/events', }, -]; - -export const mockGetContractEvents = rest.post(`${EVM_API_ROOT}/:address/events`, (req, res, ctx) => { - const address = req.params.address as string; - const chain = req.url.searchParams.get('chain') as string | null; - const topic = req.url.searchParams.get('topic') as string | null; - const fromBlock = req.url.searchParams.get('from_block') as string | null; - const toBlock = req.url.searchParams.get('to_block') as string | null; - const fromDate = req.url.searchParams.get('from_date') as string | null; - const toDate = req.url.searchParams.get('to_date') as string | null; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - const scenario = scenarios.find( - (s) => - s.condition.address === address && - s.condition.chain === chain && - s.condition.toBlock === toBlock && - s.condition.fromBlock === fromBlock && - s.condition.topic === topic && - s.condition.fromDate === fromDate && - s.condition.toDate === toDate, - ); - - if (scenario) { - return res(ctx.status(scenario.responseStatus), ctx.json(scenario.response)); - } - - throw new Error('getContractEvents: Not supported scenario'); -}); + [ + { + condition: { + chain: '0x89', + address: '0x2953399124f0cbb46d2cbacd8a89cf0599974963', + topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', + from_block: '14327217', + to_block: '14327217', + from_date: '2022-03-05T13:45:42.000Z', + to_date: '2022-03-05T13:45:42.000Z', + }, + response: createResponse('0x2953399124f0cbb46d2cbacd8a89cf0599974963'), + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts b/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts index 39b7b9f78c..901510be87 100644 --- a/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts +++ b/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts @@ -1,5 +1,5 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; const createResponse = (address: string) => ({ total: 100, @@ -22,58 +22,44 @@ const createResponse = (address: string) => ({ ], }); -const scenarios = [ +export const mockGetContractLogs = MockScenarios.create( { - condition: { - chain: '0x89', - address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989', - fromDate: '2022-03-05T13:45:42.000Z', - toDate: '2022-03-05T13:45:42.000Z', - subdomain: 'ethereum', - topic0: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', - topic1: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', - topic2: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', - topic3: null, - }, - response: createResponse('0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989'), - responseStatus: 200, + name: 'mockGetContractLogs', + url: '/:address/logs', + getParams: (req) => ({ + address: req.params.address, + chain: req.url.searchParams.get('chain'), + topic: req.url.searchParams.get('topic'), + topic0: req.url.searchParams.get('topic0'), + topic1: req.url.searchParams.get('topic1'), + topic2: req.url.searchParams.get('topic2'), + from_date: req.url.searchParams.get('from_date'), + to_date: req.url.searchParams.get('to_date'), + }), + method: 'get', }, -]; - -export const mockGetContractLogs = rest.get(`${EVM_API_ROOT}/:address/logs`, (req, res, ctx) => { - const address = req.params.address as string; - const chain = req.url.searchParams.get('chain') as string | null; - const topic3 = req.url.searchParams.get('topic3') as string | null; - const fromDate = req.url.searchParams.get('from_date') as string | null; - const toDate = req.url.searchParams.get('to_date') as string | null; - const topic0 = req.url.searchParams.get('topic0') as string | null; - const topic1 = req.url.searchParams.get('topic1') as string | null; - const topic2 = req.url.searchParams.get('topic2') as string | null; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - if (!address) { - return res(ctx.status(404)); - } - - const scenario = scenarios.find( - (s) => - s.condition.address === address && - s.condition.chain === chain && - s.condition.topic1 === topic1 && - s.condition.topic2 === topic2 && - s.condition.topic3 === topic3 && - s.condition.fromDate === fromDate && - s.condition.toDate === toDate && - s.condition.topic0 === topic0, - ); - - if (scenario) { - return res(ctx.status(scenario.responseStatus), ctx.json(scenario.response)); - } - - throw new Error('getContractLogs: Not supported scenario'); -}); + [ + { + condition: { + chain: '0x89', + address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989', + topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', + from_date: '2022-03-05T13:45:42.000Z', + to_date: '2022-03-05T13:45:42.000Z', + topic0: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', + topic1: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', + topic2: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', + }, + response: createResponse('0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989'), + responseStatus: 200, + }, + { + condition: { + address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b97', + chain: '0x5', + }, + response: createErrorResponse('Invalid address provided'), + responseStatus: 400, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts b/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts index cc15d6de58..c1c5b91cb4 100644 --- a/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts +++ b/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts @@ -1,29 +1,27 @@ -/* eslint-disable no-console */ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockGetDateToBlocks: Record = { - '2021-09-29T13:09:15.000Z': 13320838, -}; - -export const mockGetDateToBlock = rest.get(`${EVM_API_ROOT}/dateToBlock`, (req, res, ctx) => { - const date = req.url.searchParams.get('date') as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockGetDateToBlocks[date]; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - block: value, +export const mockGetDateToBlock = MockScenarios.create( + { + name: 'mockGetDateToBlock', + method: 'get', + getParams: (req) => ({ + chain: req.url.searchParams.get('chain'), + date: req.url.searchParams.get('date'), + providerUrl: req.url.searchParams.get('providerUrl'), }), - ); -}); + url: '/dateToBlock', + }, + [ + { + condition: { + date: '2021-09-29T13:09:15+00:00', + chain: '0x5', + }, + response: { + date: '2020-01-01T00:00:00+00:00', + block: 13320838, + timestamp: 1577836811, + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts b/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts index db00fac088..dfb7cc0bc8 100644 --- a/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts +++ b/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts @@ -1,32 +1,52 @@ -/* eslint-disable no-console */ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockGetPairAddresss: Record = { - '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c': '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', -}; - -export const mockGetPairAddress = rest.get( - `${EVM_API_ROOT}/:token0_address/:token1_address/pairAddress`, - (req, res, ctx) => { - const token0_address = req.params.token0_address as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockGetPairAddresss[token0_address]; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - token0: value, - }), - ); +export const mockGetPairAddress = MockScenarios.create( + { + name: 'mockGetPairAddress', + getParams: (req) => ({ + token0_address: req.url.searchParams.get('token0_address'), + token1_address: req.url.searchParams.get('token1_address'), + exchange: req.url.searchParams.get('exchange'), + chain: req.url.searchParams.get('chain'), + }), + url: '/:token0_address/:token1_address/pairAddress', + method: 'get', }, + [ + { + condition: { + token0_address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', + token1_address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', + exchange: 'pancakeswapv1', + chain: '0x38', + }, + response: { + token0: { + address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', + name: 'Wrapped BNB', + symbol: 'WBNB', + logo: null, + logo_hash: null, + thumbnail: null, + decimals: '18', + block_number: '8242108', + validated: 1, + created_at: '2022-01-20T10:41:03.034Z', + }, + token1: { + address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', + name: 'BUSD Token', + symbol: 'BUSD', + logo: null, + logo_hash: null, + thumbnail: null, + decimals: '18', + block_number: '8242108', + validated: 1, + created_at: '2022-01-20T10:41:03.034Z', + }, + pairAddress: '0x1b96b92314c44b159149f7e0303511fb2fc4774f', + }, + }, + ], ); diff --git a/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts b/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts index 07636b9afe..dc27f05a8f 100644 --- a/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts +++ b/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts @@ -1,28 +1,25 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockGetPairReservess: Record = { - '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b974': '232416936901978959300412', -}; - -export const mockGetPairReserves = rest.get(`${EVM_API_ROOT}/:pair_address/reserves`, (req, res, ctx) => { - const pair_address = req.params.pair_address as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockGetPairReservess[pair_address]; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - reserve0: value, +export const mockGetPairReserves = MockScenarios.create( + { + name: 'mockGetPairReserves', + getParams: (req) => ({ + pair_address: req.url.searchParams.get('pair_address'), + chain: req.url.searchParams.get('chain'), }), - ); -}); + url: '/:pair_address/reserves', + method: 'get', + }, + [ + { + condition: { + pair_address: '0x1b96b92314c44b159149f7e0303511fb2fc4774f', + chain: '0x38', + }, + response: { + reserve0: '3306559496062120878084', + reserve1: '878923281701700934205705', + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getTransaction.ts b/packages/evmApi/integration/mocks/endpoints/getTransaction.ts index 285d6414b3..1b7c1a8c60 100644 --- a/packages/evmApi/integration/mocks/endpoints/getTransaction.ts +++ b/packages/evmApi/integration/mocks/endpoints/getTransaction.ts @@ -1,27 +1,39 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; -export const mockGetTransaction = rest.get(`${EVM_API_ROOT}/transaction/:transaction_hash`, (req, res, ctx) => { - const transactionHash = req.params.transaction_hash as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - if (transactionHash === '0x4044044044044044044044044044044044044044044044044044044044044040') { - return res(ctx.status(404)); - } - - if (transactionHash === '0x2000000000000000000000000000040440440440440440440440440440440440') { - // false-positive - return res(ctx.status(200), ctx.json({})); - } - - if (transactionHash === '0x2c1150c5c8403d10714f840eb032a75f91f906c539601a4fc45835a1b830400e') { - return res( - ctx.status(200), - ctx.json({ +export const mockGetTransaction = MockScenarios.create( + { + method: 'get', + name: 'mockGetTransaction', + url: '/transaction/:transactionHash', + getParams: (req) => ({ + transactionHash: req.params.transactionHash, + subdomain: req.url.searchParams.get('subdomain'), + chain: req.url.searchParams.get('chain'), + }), + }, + [ + { + condition: { + transactionHash: '0x4044044044044044044044044044044044044044044044044044044044044040', + chain: '0x5', + }, + response: createErrorResponse('null'), + responseStatus: 404, + }, + { + condition: { + transactionHash: '0x2000000000000000000000000000040440440440440440440440440440440440', + chain: '0x5', + }, + response: {}, + }, + { + condition: { + transactionHash: '0x2c1150c5c8403d10714f840eb032a75f91f906c539601a4fc45835a1b830400e', + chain: '0x5', + }, + response: { hash: '0x2c1150c5c8403d10714f840eb032a75f91f906c539601a4fc45835a1b830400e', nonce: '4074269', transaction_index: '47', @@ -59,9 +71,7 @@ export const mockGetTransaction = rest.get(`${EVM_API_ROOT}/transaction/:transac transfer_index: [15416552, 47, 110], }, ], - }), - ); - } - - throw new Error('Not supported scenario'); -}); + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/getWalletTransactions.ts b/packages/evmApi/integration/mocks/endpoints/getWalletTransactions.ts index 8ab99b0317..297bc2edea 100644 --- a/packages/evmApi/integration/mocks/endpoints/getWalletTransactions.ts +++ b/packages/evmApi/integration/mocks/endpoints/getWalletTransactions.ts @@ -1,28 +1,64 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +/* eslint-disable etc/no-commented-out-code */ +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; -const transactions: Record = { - '0x7de3085b3190b3a787822ee16f23be010f5f8686': 404, -}; - -export const mockGetWalletTransactions = rest.get(`${EVM_API_ROOT}/:address`, (req, res, ctx) => { - const address = req.params.address as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = transactions[address]; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - total: value, +export const mockGetWalletTransactions = MockScenarios.create( + { + method: 'get', + url: `/:address`, + name: 'mockGetWalletTransactions', + getParams: (req) => ({ + address: req.params.address, + chain: req.url.searchParams.get('chain'), + subdomain: req.url.searchParams.get('subdomain'), + from_block: req.url.searchParams.get('from_block'), + to_block: req.url.searchParams.get('to_block'), + limit: req.url.searchParams.get('limit'), + to_date: req.url.searchParams.get('to_date'), + from_date: req.url.searchParams.get('from_date'), + cursor: req.url.searchParams.get('cursor'), }), - ); -}); + }, + [ + { + condition: { + address: '0x7dE3085b3190B3a787822Ee16F23be010f5F868', + chain: '0x5', + }, + response: createErrorResponse('Invalid address provided'), + responseStatus: 400, + }, + { + condition: { + address: '0x7de3085b3190b3a787822ee16f23be010f5f8686', + chain: '0x5', + }, + response: { + total: 2000, + page: 2, + page_size: 100, + result: [ + { + hash: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e', + nonce: '326595425', + transaction_index: '25', + from_address: '0xd4a3BebD824189481FC45363602b83C9c7e9cbDf', + to_address: '0xa71db868318f0a0bae9411347cd4a6fa23d8d4ef', + value: '650000000000000000', + gas: '6721975', + gas_price: '20000000000', + input: 'string', + receipt_cumulative_gas_used: '1340925', + receipt_gas_used: '1340925', + receipt_contract_address: '0x1d6a4cf64b52f6c73f201839aded7379ce58059c', + receipt_root: 'string', + receipt_status: '1', + block_timestamp: '2021-04-02T10:07:54.000Z', + block_number: '12526958', + block_hash: '0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86', + }, + ], + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/resolveAddress.ts b/packages/evmApi/integration/mocks/endpoints/resolveAddress.ts index 330204d626..32451e2d08 100644 --- a/packages/evmApi/integration/mocks/endpoints/resolveAddress.ts +++ b/packages/evmApi/integration/mocks/endpoints/resolveAddress.ts @@ -1,26 +1,30 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; -export const mockResolveAddress = rest.get(`${EVM_API_ROOT}/resolve/:address/reverse`, (req, res, ctx) => { - const address = req.params.address as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - if (address === '0x4044044044044044044044044044044044044040') { - return res(ctx.status(404)); - } - - if (address === '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') { - return res( - ctx.status(200), - ctx.json({ +export const mockResolveAddress = MockScenarios.create( + { + name: 'mockResolveAddress', + method: 'get', + getParams: (req) => ({ + address: req.params.address, + }), + url: '/resolve/:address/reverse', + }, + [ + { + condition: { + address: '0x4044044044044044044044044044044044044040', + }, + response: createErrorResponse('null'), + responseStatus: 404, + }, + { + condition: { + address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', + }, + response: { name: 'vitalik.eth', - }), - ); - } - - throw new Error('resolveAddress: Not supported scenario'); -}); + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/resolveDomain.ts b/packages/evmApi/integration/mocks/endpoints/resolveDomain.ts index 744d4d9993..0078445bdc 100644 --- a/packages/evmApi/integration/mocks/endpoints/resolveDomain.ts +++ b/packages/evmApi/integration/mocks/endpoints/resolveDomain.ts @@ -1,26 +1,31 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; +import { createErrorResponse } from '../response/errorResponse'; -export const mockResolveDomain = rest.get(`${EVM_API_ROOT}/resolve/:domain`, (req, res, ctx) => { - const domain = req.params.domain as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - if (domain === 'brad.crypto') { - return res( - ctx.status(200), - ctx.json({ +export const mockResolveDomain = MockScenarios.create( + { + name: 'mockResolveDomain', + method: 'get', + url: '/resolve/:domain', + getParams: (req) => ({ + domain: req.params.domain, + currency: req.url.searchParams.get('currency'), + }), + }, + [ + { + condition: { + domain: 'brad.crypto', + }, + response: { address: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e', - }), - ); - } - - if (domain === 'notfound.crypto') { - return res(ctx.status(404)); - } - - throw new Error('resolveDomain: Not supported scenario'); -}); + }, + }, + { + condition: { + domain: 'notfound.crypto', + }, + responseStatus: 404, + response: createErrorResponse('null'), + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts b/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts index 7efe81e778..4fdd61ee99 100644 --- a/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts +++ b/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts @@ -1,29 +1,47 @@ -/* eslint-disable no-console */ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockRunContractFunctions: Record = { - '0xecc7f044aa1ce2ad9d2453b01b8732a051213ecf': '1000000000000000000000000', -}; - -export const mockRunContractFunction = rest.post(`${EVM_API_ROOT}/:address/function`, (req, res, ctx) => { - const address = req.params.address as string; - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockRunContractFunctions[address]; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - data: value, +export const mockRunContractFunction = MockScenarios.create( + { + name: 'mockRunContractFunction', + getParams: (req) => ({ + address: req.params.address, + chain: req.url.searchParams.get('chain'), + function_name: req.url.searchParams.get('function_name'), + subdomain: req.url.searchParams.get('subdomain'), + providerUrl: req.url.searchParams.get('providerUrl'), + abi: req.body['abi'], + params: req.body['params'], }), - ); -}); + url: '/:address/function', + method: 'post', + }, + [ + { + condition: { + address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + chain: '0x1', + function_name: 'name', + subdomain: 'foo.com', + providerUrl: 'https://url', + abi: [ + { + constant: true, + inputs: [], + name: 'name', + outputs: [ + { + name: '', + type: 'string', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + ], + params: {}, + }, + response: 'Wrapped Ether' as never, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/uploadFolder.ts b/packages/evmApi/integration/mocks/endpoints/uploadFolder.ts index 77bd057b02..0aa864eee0 100644 --- a/packages/evmApi/integration/mocks/endpoints/uploadFolder.ts +++ b/packages/evmApi/integration/mocks/endpoints/uploadFolder.ts @@ -1,28 +1,27 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockUploadFolders: Record = { - 'moralis/logo.jpg': - 'https://ipfs.moralis.io:2053/ipfs/QmfL6fMaYJDnizFVj4wxyutDnGMePG2JL95rN2A5mcWyB1/moralis/logo.jpg', -}; - -export const mockUploadFolder = rest.post(`${EVM_API_ROOT}/ipfs/uploadFolder`, (req, res, ctx) => { - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - const value = mockUploadFolders; - - if (!value) { - return res(ctx.status(404)); - } - - return res( - ctx.status(200), - ctx.json({ - path: value, +export const mockUploadFolder = MockScenarios.create( + { + name: 'mockUploadFolder', + method: 'post', + getParams: (req) => ({ + abi: req.body, }), - ); -}); + url: '/ipfs/uploadFolder', + }, + [ + { + condition: { + abi: [ + { + path: 'moralis/logo.jpg', + content: 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3', + }, + ], + }, + response: { + path: 'https://ipfs.moralis.io/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/moralis/logo.jpg', + }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/endpoints/web3ApiVersion.ts b/packages/evmApi/integration/mocks/endpoints/web3ApiVersion.ts index 2776f562e7..f471a8faee 100644 --- a/packages/evmApi/integration/mocks/endpoints/web3ApiVersion.ts +++ b/packages/evmApi/integration/mocks/endpoints/web3ApiVersion.ts @@ -1,12 +1,16 @@ -import { rest } from 'msw'; -import { EVM_API_ROOT, MOCK_API_KEY } from '../config'; +import { MockScenarios } from '@moralisweb3/test-utils'; -export const mockWeb3ApiVersion = rest.get(`${EVM_API_ROOT}/web3/version`, (req, res, ctx) => { - const apiKey = req.headers.get('x-api-key'); - - if (apiKey !== MOCK_API_KEY) { - return res(ctx.status(401)); - } - - return res(ctx.status(200), ctx.json({ version: '0.0.53' })); -}); +export const mockWeb3ApiVersion = MockScenarios.create( + { + name: 'mockWeb3ApiVersion', + getParams: () => ({}), + url: '/web3/version', + method: 'get', + }, + [ + { + condition: {}, + response: { version: '0.0.53' }, + }, + ], +); diff --git a/packages/evmApi/integration/mocks/mockServer.ts b/packages/evmApi/integration/mocks/mockServer.ts index 77567d9dc0..7b17902b20 100644 --- a/packages/evmApi/integration/mocks/mockServer.ts +++ b/packages/evmApi/integration/mocks/mockServer.ts @@ -1,3 +1,4 @@ +import { MockServer } from '@moralisweb3/test-utils'; import { setupServer } from 'msw/node'; import { mockEndpointWeights } from './endpoints/endpointWeights'; import { mockGetBlock } from './endpoints/getBlock'; @@ -36,16 +37,12 @@ import { mockSearchNFTs } from './endpoints/searchNFTs'; import { mockSyncNFTContract } from './endpoints/syncNFTContract'; import { mockUploadFolder } from './endpoints/uploadFolder'; import { mockWeb3ApiVersion } from './endpoints/web3ApiVersion'; +import { EVM_API_ROOT, MOCK_API_KEY } from './config'; -const handlers = [ +export const handlers = [ mockGetNFTTransfersFromToBlock, mockSearchNFTs, - mockEndpointWeights, - mockGetBlock, - mockGetContractEvents, mockGetContractNFTs, - mockGetDateToBlock, - mockGetContractLogs, mockGetNativeBalance, mockGetNFTContractMetadata, mockGetNFTContractTransfers, @@ -56,25 +53,34 @@ const handlers = [ mockGetNFTTokenIdOwners, mockGetNFTTransfers, mockGetNFTTransfersByBlock, - mockGetPairAddress, - mockGetPairReserves, mockGetTokenAllowance, mockGetTokenMetadata, mockGetTokenMetadataBySymbol, mockGetTokenPrice, mockGetTokenTransfers, - mockGetTransaction, mockGetWalletNFTs, mockGetWalletNFTTransfers, mockGetWalletTokenTransfers, + mockSyncNFTContract, + mockGetWalletNFTCollections, +]; + +const handler2 = [ + mockGetDateToBlock, + mockGetTransaction, mockGetWalletTransactions, + mockGetContractEvents, + mockGetContractLogs, + mockGetBlock, + mockUploadFolder, mockResolveAddress, mockResolveDomain, + mockGetPairAddress, + mockGetPairReserves, mockRunContractFunction, - mockSyncNFTContract, - mockUploadFolder, mockWeb3ApiVersion, - mockGetWalletNFTCollections, + mockEndpointWeights, ]; export const mockServer = setupServer(...handlers); +export const mockServer2 = MockServer.create({ apiKey: MOCK_API_KEY, apiRoot: EVM_API_ROOT }, handler2).start(); diff --git a/packages/evmApi/integration/mocks/response/errorResponse.ts b/packages/evmApi/integration/mocks/response/errorResponse.ts new file mode 100644 index 0000000000..006801ff3c --- /dev/null +++ b/packages/evmApi/integration/mocks/response/errorResponse.ts @@ -0,0 +1,4 @@ +export const createErrorResponse = (message: string, details?: Record) => ({ + message, + details, +}); diff --git a/packages/evmApi/integration/setup.ts b/packages/evmApi/integration/setup.ts index fe83d53847..4ac0013b7c 100644 --- a/packages/evmApi/integration/setup.ts +++ b/packages/evmApi/integration/setup.ts @@ -3,7 +3,7 @@ import { Core } from '@moralisweb3/common-core'; import { CommonEvmUtils } from '@moralisweb3/common-evm-utils'; import { EvmApi } from '../src/EvmApi'; import { MOCK_API_KEY } from './mocks/config'; -import { mockServer } from './mocks/mockServer'; +import { mockServer, mockServer2 } from './mocks/mockServer'; export function setupEvmApi(): EvmApi { const core = Core.create(); @@ -25,6 +25,30 @@ export function setupEvmApi(): EvmApi { return evmApi; } +export function setupEvmApi2(): MoralisEvmApi { + const core = MoralisCore.create(); + const apiUtils = MoralisApiUtils.create(core); + const evmUtils = MoralisEvmUtils.create(core); + const evmApi = MoralisEvmApi.create(core); + + // DO NOT SET `MoralisCoreProvider.setDefault(core)` here! + + core.registerModules([apiUtils, evmUtils, evmApi]); + core.start({ + apiKey: MOCK_API_KEY, + }); + + mockServer2.listen({ + onUnhandledRequest: 'warn', + }); + + return evmApi; +} + export function cleanEvmApi() { mockServer.close(); } + +export function cleanEvmApi2() { + mockServer2.close(); +} diff --git a/packages/evmApi/integration/test/endpointWeights.test.ts b/packages/evmApi/integration/test/endpointWeights.test.ts index 55b41be1a4..85d6c6e192 100644 --- a/packages/evmApi/integration/test/endpointWeights.test.ts +++ b/packages/evmApi/integration/test/endpointWeights.test.ts @@ -1,22 +1,33 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('endpointWeights', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get the endpoint weight ', async () => { const result = await evmApi.utils.endpointWeights(); - expect(result.toJSON()).toStrictEqual({ endpoint: 'getBlock' }); - expect(result).toBeDefined(); - expect(result).toEqual(expect.arrayContaining([])); + const getBlock = result.result.find((item) => item.endpoint === 'getBlock'); + expect(getBlock?.path).toBe('/block/{block_number_or_hash}'); + expect(getBlock?.price).toBe(5); + expect((getBlock as any).rateLimitCost).toBe(5); // TODO: we need to update the model. + + const getContractEvents = result.result.find((item) => item.endpoint === 'getContractEvents'); + expect(getContractEvents?.path).toBe('/{address}/events'); + expect(getContractEvents?.price).toBe(2); + expect((getContractEvents as any).rateLimitCost).toBe(2); // TODO: we need to update the model. + + const getTransactions = result.result.find((item) => item.endpoint === 'getTransactions'); + expect(getTransactions?.path).toBe('/transaction/{transaction_hash}'); + expect(getTransactions?.price).toBe(1); + expect((getTransactions as any).rateLimitCost).toBe(1); // TODO: we need to update the model. }); }); diff --git a/packages/evmApi/integration/test/getBlock.test.ts b/packages/evmApi/integration/test/getBlock.test.ts index 8a3e65ec5e..2bd07df1b6 100644 --- a/packages/evmApi/integration/test/getBlock.test.ts +++ b/packages/evmApi/integration/test/getBlock.test.ts @@ -1,20 +1,21 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getBlock', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns null when API returns HTTP 404', async () => { const response = await evmApi.block.getBlock({ blockNumberOrHash: '404', + chain: '0x5', }); expect(response).toBeNull(); @@ -23,6 +24,7 @@ describe('getBlock', () => { it('returns null when API returns false-positive not found', async () => { const response = await evmApi.block.getBlock({ blockNumberOrHash: '200404', + chain: '0x5', }); expect(response).toBeNull(); @@ -31,6 +33,7 @@ describe('getBlock', () => { it('returns a block', async () => { const response = await evmApi.block.getBlock({ blockNumberOrHash: '15416422', + chain: '0x5', }); const result = response!.result.result; diff --git a/packages/evmApi/integration/test/getContractEvents.test.ts b/packages/evmApi/integration/test/getContractEvents.test.ts index 8b76d5eb3b..dd5b8b0c27 100644 --- a/packages/evmApi/integration/test/getContractEvents.test.ts +++ b/packages/evmApi/integration/test/getContractEvents.test.ts @@ -1,5 +1,5 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ERC721_TRANSFER_ABI = { anonymous: false, @@ -40,18 +40,18 @@ const ERC721_TRANSFER_ABI = { }; describe('getContractEvents', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns events', async () => { - const result = await evmApi.events.getContractEvents({ + const response = await evmApi.events.getContractEvents({ chain: 137, // Polygon address: '0x2953399124f0cbb46d2cbacd8a89cf0599974963', abi: ERC721_TRANSFER_ABI, @@ -62,7 +62,10 @@ describe('getContractEvents', () => { toDate: '2022-03-05T13:45:42.000Z', }); - // TODO: need to add the mock responese for above arguments. - expect(result).toBeDefined(); + const result = response.result; + expect(response).toBeDefined(); + expect(response.raw.total).toBe(12); + expect(result[0].address.lowercase).toBe('0x2953399124f0cbb46d2cbacd8a89cf0599974963'); + expect(result[0].blockNumber.toString()).toBe('14327217'); }); }); diff --git a/packages/evmApi/integration/test/getContractLogs.test.ts b/packages/evmApi/integration/test/getContractLogs.test.ts index 6acea9ff18..175e72a743 100644 --- a/packages/evmApi/integration/test/getContractLogs.test.ts +++ b/packages/evmApi/integration/test/getContractLogs.test.ts @@ -1,21 +1,22 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getContractLogs', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get logs for an address', async () => { const result = await evmApi.events.getContractLogs({ address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989', chain: 137, // Polygon + topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', fromDate: '2022-03-05T13:45:42.000Z', toDate: '2022-03-05T13:45:42.000Z', topic0: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', @@ -32,6 +33,7 @@ describe('getContractLogs', () => { const failedResult = await evmApi.events .getContractLogs({ address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b97', + chain: 56, // Goerli }) .then() .catch((err) => { diff --git a/packages/evmApi/integration/test/getDateToBlock.test.ts b/packages/evmApi/integration/test/getDateToBlock.test.ts index be82f26605..f005e17c7a 100644 --- a/packages/evmApi/integration/test/getDateToBlock.test.ts +++ b/packages/evmApi/integration/test/getDateToBlock.test.ts @@ -1,37 +1,25 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getDateToBlock', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get the closest block of the provided date ', async () => { const result = await evmApi.block.getDateToBlock({ date: '2021-09-29T13:09:15+00:00', + chain: 5, }); expect(result).toBeDefined(); expect(result.raw.block).toBe(13320838); expect(result).toEqual(expect.objectContaining({})); }); - - it('should not get get the closest block of the provided date', async () => { - const failedResult = await evmApi.block - .getDateToBlock({ - date: '2021-09-29T13:09:15+00:00', - }) - .then() - .catch((err) => { - return err; - }); - - expect(failedResult).toBeDefined(); - }); }); diff --git a/packages/evmApi/integration/test/getPairAddress.test.ts b/packages/evmApi/integration/test/getPairAddress.test.ts index fc7830c58c..385f969bf1 100644 --- a/packages/evmApi/integration/test/getPairAddress.test.ts +++ b/packages/evmApi/integration/test/getPairAddress.test.ts @@ -1,15 +1,15 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getPairAddress', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get pair data for a given pair address ', async () => { @@ -20,18 +20,14 @@ describe('getPairAddress', () => { chain: 56, }); - expect(result).toBeDefined(); - expect(result.raw).toStrictEqual({ token0: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c' }); - }); - - it('should not get pair data for a given pair address ', async () => { - expect( - evmApi.defi.getPairAddress({ - token0Address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095', - token1Address: '0xe9e7cea3dedca5984780bafc599bd69add087d5', - exchange: 'pancakeswapv1', - chain: 56, - }), - ).rejects.toThrowErrorMatchingInlineSnapshot(`"[C0005] Invalid address provided"`); + expect(result.result.pairAddress?.checksum).toEqual('0x1B96B92314C44b159149f7E0303511fB2Fc4774f'); + expect(result.result.token0.token.contractAddress.checksum).toEqual('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'); + expect(result.result.token0.token.name).toEqual('Wrapped BNB'); + expect(result.result.token0.token.symbol).toEqual('WBNB'); + expect(result.result.token0.blockNumber).toEqual('8242108'); + expect(result.result.token1.token.contractAddress.checksum).toEqual('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'); + expect(result.result.token1.token.name).toEqual('BUSD Token'); + expect(result.result.token1.token.symbol).toEqual('BUSD'); + expect(result.result.token1.blockNumber).toEqual('8242108'); }); }); diff --git a/packages/evmApi/integration/test/getPairReserves.test.ts b/packages/evmApi/integration/test/getPairReserves.test.ts index 49c8652b78..a520a1ac03 100644 --- a/packages/evmApi/integration/test/getPairReserves.test.ts +++ b/packages/evmApi/integration/test/getPairReserves.test.ts @@ -1,24 +1,24 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getPairReserves', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get the liquidity reserves for a given pair address ', async () => { const result = await evmApi.defi.getPairReserves({ - pairAddress: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b974', + pairAddress: '0x1b96b92314c44b159149f7e0303511fb2fc4774f', + chain: 0x38, }); - expect(result.toJSON().reserve0).toBe('232416936901978959300412'); - expect(result.raw.reserve0).toBe('232416936901978959300412'); - expect(result.result.reserve0).toBe('232416936901978959300412'); + expect(result.result.reserve0).toBe('3306559496062120878084'); + expect(result.result.reserve1).toBe('878923281701700934205705'); }); }); diff --git a/packages/evmApi/integration/test/getTransaction.test.ts b/packages/evmApi/integration/test/getTransaction.test.ts index f2cc0f202b..1bcbd421d6 100644 --- a/packages/evmApi/integration/test/getTransaction.test.ts +++ b/packages/evmApi/integration/test/getTransaction.test.ts @@ -1,20 +1,21 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getTransaction', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns null when API returns HTTP 404', async () => { const response = await evmApi.transaction.getTransaction({ transactionHash: '0x4044044044044044044044044044044044044044044044044044044044044040', + chain: '0x5', }); expect(response).toBeNull(); @@ -23,6 +24,7 @@ describe('getTransaction', () => { it('returns null when API returns false-positive not found', async () => { const response = await evmApi.transaction.getTransaction({ transactionHash: '0x2000000000000000000000000000040440440440440440440440440440440440', + chain: '0x5', }); expect(response).toBeNull(); @@ -31,6 +33,7 @@ describe('getTransaction', () => { it('returns properly transaction', async () => { const response = await evmApi.transaction.getTransaction({ transactionHash: '0x2c1150c5c8403d10714f840eb032a75f91f906c539601a4fc45835a1b830400e', + chain: '0x5', }); const result = response!.result; diff --git a/packages/evmApi/integration/test/getWalletTransactions.test.ts b/packages/evmApi/integration/test/getWalletTransactions.test.ts index 6704f1b978..04d1c132c6 100644 --- a/packages/evmApi/integration/test/getWalletTransactions.test.ts +++ b/packages/evmApi/integration/test/getWalletTransactions.test.ts @@ -1,34 +1,40 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getWalletTransactions', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should get the transactions of an account', async () => { - const result = await evmApi.transaction.getWalletTransactions({ + const response = await evmApi.transaction.getWalletTransactions({ address: '0x7de3085b3190b3a787822ee16f23be010f5f8686', + chain: '0x5', }); + const result = response.result; - expect(result).toBeDefined(); - expect(result.raw.total).toBe(404); - expect(result).toEqual(expect.objectContaining({})); + expect(response).toBeDefined(); + expect(response.raw.total).toBe(2000); + expect(result[0].blockHash).toBe('0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86'); + expect(result[0].blockNumber.toString()).toBe('12526958'); + expect(result[0].from.format()).toBe('0xd4a3bebd824189481fc45363602b83c9c7e9cbdf'); + expect(result[0].gas?.toString()).toBe('6721975'); }); it('should not get the transactions of an invalid account and throw an error ', async () => { const failedResult = await evmApi.transaction .getWalletTransactions({ address: '0x7dE3085b3190B3a787822Ee16F23be010f5F868', + chain: '0x5', }) .then() - .catch((err) => { + .catch((err: unknown) => { return err; }); @@ -36,6 +42,7 @@ describe('getWalletTransactions', () => { expect( evmApi.transaction.getWalletTransactions({ address: '0x7dE3085b3190B3a787822Ee16F23be010f5F868', + chain: '0x5', }), ).rejects.toThrowErrorMatchingInlineSnapshot(`"[C0005] Invalid address provided"`); }); diff --git a/packages/evmApi/integration/test/resolveAddress.test.ts b/packages/evmApi/integration/test/resolveAddress.test.ts index 46d3096cf4..d7b794590b 100644 --- a/packages/evmApi/integration/test/resolveAddress.test.ts +++ b/packages/evmApi/integration/test/resolveAddress.test.ts @@ -1,15 +1,15 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('resolveAddress', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns a name', async () => { diff --git a/packages/evmApi/integration/test/resolveDomain.test.ts b/packages/evmApi/integration/test/resolveDomain.test.ts index 1b962bb9e5..823da9bbc6 100644 --- a/packages/evmApi/integration/test/resolveDomain.test.ts +++ b/packages/evmApi/integration/test/resolveDomain.test.ts @@ -1,15 +1,15 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('resolveDomain', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns an address', async () => { diff --git a/packages/evmApi/integration/test/runContractFunction.test.ts b/packages/evmApi/integration/test/runContractFunction.test.ts index cd702c15a6..cb6fbd6fe7 100644 --- a/packages/evmApi/integration/test/runContractFunction.test.ts +++ b/packages/evmApi/integration/test/runContractFunction.test.ts @@ -1,5 +1,5 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ABI = [ { @@ -16,246 +16,31 @@ const ABI = [ stateMutability: 'view', type: 'function', }, - { - constant: false, - inputs: [ - { - name: '_spender', - type: 'address', - }, - { - name: '_value', - type: 'uint256', - }, - ], - name: 'approve', - outputs: [ - { - name: '', - type: 'bool', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, - { - constant: true, - inputs: [], - name: 'totalSupply', - outputs: [ - { - name: '', - type: 'uint256', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: false, - inputs: [ - { - name: '_from', - type: 'address', - }, - { - name: '_to', - type: 'address', - }, - { - name: '_value', - type: 'uint256', - }, - ], - name: 'transferFrom', - outputs: [ - { - name: '', - type: 'bool', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, - { - constant: true, - inputs: [], - name: 'decimals', - outputs: [ - { - name: '', - type: 'uint8', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: true, - inputs: [ - { - name: '_owner', - type: 'address', - }, - ], - name: 'balanceOf', - outputs: [ - { - name: 'balance', - type: 'uint256', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: true, - inputs: [], - name: 'symbol', - outputs: [ - { - name: '', - type: 'string', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - constant: false, - inputs: [ - { - name: '_to', - type: 'address', - }, - { - name: '_value', - type: 'uint256', - }, - ], - name: 'transfer', - outputs: [ - { - name: '', - type: 'bool', - }, - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, - { - constant: true, - inputs: [ - { - name: '_owner', - type: 'address', - }, - { - name: '_spender', - type: 'address', - }, - ], - name: 'allowance', - outputs: [ - { - name: '', - type: 'uint256', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - { - payable: true, - stateMutability: 'payable', - type: 'fallback', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - name: 'owner', - type: 'address', - }, - { - indexed: true, - name: 'spender', - type: 'address', - }, - { - indexed: false, - name: 'value', - type: 'uint256', - }, - ], - name: 'Approval', - type: 'event', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - name: 'from', - type: 'address', - }, - { - indexed: true, - name: 'to', - type: 'address', - }, - { - indexed: false, - name: 'value', - type: 'uint256', - }, - ], - name: 'Transfer', - type: 'event', - }, ]; describe('runContractFunction', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should run a contract and return readonly data', async () => { const result = await evmApi.utils.runContractFunction({ - address: '0xecc7f044aa1ce2ad9d2453b01b8732a051213ecf', - functionName: 'totalSupply', - chain: 5, + address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + functionName: 'name', + chain: 0x1, + subdomain: 'foo.com', abi: ABI, + params: {}, + providerUrl: 'https://url', }); expect(result).toBeDefined(); - expect(result).toEqual(expect.objectContaining({})); - expect(result.raw).toStrictEqual({ data: '1000000000000000000000000' }); - }); - - it('should not run when a contract when an address is invalid', async () => { - await expect( - evmApi.utils.runContractFunction({ - address: '0x123456', // this address is invalid - functionName: 'totalSupply', - chain: 5, - abi: ABI, - }), - ).rejects.toThrowErrorMatchingInlineSnapshot(`"[C0005] Invalid address provided"`); + expect(result.result).toEqual('Wrapped Ether'); }); }); diff --git a/packages/evmApi/integration/test/uploadFolder.test.ts b/packages/evmApi/integration/test/uploadFolder.test.ts index e74583a7fd..189f5efec3 100644 --- a/packages/evmApi/integration/test/uploadFolder.test.ts +++ b/packages/evmApi/integration/test/uploadFolder.test.ts @@ -1,5 +1,5 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ABI = [ { @@ -9,14 +9,14 @@ const ABI = [ ]; describe('uploadFolder', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('should Uploads multiple files and place them in a folder directory', async () => { @@ -27,10 +27,7 @@ describe('uploadFolder', () => { expect(result).toBeDefined(); expect(result).toEqual(expect.arrayContaining([])); expect(result.raw).toStrictEqual({ - path: { - 'moralis/logo.jpg': - 'https://ipfs.moralis.io:2053/ipfs/QmfL6fMaYJDnizFVj4wxyutDnGMePG2JL95rN2A5mcWyB1/moralis/logo.jpg', - }, + path: 'https://ipfs.moralis.io/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/moralis/logo.jpg', }); }); diff --git a/packages/evmApi/integration/test/web3ApiVersion.test.ts b/packages/evmApi/integration/test/web3ApiVersion.test.ts index a0bd510930..2cdef73747 100644 --- a/packages/evmApi/integration/test/web3ApiVersion.test.ts +++ b/packages/evmApi/integration/test/web3ApiVersion.test.ts @@ -1,15 +1,15 @@ -import { EvmApi } from '../../src/EvmApi'; -import { cleanEvmApi, setupEvmApi } from '../setup'; +import { MoralisEvmApi } from '../../src/EvmApi'; +import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('web3ApiVersion', () => { - let evmApi: EvmApi; + let evmApi: MoralisEvmApi; beforeAll(() => { - evmApi = setupEvmApi(); + evmApi = setupEvmApi2(); }); afterAll(() => { - cleanEvmApi(); + cleanEvmApi2(); }); it('returns version', async () => { diff --git a/yarn.lock b/yarn.lock index 3f1f52baa5..4b5ccbe4ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5303,32 +5303,6 @@ resolved "https://registry.npmjs.org/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz" integrity sha512-/kSXhY692qiV1MXu6EeOZvg5nECLclxNXcKCxJ3cXQgYuRymRHpdx/t7JXfsK+JLjwA1e1c1/SBrlQYpusC29Q== -"@moralisweb3/core@^2.7.4": - version "2.7.4" - resolved "https://registry.yarnpkg.com/@moralisweb3/core/-/core-2.7.4.tgz#b4edecf4d72ef06ca52e2ae4a8afc9e7f959a339" - integrity sha512-gIR2POQ+sTebJMEPk6vaU+nPlBigHACzAtXmPhmliOeXaaSmVUSA+RqJvm1Cy+tu/8ZCDEBWBVTtC0wPBTbZPQ== - dependencies: - axios "^0.27.2" - eventemitter3 "^4.0.7" - typed-emitter "^2.1.0" - -"@moralisweb3/evm-utils@^2.7.4": - version "2.7.4" - resolved "https://registry.yarnpkg.com/@moralisweb3/evm-utils/-/evm-utils-2.7.4.tgz#26d5225684afb1b7769aa311528a62748ef79f3f" - integrity sha512-u2scxIZBbhH3jqyt7FA7ILRKgdmT8We4h7urvn5LYQAMFyVF3jU497oW+ST9jWOp+2+5qCOQhfBAUEKHhOC9Mg== - dependencies: - "@ethersproject/address" "^5.6.0" - "@ethersproject/transactions" "^5.6.0" - "@moralisweb3/core" "^2.7.4" - -"@moralisweb3/sol-utils@^2.7.4": - version "2.7.4" - resolved "https://registry.yarnpkg.com/@moralisweb3/sol-utils/-/sol-utils-2.7.4.tgz#5308935fb182906ba5de654e7b80723986d72053" - integrity sha512-0G5OBg58Ps7SxxFjT2fNHTm4hKiCHLCQpfJYWe9huDyCr4lAIyioSGzpLBOACTEx9/VZh1AdKadWLRxSsmVxZA== - dependencies: - "@moralisweb3/core" "^2.7.4" - "@solana/web3.js" "^1.56.2" - "@moralisweb3/streams-typings@^1.0.5": version "1.0.5" resolved "https://registry.yarnpkg.com/@moralisweb3/streams-typings/-/streams-typings-1.0.5.tgz#6115031ce6428f347841d930aad3b0903ed5d8e1" From 76f97d669be9553db24e61dc404da74e2973acdd Mon Sep 17 00:00:00 2001 From: b4rtaz Date: Fri, 18 Nov 2022 13:18:05 +0100 Subject: [PATCH 2/2] fixes. --- .../defi/getPairAddressOperation.ts | 4 +- .../operations/ipfs/uploadFolderOperation.ts | 4 +- .../getWalletTransactionsOperation.ts | 43 ++++++++++--------- .../mocks/endpoints/getContractLogs.ts | 10 ++--- .../mocks/endpoints/getDateToBlock.ts | 2 +- .../mocks/endpoints/getPairAddress.ts | 4 +- .../mocks/endpoints/getPairReserves.ts | 2 +- .../mocks/endpoints/runContractFunction.ts | 2 +- packages/evmApi/integration/setup.ts | 10 ++--- .../integration/test/endpointWeights.test.ts | 4 +- .../evmApi/integration/test/getBlock.test.ts | 4 +- .../test/getContractEvents.test.ts | 4 +- .../integration/test/getContractLogs.test.ts | 12 +++--- .../integration/test/getDateToBlock.test.ts | 4 +- .../integration/test/getPairAddress.test.ts | 6 +-- .../integration/test/getPairReserves.test.ts | 4 +- .../integration/test/getTransaction.test.ts | 4 +- .../test/getWalletTransactions.test.ts | 4 +- .../integration/test/resolveAddress.test.ts | 4 +- .../integration/test/resolveDomain.test.ts | 4 +- .../test/runContractFunction.test.ts | 4 +- .../integration/test/uploadFolder.test.ts | 4 +- .../integration/test/web3ApiVersion.test.ts | 4 +- 23 files changed, 74 insertions(+), 73 deletions(-) diff --git a/packages/common/evmUtils/src/operations/defi/getPairAddressOperation.ts b/packages/common/evmUtils/src/operations/defi/getPairAddressOperation.ts index c4bf4cfa45..f44f15442b 100644 --- a/packages/common/evmUtils/src/operations/defi/getPairAddressOperation.ts +++ b/packages/common/evmUtils/src/operations/defi/getPairAddressOperation.ts @@ -65,7 +65,7 @@ type TokenJSONResponse = GetPairAddressJSONResponse['token0'] | GetPairAddressJS function createErc20Token(token: TokenJSONResponse, core: Core, chain?: EvmChainish) { return Erc20Token.create( { - contractAddress: token?.address ? EvmAddress.create(token?.address) : '', + contractAddress: token?.address ? EvmAddress.create(token?.address, core) : '', decimals: token?.decimals ?? 0, name: token?.name ?? '', symbol: token?.symbol ?? '', @@ -92,7 +92,7 @@ function deserializeResponse(jsonResponse: GetPairAddressJSONResponse, request: validated: jsonResponse.token1?.validated, createdAt: jsonResponse.token1?.created_at ? new Date(jsonResponse.token1?.created_at) : undefined, }, - pairAddress: jsonResponse.pairAddress ? EvmAddress.create(jsonResponse.pairAddress) : undefined, + pairAddress: jsonResponse.pairAddress ? EvmAddress.create(jsonResponse.pairAddress, core) : undefined, }; } diff --git a/packages/common/evmUtils/src/operations/ipfs/uploadFolderOperation.ts b/packages/common/evmUtils/src/operations/ipfs/uploadFolderOperation.ts index 2ebd077533..5e81c2073d 100644 --- a/packages/common/evmUtils/src/operations/ipfs/uploadFolderOperation.ts +++ b/packages/common/evmUtils/src/operations/ipfs/uploadFolderOperation.ts @@ -48,9 +48,7 @@ function getRequestUrlParams(_: UploadFolderRequest) { } function getRequestBody(request: UploadFolderRequest) { - return { - abi: request.abi, - }; + return request.abi; } function deserializeResponse(jsonResponse: UploadFolderJSONResponse) { diff --git a/packages/common/evmUtils/src/operations/transaction/getWalletTransactionsOperation.ts b/packages/common/evmUtils/src/operations/transaction/getWalletTransactionsOperation.ts index 587af637d1..d8efc82db0 100644 --- a/packages/common/evmUtils/src/operations/transaction/getWalletTransactionsOperation.ts +++ b/packages/common/evmUtils/src/operations/transaction/getWalletTransactionsOperation.ts @@ -100,25 +100,28 @@ function deserializeResponse( core: Core, ) { return (jsonResponse.result ?? []).map((transfer) => - EvmTransaction.create({ - cumulativeGasUsed: transfer.receipt_cumulative_gas_used, - gasPrice: transfer.gas_price, - gasUsed: transfer.receipt_gas_used, - index: +transfer.transaction_index, - contractAddress: transfer.receipt_contract_address, - receiptRoot: transfer.receipt_root, - receiptStatus: +transfer.receipt_status, - chain: EvmChainResolver.resolve(request.chain, core), - data: transfer.input, - from: transfer.from_address, - hash: transfer.hash, - nonce: transfer.nonce, - value: transfer.value, - blockHash: transfer.block_hash, - blockNumber: +transfer.block_number, - blockTimestamp: new Date(transfer.block_timestamp), - gas: BigNumber.create(transfer.gas), - to: transfer.to_address, - }), + EvmTransaction.create( + { + cumulativeGasUsed: transfer.receipt_cumulative_gas_used, + gasPrice: transfer.gas_price, + gasUsed: transfer.receipt_gas_used, + index: +transfer.transaction_index, + contractAddress: transfer.receipt_contract_address, + receiptRoot: transfer.receipt_root, + receiptStatus: +transfer.receipt_status, + chain: EvmChainResolver.resolve(request.chain, core), + data: transfer.input, + from: transfer.from_address, + hash: transfer.hash, + nonce: transfer.nonce, + value: transfer.value, + blockHash: transfer.block_hash, + blockNumber: +transfer.block_number, + blockTimestamp: new Date(transfer.block_timestamp), + gas: BigNumber.create(transfer.gas), + to: transfer.to_address, + }, + core, + ), ); } diff --git a/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts b/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts index 901510be87..9e8e4b9358 100644 --- a/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts +++ b/packages/evmApi/integration/mocks/endpoints/getContractLogs.ts @@ -29,10 +29,10 @@ export const mockGetContractLogs = MockScenarios.create( getParams: (req) => ({ address: req.params.address, chain: req.url.searchParams.get('chain'), - topic: req.url.searchParams.get('topic'), topic0: req.url.searchParams.get('topic0'), topic1: req.url.searchParams.get('topic1'), topic2: req.url.searchParams.get('topic2'), + topic3: req.url.searchParams.get('topic3'), from_date: req.url.searchParams.get('from_date'), to_date: req.url.searchParams.get('to_date'), }), @@ -43,12 +43,12 @@ export const mockGetContractLogs = MockScenarios.create( condition: { chain: '0x89', address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989', - topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', from_date: '2022-03-05T13:45:42.000Z', to_date: '2022-03-05T13:45:42.000Z', - topic0: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', - topic1: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', - topic2: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', + topic0: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', + topic1: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', + topic2: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', + topic3: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', }, response: createResponse('0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989'), responseStatus: 200, diff --git a/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts b/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts index c1c5b91cb4..b4b7664fd4 100644 --- a/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts +++ b/packages/evmApi/integration/mocks/endpoints/getDateToBlock.ts @@ -14,7 +14,7 @@ export const mockGetDateToBlock = MockScenarios.create( [ { condition: { - date: '2021-09-29T13:09:15+00:00', + date: '2021-09-29T13:09:15.000Z', chain: '0x5', }, response: { diff --git a/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts b/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts index dfb7cc0bc8..49c4ac1993 100644 --- a/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts +++ b/packages/evmApi/integration/mocks/endpoints/getPairAddress.ts @@ -4,8 +4,8 @@ export const mockGetPairAddress = MockScenarios.create( { name: 'mockGetPairAddress', getParams: (req) => ({ - token0_address: req.url.searchParams.get('token0_address'), - token1_address: req.url.searchParams.get('token1_address'), + token0_address: req.params['token0_address'], + token1_address: req.params['token1_address'], exchange: req.url.searchParams.get('exchange'), chain: req.url.searchParams.get('chain'), }), diff --git a/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts b/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts index dc27f05a8f..50754741f5 100644 --- a/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts +++ b/packages/evmApi/integration/mocks/endpoints/getPairReserves.ts @@ -4,7 +4,7 @@ export const mockGetPairReserves = MockScenarios.create( { name: 'mockGetPairReserves', getParams: (req) => ({ - pair_address: req.url.searchParams.get('pair_address'), + pair_address: req.params['pair_address'], chain: req.url.searchParams.get('chain'), }), url: '/:pair_address/reserves', diff --git a/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts b/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts index 4fdd61ee99..8de2676e65 100644 --- a/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts +++ b/packages/evmApi/integration/mocks/endpoints/runContractFunction.ts @@ -18,7 +18,7 @@ export const mockRunContractFunction = MockScenarios.create( [ { condition: { - address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', chain: '0x1', function_name: 'name', subdomain: 'foo.com', diff --git a/packages/evmApi/integration/setup.ts b/packages/evmApi/integration/setup.ts index 4ac0013b7c..eb7504fbf8 100644 --- a/packages/evmApi/integration/setup.ts +++ b/packages/evmApi/integration/setup.ts @@ -25,11 +25,11 @@ export function setupEvmApi(): EvmApi { return evmApi; } -export function setupEvmApi2(): MoralisEvmApi { - const core = MoralisCore.create(); - const apiUtils = MoralisApiUtils.create(core); - const evmUtils = MoralisEvmUtils.create(core); - const evmApi = MoralisEvmApi.create(core); +export function setupEvmApi2(): EvmApi { + const core = Core.create(); + const apiUtils = ApiUtils.create(core); + const evmUtils = CommonEvmUtils.create(core); + const evmApi = EvmApi.create(core); // DO NOT SET `MoralisCoreProvider.setDefault(core)` here! diff --git a/packages/evmApi/integration/test/endpointWeights.test.ts b/packages/evmApi/integration/test/endpointWeights.test.ts index 85d6c6e192..c4cd59678d 100644 --- a/packages/evmApi/integration/test/endpointWeights.test.ts +++ b/packages/evmApi/integration/test/endpointWeights.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('endpointWeights', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getBlock.test.ts b/packages/evmApi/integration/test/getBlock.test.ts index 2bd07df1b6..f413a4a459 100644 --- a/packages/evmApi/integration/test/getBlock.test.ts +++ b/packages/evmApi/integration/test/getBlock.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getBlock', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getContractEvents.test.ts b/packages/evmApi/integration/test/getContractEvents.test.ts index dd5b8b0c27..251fdf41c8 100644 --- a/packages/evmApi/integration/test/getContractEvents.test.ts +++ b/packages/evmApi/integration/test/getContractEvents.test.ts @@ -1,4 +1,4 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ERC721_TRANSFER_ABI = { @@ -40,7 +40,7 @@ const ERC721_TRANSFER_ABI = { }; describe('getContractEvents', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getContractLogs.test.ts b/packages/evmApi/integration/test/getContractLogs.test.ts index 175e72a743..96087782d6 100644 --- a/packages/evmApi/integration/test/getContractLogs.test.ts +++ b/packages/evmApi/integration/test/getContractLogs.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getContractLogs', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); @@ -16,12 +16,12 @@ describe('getContractLogs', () => { const result = await evmApi.events.getContractLogs({ address: '0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b989', chain: 137, // Polygon - topic: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', fromDate: '2022-03-05T13:45:42.000Z', toDate: '2022-03-05T13:45:42.000Z', - topic0: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', - topic1: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', - topic2: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', + topic0: '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', + topic1: '0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a', + topic2: '0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391', + topic3: '0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9', }); expect(result).toBeDefined(); diff --git a/packages/evmApi/integration/test/getDateToBlock.test.ts b/packages/evmApi/integration/test/getDateToBlock.test.ts index f005e17c7a..bdf02a7b25 100644 --- a/packages/evmApi/integration/test/getDateToBlock.test.ts +++ b/packages/evmApi/integration/test/getDateToBlock.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getDateToBlock', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getPairAddress.test.ts b/packages/evmApi/integration/test/getPairAddress.test.ts index 385f969bf1..d5a62d8bb8 100644 --- a/packages/evmApi/integration/test/getPairAddress.test.ts +++ b/packages/evmApi/integration/test/getPairAddress.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getPairAddress', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); @@ -25,7 +25,7 @@ describe('getPairAddress', () => { expect(result.result.token0.token.name).toEqual('Wrapped BNB'); expect(result.result.token0.token.symbol).toEqual('WBNB'); expect(result.result.token0.blockNumber).toEqual('8242108'); - expect(result.result.token1.token.contractAddress.checksum).toEqual('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'); + expect(result.result.token1.token.contractAddress.checksum).toEqual('0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'); expect(result.result.token1.token.name).toEqual('BUSD Token'); expect(result.result.token1.token.symbol).toEqual('BUSD'); expect(result.result.token1.blockNumber).toEqual('8242108'); diff --git a/packages/evmApi/integration/test/getPairReserves.test.ts b/packages/evmApi/integration/test/getPairReserves.test.ts index a520a1ac03..3125010140 100644 --- a/packages/evmApi/integration/test/getPairReserves.test.ts +++ b/packages/evmApi/integration/test/getPairReserves.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getPairReserves', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getTransaction.test.ts b/packages/evmApi/integration/test/getTransaction.test.ts index 1bcbd421d6..3762751ac2 100644 --- a/packages/evmApi/integration/test/getTransaction.test.ts +++ b/packages/evmApi/integration/test/getTransaction.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getTransaction', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/getWalletTransactions.test.ts b/packages/evmApi/integration/test/getWalletTransactions.test.ts index 04d1c132c6..799448ca38 100644 --- a/packages/evmApi/integration/test/getWalletTransactions.test.ts +++ b/packages/evmApi/integration/test/getWalletTransactions.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('getWalletTransactions', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/resolveAddress.test.ts b/packages/evmApi/integration/test/resolveAddress.test.ts index d7b794590b..4b9459bca6 100644 --- a/packages/evmApi/integration/test/resolveAddress.test.ts +++ b/packages/evmApi/integration/test/resolveAddress.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('resolveAddress', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/resolveDomain.test.ts b/packages/evmApi/integration/test/resolveDomain.test.ts index 823da9bbc6..edac53fc47 100644 --- a/packages/evmApi/integration/test/resolveDomain.test.ts +++ b/packages/evmApi/integration/test/resolveDomain.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('resolveDomain', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/runContractFunction.test.ts b/packages/evmApi/integration/test/runContractFunction.test.ts index cb6fbd6fe7..8f80ab4673 100644 --- a/packages/evmApi/integration/test/runContractFunction.test.ts +++ b/packages/evmApi/integration/test/runContractFunction.test.ts @@ -1,4 +1,4 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ABI = [ @@ -19,7 +19,7 @@ const ABI = [ ]; describe('runContractFunction', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/uploadFolder.test.ts b/packages/evmApi/integration/test/uploadFolder.test.ts index 189f5efec3..aba35d910a 100644 --- a/packages/evmApi/integration/test/uploadFolder.test.ts +++ b/packages/evmApi/integration/test/uploadFolder.test.ts @@ -1,4 +1,4 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; const ABI = [ @@ -9,7 +9,7 @@ const ABI = [ ]; describe('uploadFolder', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2(); diff --git a/packages/evmApi/integration/test/web3ApiVersion.test.ts b/packages/evmApi/integration/test/web3ApiVersion.test.ts index 2cdef73747..baa958624c 100644 --- a/packages/evmApi/integration/test/web3ApiVersion.test.ts +++ b/packages/evmApi/integration/test/web3ApiVersion.test.ts @@ -1,8 +1,8 @@ -import { MoralisEvmApi } from '../../src/EvmApi'; +import { EvmApi } from '../../src/EvmApi'; import { cleanEvmApi2, setupEvmApi2 } from '../setup'; describe('web3ApiVersion', () => { - let evmApi: MoralisEvmApi; + let evmApi: EvmApi; beforeAll(() => { evmApi = setupEvmApi2();