diff --git a/src/assets/CollectibleDetectionController.test.ts b/src/assets/CollectibleDetectionController.test.ts index 90ed2eb424b..0796ca5ca05 100644 --- a/src/assets/CollectibleDetectionController.test.ts +++ b/src/assets/CollectibleDetectionController.test.ts @@ -299,6 +299,7 @@ describe('CollectibleDetectionController', () => { tokenId: '2574', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }, ]); }); @@ -338,6 +339,7 @@ describe('CollectibleDetectionController', () => { standard: 'ERC721', tokenId: '2573', favorite: false, + isCurrentlyOwned: true, }, { address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD', @@ -347,6 +349,7 @@ describe('CollectibleDetectionController', () => { tokenId: '2574', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }, ]); }); @@ -448,6 +451,7 @@ describe('CollectibleDetectionController', () => { tokenId: '2574', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }; const collectibleGG2574 = { address: '0xCE7ec4B2DfB30eB6c0BB5656D33aAd6BFb4001Fc', @@ -457,6 +461,7 @@ describe('CollectibleDetectionController', () => { tokenId: '2574', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }; const collectibleII2577 = { address: '0x0B0fa4fF58D28A88d63235bd0756EDca69e49e6d', @@ -466,6 +471,7 @@ describe('CollectibleDetectionController', () => { tokenId: '2577', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }; const collectibleContractHH = { address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD', diff --git a/src/assets/CollectiblesController.test.ts b/src/assets/CollectiblesController.test.ts index a1fa96e36f5..4deabf251b2 100644 --- a/src/assets/CollectiblesController.test.ts +++ b/src/assets/CollectiblesController.test.ts @@ -218,6 +218,7 @@ describe('CollectiblesController', () => { tokenId: '1', standard: 'standard', favorite: false, + isCurrentlyOwned: true, }); expect( @@ -256,6 +257,7 @@ describe('CollectiblesController', () => { name: 'name', tokenId: '1234', favorite: false, + isCurrentlyOwned: true, }); }); @@ -282,6 +284,7 @@ describe('CollectiblesController', () => { standard: 'standard', tokenId: '1', favorite: false, + isCurrentlyOwned: true, }); await collectiblesController.addCollectible('0x01', '1', { @@ -304,6 +307,7 @@ describe('CollectiblesController', () => { tokenId: '1', standard: 'standard', favorite: false, + isCurrentlyOwned: true, }); }); @@ -352,6 +356,7 @@ describe('CollectiblesController', () => { standard: 'ERC1155', tokenId: '1', favorite: false, + isCurrentlyOwned: true, }); }); @@ -379,6 +384,7 @@ describe('CollectiblesController', () => { numberOfSales: 1, standard: 'ERC1155', favorite: false, + isCurrentlyOwned: true, }); }); @@ -406,6 +412,7 @@ describe('CollectiblesController', () => { imageOriginal: 'Kudos url', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }); expect( @@ -445,6 +452,7 @@ describe('CollectiblesController', () => { tokenId: '1203', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }); expect( @@ -504,6 +512,7 @@ describe('CollectiblesController', () => { name: 'name', tokenId: '1234', favorite: false, + isCurrentlyOwned: true, }); }); @@ -553,6 +562,7 @@ describe('CollectiblesController', () => { standard: 'ERC721', tokenId: '1203', favorite: false, + isCurrentlyOwned: true, }, ]); @@ -650,6 +660,7 @@ describe('CollectiblesController', () => { description: 'description', standard: 'ERC721', favorite: false, + isCurrentlyOwned: true, }); }); }); @@ -683,6 +694,7 @@ describe('CollectiblesController', () => { name: 'name', tokenId: '1234', favorite: false, + isCurrentlyOwned: true, }); }); @@ -778,6 +790,7 @@ describe('CollectiblesController', () => { name: 'name', tokenId: '4321', favorite: false, + isCurrentlyOwned: true, }); }); @@ -829,6 +842,7 @@ describe('CollectiblesController', () => { name: 'name', tokenId: '4321', favorite: false, + isCurrentlyOwned: true, }); }); }); @@ -1056,6 +1070,7 @@ describe('CollectiblesController', () => { address: ERC721_DEPRESSIONIST_ADDRESS, tokenId: ERC721_DEPRESSIONIST_ID, favorite: true, + isCurrentlyOwned: true, }), ); @@ -1107,6 +1122,7 @@ describe('CollectiblesController', () => { address: ERC721_DEPRESSIONIST_ADDRESS, tokenId: ERC721_DEPRESSIONIST_ID, favorite: false, + isCurrentlyOwned: true, }), ); @@ -1114,5 +1130,89 @@ describe('CollectiblesController', () => { collectiblesController.state.allCollectibles[selectedAddress][chainId], ).toHaveLength(1); }); + + describe('checkAndUpdateCollectiblesOwnershipStatus', () => { + it('should check whether collectibles for the current selectedAddress/chainId combination are still owned by the selectedAddress and update the isCurrentlyOwned value to false when collectible is not still owned', async () => { + sandbox.restore(); + sandbox + .stub(collectiblesController, 'isCollectibleOwner' as any) + .returns(false); + + const { selectedAddress, chainId } = collectiblesController.config; + await collectiblesController.addCollectible('0x02', '1', { + name: 'name', + image: 'image', + description: 'description', + standard: 'standard', + favorite: false, + }); + + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(true); + + await collectiblesController.checkAndUpdateCollectiblesOwnershipStatus(); + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(false); + }); + }); + + it('should check whether collectibles for the current selectedAddress/chainId combination are still owned by the selectedAddress and leave/set the isCurrentlyOwned value to true when collectible is still owned', async () => { + const { selectedAddress, chainId } = collectiblesController.config; + await collectiblesController.addCollectible('0x02', '1', { + name: 'name', + image: 'image', + description: 'description', + standard: 'standard', + favorite: false, + }); + + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(true); + + await collectiblesController.checkAndUpdateCollectiblesOwnershipStatus(); + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(true); + }); + + it('should check whether collectibles for the current selectedAddress/chainId combination are still owned by the selectedAddress and leave the isCurrentlyOwned value as is when collectible ownership check fails', async () => { + sandbox.restore(); + sandbox + .stub(collectiblesController, 'isCollectibleOwner' as any) + .throws(new Error('Unable to verify ownership')); + + const { selectedAddress, chainId } = collectiblesController.config; + await collectiblesController.addCollectible('0x02', '1', { + name: 'name', + image: 'image', + description: 'description', + standard: 'standard', + favorite: false, + }); + + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(true); + + await collectiblesController.checkAndUpdateCollectiblesOwnershipStatus(); + expect( + collectiblesController.state.allCollectibles[selectedAddress][ + chainId + ][0].isCurrentlyOwned, + ).toBe(true); + }); }); });