Skip to content

Commit

Permalink
Merge pull request #833 from MoralisWeb3/main-to-beta-merge-2
Browse files Browse the repository at this point in the history
merge main to beta.
  • Loading branch information
b4rtaz authored Nov 21, 2022
2 parents 324a1eb + 76f97d6 commit bb045cb
Show file tree
Hide file tree
Showing 35 changed files with 666 additions and 778 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '',
Expand All @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ function getRequestUrlParams(_: UploadFolderRequest) {
}

function getRequestBody(request: UploadFolderRequest) {
return {
abi: request.abi,
};
return request.abi;
}

function deserializeResponse(jsonResponse: UploadFolderJSONResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
60 changes: 36 additions & 24 deletions packages/evmApi/integration/mocks/endpoints/endpointWeights.ts
Original file line number Diff line number Diff line change
@@ -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,
},
],
);
68 changes: 40 additions & 28 deletions packages/evmApi/integration/mocks/endpoints/getBlock.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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');
});
},
},
],
);
75 changes: 29 additions & 46 deletions packages/evmApi/integration/mocks/endpoints/getContractEvents.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'),
},
],
);
Loading

1 comment on commit bb045cb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 24%
25.68% (47/183) 19.56% (9/46) 22.85% (8/35)
auth Coverage: 94%
95.38% (124/130) 81.81% (18/22) 95.45% (42/44)
evm-api Coverage: 97%
97.46% (77/79) 66.66% (6/9) 95.74% (45/47)
common-evm-utils Coverage: 64%
65% (938/1443) 19.93% (123/617) 35.89% (201/560)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
73.77% (135/183) 60% (12/20) 65.67% (44/67)
common-streams-utils Coverage: 95%
95.6% (674/705) 97.93% (190/194) 100% (244/244)
streams Coverage: 87%
87.64% (525/599) 68.26% (71/104) 84.52% (142/168)

Please sign in to comment.