From b007795528dd73f813be2542ac1d66ad08fe882c Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Sat, 30 Nov 2024 04:41:38 +0530 Subject: [PATCH] duplicate results for same assetIds in getAssets bug fixed --- das_api/src/api/api_impl.rs | 19 ++- ...cGsTKbj7FecLwxTHaodZRFwza7m7LamqDG4YjczZMj | Bin 0 -> 824 bytes ...AZ3mGuq7nCYGzUyw4MiA74ysr15EfqLpzCzX2cRVng | Bin 0 -> 824 bytes ...Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk | Bin 0 -> 224 bytes ...KKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X | Bin 0 -> 224 bytes .../tests/integration_tests/main.rs | 1 + ...ds__get_assets_with_multiple_same_ids.snap | 139 ++++++++++++++++++ .../test_get_assets_with_multiple_same_ids.rs | 42 ++++++ 8 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/2ecGsTKbj7FecLwxTHaodZRFwza7m7LamqDG4YjczZMj create mode 100644 integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/DZAZ3mGuq7nCYGzUyw4MiA74ysr15EfqLpzCzX2cRVng create mode 100644 integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk create mode 100644 integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X create mode 100644 integration_tests/tests/integration_tests/snapshots/integration_tests__test_get_assets_with_multiple_same_ids__get_assets_with_multiple_same_ids.snap create mode 100644 integration_tests/tests/integration_tests/test_get_assets_with_multiple_same_ids.rs diff --git a/das_api/src/api/api_impl.rs b/das_api/src/api/api_impl.rs index 4b55f43d8..513c8dcf2 100644 --- a/das_api/src/api/api_impl.rs +++ b/das_api/src/api/api_impl.rs @@ -23,6 +23,7 @@ use sea_orm::{sea_query::ConditionType, ConnectionTrait, DbBackend, Statement}; use crate::error::DasApiError; use crate::validation::{validate_opt_pubkey, validate_search_with_name}; use open_rpc_schema::document::OpenrpcDocument; +use std::collections::HashSet; use { crate::api::*, crate::config::Config, @@ -148,6 +149,16 @@ pub fn not_found(asset_id: &String) -> DbErr { DbErr::RecordNotFound(format!("Asset Proof for {} Not Found", asset_id)) } +pub fn remove_duplicates_asset_ids(id_bytes: Vec>) -> Vec> { + let mut hash_set = HashSet::new(); + id_bytes.into_iter().filter(|asset_id| hash_set.insert(asset_id.clone())).collect() +} + +pub fn remove_duplicates_string_ids(id: Vec) -> Vec { + let mut hash_set = HashSet::new(); + id.into_iter().filter(|id| hash_set.insert(id.clone())).collect() +} + #[document_rpc] #[async_trait] impl ApiContract for DasApi { @@ -230,9 +241,13 @@ impl ApiContract for DasApi { let options = options.unwrap_or_default(); - let assets = get_assets(&self.db_connection, id_bytes, batch_size as u64, &options).await?; + let unique_asset_ids = remove_duplicates_asset_ids(id_bytes); + + let assets = get_assets(&self.db_connection, unique_asset_ids, batch_size as u64, &options).await?; + + let filtered_string_ids = remove_duplicates_string_ids(ids); - let result: Vec> = ids.iter().map(|id| assets.get(id).cloned()).collect(); + let result: Vec> = filtered_string_ids.iter().map(|id| assets.get(id).cloned()).collect(); Ok(result) } diff --git a/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/2ecGsTKbj7FecLwxTHaodZRFwza7m7LamqDG4YjczZMj b/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/2ecGsTKbj7FecLwxTHaodZRFwza7m7LamqDG4YjczZMj new file mode 100644 index 0000000000000000000000000000000000000000..1ae41d2d6fd0535e0c662f950f965d0a9f065345 GIT binary patch literal 824 zcmY#jfB*@G90nE!4+a$=H-NzfNJap00)qsQl&IsMs?YYJjnSgZG5l-M)pn+sHn%t0 z_P;MWoys>@d5XIrb>riUHLezOgX*(c4xf$Kky9+S;O|z?Z5Q`2|Il>P0GYWZ6i6~K z{D%Sw8C4+=|9-c2)nrBxi-BP|69WUw->D5PF_(f?v9D|4c*Ike5+XQc!HAub-DzQe2W>l$f5Xmy?;7t)E$tR;-_tn3i3XnwgSbmQ`+) zSdyDvZj@D(ot>6xYL-}(R#cUknOu~bR8?+TQJ$7vWt?PYo>pj@o>Z1ol#11QnhG+4 z0+Uc6GNv#xF#ZK%hOKHQ4;vh$5AGMASa`SNMBk0Dbxi#SZCpfn9);w-`XoS8w+>;$ E0sCH>PXGV_ literal 0 HcmV?d00001 diff --git a/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/DZAZ3mGuq7nCYGzUyw4MiA74ysr15EfqLpzCzX2cRVng b/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/DZAZ3mGuq7nCYGzUyw4MiA74ysr15EfqLpzCzX2cRVng new file mode 100644 index 0000000000000000000000000000000000000000..3e817c9dc76e79d97e41f6cd5f0e75fc406e9c67 GIT binary patch literal 824 zcmY#jfB*@G90nE!4+a$=H-NzfNJap00)qsQ+|{|zujMrdr@*@x2mGX7M#Z$}G4!20 zI4ASn*)P)W={LCxQa3)nSmSCjH>f_F45zMt`HWP34f!H}Ekx zeqGD%o_R^_%&XV49_%_)7B!RI`rqd09ba$Uvt0g1MC~=tr~k`VDgX`gO-xbnNlYnL zP_{5JG5{Hk3b=q=Uq_H9LEr=sXOxr_6kF-*=O(7)05$3r8|#%8>z1b$m*^VlCFUkp z<>w`q7waYG=jvw_=jZ8z%+&+2z$OeHVhJN7Fc2A>qn;#qg(O-WI_YWjX=kxrbGNI> zomFiIEh4Y>N_V<4GBOYfX2ujoM#g`PER2kQHcR{ee3nuD+Vpfy>}tu&y6MaM!jt?? zALie@Mkal zF8?E<_L}F@|79!L?tXiCJ$2#ao2MVToqJumMrKRv+xTeniB>&dTkHNatOS{v;420s z85sUUfrN~z5Qy*IrCl|dk%1uy$OcjjY?q8#_x(C{{Iu|Uqe!-E^=Z1dPgzXjdXn{l T$?!|&X-$wCFkmD`H3I_x<*rn| literal 0 HcmV?d00001 diff --git a/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X b/integration_tests/tests/data/accounts/get_assets_with_multiple_same_ids/JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X new file mode 100644 index 0000000000000000000000000000000000000000..eee1c395303ef302b64595898fa274079985de18 GIT binary patch literal 224 zcmY#jfB*@G3cYu4Pd{`!_quY8%$C--@zLfJt$Mz;*8OK#2{JRmR}4sk z%z^+38C4+=zoJ{aYBD1OLlBS+q!_Mu>s(#FkV)?GTe%h9lb&Cm6UTREqO6&1iG!B? RvfT$Kg4BQkBQdHO7y$L = seed_accounts([ + "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "DZAZ3mGuq7nCYGzUyw4MiA74ysr15EfqLpzCzX2cRVng", + "JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X", + "2ecGsTKbj7FecLwxTHaodZRFwza7m7LamqDG4YjczZMj" + ]); + + apply_migrations_and_delete_data(setup.db.clone()).await; + index_seed_events(&setup, seeds.iter().collect_vec()).await; + + let request = r#" + { + "ids": [ + "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X", + "JEKKtnGvjiZ8GtATnMVgadHU41AuTbFkMW8oD2tdyV9X" + ] + } + "#; + + let request: api::GetAssets = serde_json::from_str(request).unwrap(); + let response = setup.das_api.get_assets(request).await.unwrap(); + insta::assert_json_snapshot!(name, response); +}