Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MET-685: Add new parameters #15

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
372 changes: 195 additions & 177 deletions clients/js/src/decorator.ts

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions clients/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,38 @@ import { Nullable, PublicKey } from '@metaplex-foundation/umi';
// RPC input. //
// ---------------------------------------- //

/**
* Display options for asset queries
*/
export type DisplayOptions = {
/**
* Whether to show unverified collections
*/
showUnverifiedCollections?: boolean;
/**
* Whether to show collection metadata
*/
showCollectionMetadata?: boolean;
/**
* Whether to show fungible assets
*/
showFungible?: boolean;
/**
* Whether to show inscription data
*/
showInscription?: boolean;
};

export type GetAssetsByAuthorityRpcInput = {
/**
* The address of the authority of the assets.
*/
authority: PublicKey;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByCreatorRpcInput = {
Expand All @@ -21,6 +48,11 @@ export type GetAssetsByCreatorRpcInput = {
* Indicates whether to retrieve only verified assets or not.
*/
onlyVerified: boolean;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByGroupRpcInput = {
Expand All @@ -33,13 +65,23 @@ export type GetAssetsByGroupRpcInput = {
* The value of the group
*/
groupValue: string;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type GetAssetsByOwnerRpcInput = {
/**
* The address of the owner of the assets.
*/
owner: PublicKey;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
} & Pagination;

export type SearchAssetsRpcInput = {
Expand All @@ -58,6 +100,11 @@ export type SearchAssetsRpcInput = {
*/
interface?: Nullable<DasApiAssetInterface>;

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;

/**
* The value for the JSON URI.
*/
Expand Down Expand Up @@ -144,6 +191,36 @@ export type SearchAssetsRpcInput = {
burnt?: Nullable<boolean>;
} & Pagination;

/**
* Input parameters for getAsset RPC call
*/
export type GetAssetRpcInput = {
/**
* The asset ID to fetch
*/
assetId: PublicKey;

/**
* Display options for the query
*/
options?: DisplayOptions;
};

/**
* Input parameters for getAssets RPC call
*/
export type GetAssetsRpcInput = {
/**
* Array of asset IDs to fetch
*/
assetIds: PublicKey[];

/**
* Display options for the query
*/
displayOptions?: DisplayOptions;
};

// ---------------------------------------- //
// Result types. //
// ---------------------------------------- //
Expand Down Expand Up @@ -321,6 +398,11 @@ type Pagination = {
* Retrieve assets after the specified `ID` value.
*/
after?: Nullable<string>;

/**
*
*/
cursor?: Nullable<string>;
};

/**
Expand All @@ -337,6 +419,7 @@ export type DasApiAssetInterface =
| 'LEGACY_NFT'
| 'V2_NFT'
| 'FungibleAsset'
| 'FungibleToken'
| 'Custom'
| 'Identity'
| 'Executable'
Expand Down Expand Up @@ -407,6 +490,13 @@ export type DasApiPropGroupKey = 'collection';
export type DasApiAssetGrouping = {
group_key: DasApiPropGroupKey;
group_value: string;
verified?: boolean;
collection_metadata?: {
name: string;
symbol: string;
description: string;
image: string;
};
};

export type DasApiAuthorityScope =
Expand Down
6 changes: 4 additions & 2 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export const DAS_API_ENDPOINTS: { name: string; url: string }[] = [];
Object.keys(process.env).forEach(function (key) {
if (key.startsWith('DAS_API_')) {
const name = key.substring('DAS_API_'.length);
const url = process.env[key]!;
DAS_API_ENDPOINTS.push({ name, url });
const url = process.env[key];
if (url) {
DAS_API_ENDPOINTS.push({ name, url });
}
}
});

Expand Down
54 changes: 48 additions & 6 deletions clients/js/test/getAsset.test.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the test coverage as I see it:

Method showUnverifiedCollections: true showUnverifiedCollections: false showCollectionMetadata: true showFungible: true onlyVerified: true onlyVerified: false
getAsset
getAssets
getAssetsByAuthority
getAssetsByCreator
getAssetsByGroup
getAssetsByOwner
searchAssets

Looks like everything is covered to some degree except showInscription which maybe is fine if we don't easily have those assets to test with.

Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
test(`it can fetch a regular asset by ID (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('8bFQbnBrzeiYQabEJ1ghy5T7uFpqFzPjUGsVi3SzSMHB');
const assetId = publicKey('Hu9vvgNjVDxRo6F8iTEo6sRJikhqoM2zVswR86WAf4C');

// When we fetch the asset using its ID.
const asset = await umi.rpc.getAsset(assetId);

// Then we expect the following data.
t.like(asset, <DasApiAsset>{
interface: 'ProgrammableNFT',
interface: 'V1_NFT',
id: assetId,
content: {
metadata: {
Expand All @@ -66,12 +66,54 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
t.like(asset.compression, <DasApiAssetCompression>{
compressed: false,
});
t.deepEqual(asset.grouping.length, 1);
t.deepEqual(asset.mutable, true);
t.deepEqual(asset.burnt, false);
});

test(`it can fetch a regular asset by ID not showing unverified collection data using showUnverifiedCollections false (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('5smGnzgaMsQ3JV7jWCvSxnRkHjP2dJoi1uczHTx87tji');

// When we fetch the asset using its ID with display options.
await t.throwsAsync(
async () => {
await umi.rpc.getAsset({
assetId,
options: { showUnverifiedCollections: false },
});
},
{
message: /Asset not found/,
}
);
});

test(`it can fetch a regular asset by ID with unverified collection data using showUnverifiedCollections true (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const assetId = publicKey('5smGnzgaMsQ3JV7jWCvSxnRkHjP2dJoi1uczHTx87tji');

// When we fetch the asset using its ID.
const asset = await umi.rpc.getAsset({
assetId,
options: { showUnverifiedCollections: true },
});

t.like(asset, <DasApiAsset>{
interface: 'V1_NFT',
id: assetId,
content: {
metadata: {
name: 'unverified Azure 55',
},
},
});
t.is(asset.grouping.length, 1);
t.like(asset.grouping[0], {
group_key: 'collection',
group_value: '5RT4e9uHUgG9h13cSc3L4YvkDc9qXSznoLaX4Tx8cpWS',
group_value: '5g2h8NuNNdb2riSuAKC3JJrrJKGJUH9dxM23fqdYgGt2',
verified: false,
});
t.deepEqual(asset.mutable, true);
t.deepEqual(asset.burnt, false);
});
});
101 changes: 101 additions & 0 deletions clients/js/test/getAssets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,105 @@ DAS_API_ENDPOINTS.forEach((endpoint) => {
t.deepEqual(assets[1].mutable, true);
t.deepEqual(assets[1].burnt, false);
});

test(`it can fetch multiple assets by ID with showUnverifiedCollections true (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const compressedAssetId = publicKey(
'GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA'
);
const regularAssetId = publicKey(
'8bFQbnBrzeiYQabEJ1ghy5T7uFpqFzPjUGsVi3SzSMHB'
);

// When we fetch the assets using their IDs with display options.
const assets = await umi.rpc.getAssets({
assetIds: [compressedAssetId, regularAssetId],
displayOptions: {
showUnverifiedCollections: true,
},
});

// Then we expect to get the assets back.
t.is(assets.length, 2);
t.deepEqual(assets[0].id, compressedAssetId);
t.deepEqual(assets[1].id, regularAssetId);

//And asset1 should have grouping data
t.deepEqual(assets[1].grouping.length, 1);
});

test(`it can fetch multiple assets by ID with showCollectionMetadata true (${endpoint.name})`, async (t) => {
// Given a minted NFT.
const umi = createUmi(endpoint.url);
const compressedAssetId = publicKey(
'GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA'
);
const regularAssetId = publicKey(
'8bFQbnBrzeiYQabEJ1ghy5T7uFpqFzPjUGsVi3SzSMHB'
);

// When we fetch the assets using their IDs with display options.
const assets = await umi.rpc.getAssets({
assetIds: [compressedAssetId, regularAssetId],
displayOptions: {
showCollectionMetadata: true,
},
});

// Then we expect to get the assets back with collection metadata.
t.is(assets.length, 2);
t.deepEqual(assets[1].id, regularAssetId);

// Verify collection metadata is present in the grouping
const assetWithCollectionMetadata = assets.find(
(asset) => asset.grouping[0]?.collection_metadata
);
t.truthy(
assetWithCollectionMetadata,
'Expected to find an asset with collection metadata'
);
if (!assetWithCollectionMetadata) return;

t.like(assetWithCollectionMetadata.grouping[0], {
group_key: 'collection',
group_value: '5RT4e9uHUgG9h13cSc3L4YvkDc9qXSznoLaX4Tx8cpWS',
verified: false,
collection_metadata: {
name: 'Chiaki Azure 55 Collection',
symbol: '',
image:
'https://arweave.net/fFcYDkRHF-936IbAZ3pLTmFAmxF1WlW3KwWndYPgI8Q/chiaki-violet-azure-common.png',
description:
'MONMONMON is a collection from the creativity of Peelander Yellow. Each MONMONMON has unique and kind abilities that can be used to help others and play with your friends. There are secrets in each MONMONMON. We love you.',
},
});
});

test(`it can fetch multiple assets by ID with showFungible true (${endpoint.name})`, async (t) => {
// Given a minted NFT and a fungible token.
const umi = createUmi(endpoint.url);
const nftAssetId = publicKey(
'GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA'
);
const fungibleAssetId = publicKey(
'4oZjhZTiKAbuLtfCPukCgTDAcUngDUyccctpLVT9zJuP'
);

// When we fetch the assets using their IDs with showFungible true.
const assets = await umi.rpc.getAssets({
assetIds: [nftAssetId, fungibleAssetId],
displayOptions: {
showFungible: true,
},
});

// Then we expect to get both assets back.
t.is(assets.length, 2);
const fungibleAsset = assets.find(
(asset) => asset.interface === 'FungibleToken'
);
t.truthy(fungibleAsset, 'Expected to find a fungible token');
t.deepEqual(fungibleAsset?.id, fungibleAssetId);
});
});
Loading