From c853e688ae22bc3de3b64772eca0ace255665acd Mon Sep 17 00:00:00 2001 From: Nhan Phan Date: Tue, 11 Jun 2024 14:01:40 -0700 Subject: [PATCH] make tests serial --- test/das.test.ts | 185 ++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 84 deletions(-) diff --git a/test/das.test.ts b/test/das.test.ts index fd3dc61..17f74a8 100644 --- a/test/das.test.ts +++ b/test/das.test.ts @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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( @@ -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'),