Skip to content

Commit

Permalink
Merge pull request #844 from MoralisWeb3/update-beta-from-main2
Browse files Browse the repository at this point in the history
Update beta from main2
  • Loading branch information
ErnoW authored Nov 23, 2022
2 parents 1201d18 + 78f4e35 commit 199ee53
Show file tree
Hide file tree
Showing 80 changed files with 2,203 additions and 1,303 deletions.
1 change: 1 addition & 0 deletions packages/common/evmUtils/src/dataTypes/Erc20/Erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Erc20Token implements MoralisDataObject {
* Create a new instance of Erc20Token from any valid Erc20Token input
*
* @param value - the Erc20Tokenish type
* @param core - The MoralisCore instance
* @example
* ```ts
* const token = Erc20Token.create(value);
Expand Down
11 changes: 6 additions & 5 deletions packages/common/evmUtils/src/dataTypes/Erc20Value/Erc20Value.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, BigNumberish, CoreErrorCode, CoreError, MoralisData } from '@moralisweb3/common-core';
import MoralisCore, { BigNumber, BigNumberish, CoreError, CoreErrorCode, MoralisData } from '@moralisweb3/common-core';
import { Erc20Token, Erc20Tokenish } from '../Erc20/Erc20';

const EVM_ERC20_DEFAULT_DECIMALS = 18;
Expand Down Expand Up @@ -46,30 +46,31 @@ export class Erc20Value implements MoralisData {
* Create a new instance of Erc20Value from any valid input
* @param value - The value to create
* @param options - The options for the token
* @param core - The MoralisCore instance
* @example Erc20Value.create(1000, { decimals: 3 });
* @returns The created value
* @throws CoreError if the value is invalid
*/
static create(value: Erc20Valueish, options?: Erc20Options): Erc20Value {
static create(value: Erc20Valueish, options?: Erc20Options, core?: MoralisCore): Erc20Value {
if (value instanceof Erc20Value) {
return value;
}

return new Erc20Value(value, options);
return new Erc20Value(value, options, core);
}

private _value: Erc20ValueData;
private _token?: Erc20Token;

constructor(amount: Erc20ValueInputAmount, options?: Erc20Options) {
constructor(amount: Erc20ValueInputAmount, options?: Erc20Options, core?: MoralisCore) {
this._value = Erc20Value.parse({
amount,
decimals: options?.decimals ?? options?.token?.decimals ?? EVM_ERC20_DEFAULT_DECIMALS,
token: options?.token,
});

if (options?.token) {
this._token = Erc20Token.create(options.token);
this._token = Erc20Token.create(options.token, core);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const getNFTLowestPriceOperation: Operation<
function getRequestUrlParams(request: GetNFTLowestPriceRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
address: EvmAddress.create(request.address, core).checksum,
address: EvmAddress.create(request.address, core).lowercase,
days: maybe(request.days, String),
provider_url: request.providerUrl,
marketplace: request.marketplace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getNFTOwnersOperation: PaginatedOperation<
function getRequestUrlParams(request: GetNFTOwnersRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
address: EvmAddress.create(request.address, core).checksum,
address: EvmAddress.create(request.address, core).lowercase,
format: request.format,
limit: maybe(request.limit, String),
cursor: request.cursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getNFTTransfersOperation: PaginatedOperation<
name: 'getNFTTransfers',
id: 'getNFTTransfers',
groupName: 'nft',
urlPathPattern: '/nft/{address}/{token_id}/transfers',
urlPathPattern: '/nft/{address}/{tokenId}/transfers',
urlPathParamNames: ['address', 'tokenId'],
urlSearchParamNames: ['chain', 'format', 'limit', 'cursor'],
firstPageIndex: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ function deserializeResponse(
core: Core,
) {
return (jsonResponse ?? []).map((token) =>
Erc20Value.create(token.balance, {
decimals: token.decimals,
token: {
Erc20Value.create(
token.balance,
{
decimals: token.decimals,
name: token.name,
symbol: token.symbol,
contractAddress: token.token_address,
logo: token.logo,
thumbnail: token.thumbnail,
chain: EvmChainResolver.resolve(request.chain, core),
token: {
decimals: token.decimals,
name: token.name,
symbol: token.symbol,
contractAddress: token.token_address,
logo: token.logo,
thumbnail: token.thumbnail,
chain: EvmChainResolver.resolve(request.chain, core),
},
},
}),
core,
),
);
}

Expand Down
95 changes: 69 additions & 26 deletions packages/evmApi/integration/mocks/endpoints/getContractNFTs.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,71 @@
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 tokens: Record<string, number> = {
'0x7de3085b3190b3a787822ee16f23be010f5f8686': 741,
};

export const mockGetContractNFTs = rest.get(`${EVM_API_ROOT}/nft/: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 = tokens[address];

if (!value) {
return res(ctx.status(404));
}

return res(
ctx.status(200),
ctx.json({
total: value,
export const mockGetContractNFTs = MockScenarios.create(
{
method: 'get',
name: 'mockGetContractNFTs',
url: `/nft/:address`,
getParams: (req) => ({
address: req.params.address,
}),
);
});
},
[
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387a',
},
response: {
status: 'SYNCING',
total: 2000,
page: 2,
page_size: 100,
cursor: 'string',
result: [
{
token_address: '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB',
token_id: '15',
contract_type: 'ERC721',
owner_of: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
block_number: '88256',
block_number_minted: '88256',
token_uri: 'string',
metadata: 'string',
normalized_metadata: {
name: 'Moralis Mug',
description:
'Moralis Coffee nug 3D Asset that can be used in 3D worldspaces. This NFT is presented as a flat PNG, a Unity3D Prefab and a standard fbx.',
image:
'https://arw2wxg84h6b.moralishost.com:2053/server/files/tNJatzsHirx4V2VAep6sc923OYGxvkpBeJttR7Ks/de504bbadadcbe30c86278342fcf2560_moralismug.png',
external_link: 'https://giphy.com/gifs/loop-recursion-ting-aaODAv1iuQdgI',
animation_url: 'https://giphy.com/gifs/food-design-donuts-o9ngTPVYW4qo8',
attributes: [
{
trait_type: 'Eye Color',
value: 'hazel',
display_type: 'string',
max_value: 100,
trait_count: 7,
order: 1,
},
],
},
amount: '1',
name: 'CryptoKitties',
symbol: 'RARI',
token_hash: '502cee781b0fb40ea02508b21d319ced',
last_token_uri_sync: '2021-02-24T00:47:26.647Z',
last_metadata_sync: '2021-02-24T00:47:26.647Z',
},
],
},
},
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387',
},
responseStatus: 400,
response: createErrorResponse('[C0005] Invalid address provided'),
},
],
);
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
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 mockGetNFTContractMetadata = rest.get(`${EVM_API_ROOT}/nft/:address/metadata`, (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 === '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d') {
return res(
ctx.status(200),
ctx.json({
token_address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',
name: 'BoredApeYachtClub',
symbol: 'BAYC',
export const mockGetNFTContractMetadata = MockScenarios.create(
{
method: 'get',
name: 'mockGetNFTContractMetadata',
url: `/nft/:address/metadata`,
getParams: (req) => ({
address: req.params.address,
}),
},
[
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387a',
},
response: {
token_address: '0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09',
name: 'KryptoKitties',
synced_at: 'string',
symbol: 'RARI',
contract_type: 'ERC721',
synced_at: '2021-09-12T00:00:00.000Z',
}),
);
}

if (address === '0x4044044044044044044044044044044044044040') {
return res(ctx.status(404));
}

throw new Error('getNFTContractMetadata: Not supported scenario');
});
},
},
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387',
},
responseStatus: 400,
response: createErrorResponse('[C0005] Invalid address provided'),
},
],
);
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
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 transfers: Record<string, number> = {
'0x7de3085b3190b3a787822ee16f23be010f5f8686': 900,
};

export const mockGetNFTContractTransfers = rest.get(`${EVM_API_ROOT}/nft/:address/transfers`, (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 = transfers[address];

if (!value) {
return res(ctx.status(404));
}

return res(
ctx.status(200),
ctx.json({
total: value,
export const mockGetNFTContractTransfers = MockScenarios.create(
{
method: 'get',
name: 'mockGetNFTContractTransfers',
url: `/nft/:address/transfers`,
getParams: (req) => ({
address: req.params.address,
}),
);
});
},
[
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387a',
},
response: {
total: 2000,
page: 2,
page_size: 100,
cursor: 'string',
result: [
{
token_address: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
token_id: '15',
from_address: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
to_address: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
value: '1000000000000000',
amount: '1',
contract_type: 'ERC721',
block_number: '88256',
block_timestamp: '2021-06-04T16:00:15',
block_hash: 'string',
transaction_hash: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
transaction_type: 'string',
transaction_index: 0,
log_index: 0,
operator: '0x057Ec652A4F150f7FF94f089A38008f49a0DF88e',
},
],
block_exists: true,
index_complete: true,
},
},
{
condition: {
address: '0x75e3e9c92162e62000425c98769965a76c2e387',
},
responseStatus: 400,
response: createErrorResponse('[C0005] Invalid address provided'),
},
],
);
Loading

1 comment on commit 199ee53

@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: 25%
26.34% (49/186) 19.14% (9/47) 22.85% (8/35)
auth Coverage: 94%
95.38% (124/130) 81.81% (18/22) 95.45% (42/44)
evm-api Coverage: 100%
100% (79/79) 66.66% (6/9) 100% (47/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.