From 9d5061f22dcb826fd6cf724a85624bd1e6d06e19 Mon Sep 17 00:00:00 2001 From: Nick von Pentz Date: Wed, 23 Oct 2024 12:56:25 -0400 Subject: [PATCH] wip --- .../browser/simple_hash_client.cc | 2 +- .../browser/simple_hash_client_unittest.cc | 68 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/components/brave_wallet/browser/simple_hash_client.cc b/components/brave_wallet/browser/simple_hash_client.cc index 2b06e5ee5e30..ae261ef2042d 100644 --- a/components/brave_wallet/browser/simple_hash_client.cc +++ b/components/brave_wallet/browser/simple_hash_client.cc @@ -426,7 +426,7 @@ void SimpleHashClient::OnGetNftsForMetadatas( for (const auto& nft_identifier : nft_identifiers) { auto it = metadatas->find(nft_identifier); if (it != metadatas->end()) { - nft_metadatas.push_back(std::move(it->second)); + nft_metadatas.push_back(it->second.Clone()); } } diff --git a/components/brave_wallet/browser/simple_hash_client_unittest.cc b/components/brave_wallet/browser/simple_hash_client_unittest.cc index 3aa9440317df..4b4a9bc9b82d 100644 --- a/components/brave_wallet/browser/simple_hash_client_unittest.cc +++ b/components/brave_wallet/browser/simple_hash_client_unittest.cc @@ -1772,7 +1772,7 @@ TEST_F(SimpleHashClientUnitTest, GetNftMetadatas) { "value": "Red" }, { - "trait_type": "Size", + "trait_type": "Size", "value": "Small" } ] @@ -1875,6 +1875,72 @@ TEST_F(SimpleHashClientUnitTest, GetNftMetadatas) { SetInterceptors(responses); TestGetNftMetadatas(mojom::CoinType::SOL, std::move(nft_identifiers), expected_metadatas); + + LOG(ERROR) << "BEFORE RELEVANT TESTS"; + // Test case for duplicate NFT identifiers + nft_identifiers = std::vector(); + expected_metadatas = std::vector(); + + // Add two identical NFT identifiers + auto duplicate_nft_identifier1 = mojom::NftIdentifier::New(); + duplicate_nft_identifier1->chain_id = mojom::kSolanaMainnet; + duplicate_nft_identifier1->contract_address = + "2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR"; + duplicate_nft_identifier1->token_id = ""; + nft_identifiers.push_back(std::move(duplicate_nft_identifier1)); + + auto duplicate_nft_identifier2 = mojom::NftIdentifier::New(); + duplicate_nft_identifier2->chain_id = mojom::kSolanaMainnet; + duplicate_nft_identifier2->contract_address = + "2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR"; + duplicate_nft_identifier2->token_id = ""; + nft_identifiers.push_back(std::move(duplicate_nft_identifier2)); + + // Create JSON response for duplicate NFTs (response will contain only one entry) + std::string duplicate_json = R"({ + "nfts": [ + { + "nft_id": "solana.2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR", + "chain": "solana", + "contract_address": "2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR", + "token_id": null, + "name": "Common Water Warrior #19", + "description": "A true gladiator", + "image_url": "https://cdn.simplehash.com/assets/168e33bbf5276f717d8d190810ab93b4992ac8681054c1811f8248fe7636b54b.png", + "extra_metadata": { + "metadata_original_url": "https://nft.dragonwar.io/avatars/dragons/CWTWRDR_1.json" + } + } + ] + })"; + + // Set up expected metadata for the duplicate NFT + auto duplicate_metadata = mojom::NftMetadata::New(); + duplicate_metadata->name = "Common Water Warrior #19"; + duplicate_metadata->description = "A true gladiator"; + duplicate_metadata->image = + "https://simplehash.wallet-cdn.brave.com/assets/" + "168e33bbf5276f717d8d190810ab93b4992ac8681054c1811f8248fe7636b54b.png"; + duplicate_metadata->image_data = ""; + duplicate_metadata->external_url = ""; + duplicate_metadata->background_color = ""; + duplicate_metadata->animation_url = ""; + duplicate_metadata->youtube_url = ""; + + // Add the same metadata twice since we expect the API to return the same data for both requests + expected_metadatas.push_back(duplicate_metadata.Clone()); + expected_metadatas.push_back(std::move(duplicate_metadata)); + + // Set up the response interceptor for the duplicate NFT request + responses.clear(); + responses[GURL( + "https://simplehash.wallet.brave.com/api/v0/nfts/" + "assets?nft_ids=solana.2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR%" + "2Csolana.2iZBbRGnLVEEZH6JDsaNsTo66s2uxx7DTchVWKU8oisR")] = duplicate_json; + + SetInterceptors(responses); + TestGetNftMetadatas(mojom::CoinType::SOL, std::move(nft_identifiers), + expected_metadatas); } TEST_F(SimpleHashClientUnitTest, GetNftBalances) {