From 45f72196b6b7d8716e4a84475b5fe55c6be60efc Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Sat, 30 Nov 2024 04:41:38 +0530 Subject: [PATCH] Filter duplicate asset id filters Users can pass in duplicate asset ids when calling getAssets. This remove the duplicates before processing the request. Co-authored-by: Kyle Espinola --- das_api/src/api/api_impl.rs | 4 + ...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 | 138 ++++++++++++++++++ .../test_get_assets_with_multiple_same_ids.rs | 42 ++++++ 8 files changed, 185 insertions(+) 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 9aac04b2c..43bc68db7 100644 --- a/das_api/src/api/api_impl.rs +++ b/das_api/src/api/api_impl.rs @@ -218,6 +218,10 @@ impl ApiContract for DasApi { ) -> Result>, DasApiError> { let GetAssets { ids, options } = payload; + let mut ids: Vec = ids.into_iter().collect(); + ids.sort(); + ids.dedup(); + let batch_size = ids.len(); if batch_size > 1000 { return Err(DasApiError::BatchSizeExceededError); 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); +}