Skip to content

Commit

Permalink
make tests serial
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Jun 11, 2024
1 parent d01c5f5 commit c853e68
Showing 1 changed file with 101 additions and 84 deletions.
185 changes: 101 additions & 84 deletions test/das.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
dasTestCollection2PubKey,
} from './_expectedData';

test('das: it can search assets', async (t) => {
test.serial('das: it can search assets', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

Expand All @@ -46,7 +46,7 @@ test('das: it can search assets', async (t) => {
t.like(asset, dasTestAsset1);
});

test('das: it can fetch assets by owner', async (t) => {
test.serial('das: it can fetch assets by owner', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

Expand All @@ -61,7 +61,7 @@ test('das: it can fetch assets by owner', async (t) => {
t.like(asset, dasTestAsset1);
});

test('das: it can fetch assets by authority', async (t) => {
test.serial('das: it can fetch assets by authority', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

Expand All @@ -76,22 +76,25 @@ test('das: it can fetch assets by authority', async (t) => {
t.like(asset, dasTestAsset1);
});

test('das: it can fetch assets by authority if authority is not owner', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

// Then assets are fetched via the MPL Core DAS helper
const assets = await das.getAssetsByAuthority(umi, {
authority: dasTestAsset2UpdateAuthority,
skipDerivePlugins: true,
});

// The fetched assets structure is the same as with the MPL Core fetchAssetV1
const asset = assets.find((a) => a.publicKey === dasTestAsset2PubKey);
t.like(asset, dasTestAsset2);
});

test('das: it can fetch assets by collection', async (t) => {
test.serial(
'das: it can fetch assets by authority if authority is not owner',
async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

// Then assets are fetched via the MPL Core DAS helper
const assets = await das.getAssetsByAuthority(umi, {
authority: dasTestAsset2UpdateAuthority,
skipDerivePlugins: true,
});

// The fetched assets structure is the same as with the MPL Core fetchAssetV1
const asset = assets.find((a) => a.publicKey === dasTestAsset2PubKey);
t.like(asset, dasTestAsset2);
}
);

test.serial('das: it can fetch assets by collection', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

Expand All @@ -108,7 +111,7 @@ test('das: it can fetch assets by collection', async (t) => {
t.like(asset, dasTestAssetInCollection);
});

test('das: it can fetch collections by update authority', async (t) => {
test.serial('das: it can fetch collections by update authority', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

Expand All @@ -125,72 +128,86 @@ test('das: it can fetch collections by update authority', async (t) => {
t.like(collection, dasTestCollection1);
});

test('das: it can fetch collections by update authority if update authority is not owner', async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

// Then collections are fetched via the MPL Core DAS helper
const collections = await das.getCollectionsByUpdateAuthority(umi, {
updateAuthority: publicKey(dasTestCollection2UpdateAuthority),
skipDerivePlugins: true,
});

// One of the fetched collections structure is the same as with the MPL Core fetchCollectionV1
const collection = collections.find(
(a) => a.publicKey === dasTestCollection2PubKey
);
t.like(collection, dasTestCollection2);
});

test('das: it can convert a DAS asset with the edition plugin to the MPL Core asset structure', async (t) => {
// Given an Umi instance with DAS API and an asset with the edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const assetPubKey = publicKey('94tbAopaajgjRndvvK31TBqNTkNbJdzifwW4ec7iqpYh');

// Then the asset data parsed from DAS
const assets = await das.getAssetsByOwner(umi, {
owner: publicKey('EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'),
skipDerivePlugins: true,
});
const assetDas = assets.find((a) => a.publicKey === assetPubKey) ?? {};
prepareAssetForComparison(assetDas as AssetV1, false);

// Then the asset data fetched via fetchAssetV1
const assetMplCore = await fetchAssetV1(umi, assetPubKey);
prepareAssetForComparison(assetMplCore);

// Assets data structure is the same from both sources
t.like(assetDas, assetMplCore);
});

test('das: it can convert a DAS collection with the master edition plugin to the MPL Core collection structure', async (t) => {
// Given an Umi instance with DAS API and a collection with the master edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const collectionPubKey = publicKey(
'D6kHt7XgMLtqBWSSf7QNc6YijQn8vqBwHb2ZF3GHnv7P'
);

// Then the collection data parsed from DAS
const collections = await das.getCollectionsByUpdateAuthority(umi, {
updateAuthority: publicKey('EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'),
skipDerivePlugins: true,
});
const collectionDas =
collections.find((a) => a.publicKey === collectionPubKey) ?? {};
prepareAssetForComparison(collectionDas as CollectionV1, false);

// Then the collection data fetched via fetchCollectionV1
const collectionMplCore = await fetchCollectionV1(umi, collectionPubKey);
prepareAssetForComparison(collectionMplCore);

// Collections data structure is the same from both sources
t.like(collectionDas, collectionMplCore);
});

test('das: it can fetch asset with oracle', async (t) => {
test.serial(
'das: it can fetch collections by update authority if update authority is not owner',
async (t) => {
// Given an Umi instance with DAS API
const umi = createUmiWithDas(DAS_API_ENDPOINT);

// Then collections are fetched via the MPL Core DAS helper
const collections = await das.getCollectionsByUpdateAuthority(umi, {
updateAuthority: publicKey(dasTestCollection2UpdateAuthority),
skipDerivePlugins: true,
});

// One of the fetched collections structure is the same as with the MPL Core fetchCollectionV1
const collection = collections.find(
(a) => a.publicKey === dasTestCollection2PubKey
);
t.like(collection, dasTestCollection2);
}
);

test.serial(
'das: it can convert a DAS asset with the edition plugin to the MPL Core asset structure',
async (t) => {
// Given an Umi instance with DAS API and an asset with the edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const assetPubKey = publicKey(
'94tbAopaajgjRndvvK31TBqNTkNbJdzifwW4ec7iqpYh'
);

// Then the asset data parsed from DAS
const assets = await das.getAssetsByOwner(umi, {
owner: publicKey('EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'),
skipDerivePlugins: true,
});
const assetDas = assets.find((a) => a.publicKey === assetPubKey) ?? {};
prepareAssetForComparison(assetDas as AssetV1, false);

// Then the asset data fetched via fetchAssetV1
const assetMplCore = await fetchAssetV1(umi, assetPubKey);
prepareAssetForComparison(assetMplCore);

// Assets data structure is the same from both sources
t.like(assetDas, assetMplCore);
}
);

test.serial(
'das: it can convert a DAS collection with the master edition plugin to the MPL Core collection structure',
async (t) => {
// Given an Umi instance with DAS API and a collection with the master edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const collectionPubKey = publicKey(
'D6kHt7XgMLtqBWSSf7QNc6YijQn8vqBwHb2ZF3GHnv7P'
);

// Then the collection data parsed from DAS
const collections = await das.getCollectionsByUpdateAuthority(umi, {
updateAuthority: publicKey(
'EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'
),
skipDerivePlugins: true,
});
const collectionDas =
collections.find((a) => a.publicKey === collectionPubKey) ?? {};
prepareAssetForComparison(collectionDas as CollectionV1, false);

// Then the collection data fetched via fetchCollectionV1
const collectionMplCore = await fetchCollectionV1(umi, collectionPubKey);
prepareAssetForComparison(collectionMplCore);

// Collections data structure is the same from both sources
t.like(collectionDas, collectionMplCore);
}
);

test.serial('das: it can fetch asset with oracle', async (t) => {
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const assets = await das.searchAssets(umi, {
owner: publicKey('APrZTeVysBJqAznfLXS71NAzjr2fCVTSF1A66MeErzM7'),
skipDerivePlugins: true,
});

const asset = assets.find(
Expand All @@ -204,7 +221,7 @@ test('das: it can fetch asset with oracle', async (t) => {
t.like(asset, mplCoreAsset);
});

test('das: it can fetch derived asset', async (t) => {
test.serial('das: it can fetch derived asset', async (t) => {
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const assets = await das.getAssetsByCollection(umi, {
collection: publicKey('4waGHv3uwEvvZ35VNh8xZrVAkuDr6tEx8YnCvxYN4A7A'),
Expand Down

0 comments on commit c853e68

Please sign in to comment.