From 15f7c8aeee4ea0e3fc7c1d2cd406097c196a290c Mon Sep 17 00:00:00 2001 From: klambert-ledger Date: Wed, 22 Sep 2021 16:15:37 +0200 Subject: [PATCH] Update ugly integration test for NFTs --- src/families/ethereum/test-specifics.ts | 52 ++++++++++++++++++++----- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/src/families/ethereum/test-specifics.ts b/src/families/ethereum/test-specifics.ts index 049bf27482..eb3d7cef7c 100644 --- a/src/families/ethereum/test-specifics.ts +++ b/src/families/ethereum/test-specifics.ts @@ -59,17 +59,51 @@ export default (): void => { .pipe(reduce((a, f) => f(a), account)) .toPromise(); - const openSeaRes = await axios - .get( - `https://api.opensea.io/api/v1/assets?limit=50&owner=${nftAccount.freshAddress}` - ) - .then(({ data }) => - data?.assets.filter( - (a) => a?.asset_contract?.schema_name === "ERC721" - ) + const getPaginatedOpenSeaRes = async (assets = []) => { + const { data } = await axios.get( + `https://api.opensea.io/api/v1/assets?offset=${assets.length}&limit=50&owner=${nftAccount.freshAddress}` ); - expect(synced.NFT?.length).toBe(openSeaRes.length); + assets.push(...((data?.assets ?? []) as [])); + + if (data?.assets?.length === 50) { + await getPaginatedOpenSeaRes(assets); + } + + return assets; + }; + + const openSeaList: any = await getPaginatedOpenSeaRes().then( + (assets: any) => + // removes lazy minting from open sea + assets + ?.filter( + (a) => + !( + a?.is_presale && + a?.num_sales === 0 && + a?.creator?.address === nftAccount.freshAddress + ) + ) + .map((n) => ({ + contract: n.asset_contract.address, + tokenId: n.token_id, + })) + ); + + const ourList = + synced.NFT?.map((n) => ({ + contract: n.collection.contract, + tokenId: n.tokenId, + })) || []; + + expect(ourList?.length).toEqual(openSeaList?.length); + expect( + _.isEqual( + _.sortBy(openSeaList, ["contract", "tokenId"]), + _.sortBy(ourList, ["contract", "tokenId"]) + ) + ).toBe(true); } ); });