From 34a3f2a302ca93c34fe679454b4664e179bcef60 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Wed, 22 May 2024 16:12:43 +0300 Subject: [PATCH] added tests for unordered set mapper read from address --- .../storage_mapper_get_at_address.scen.json | 67 ++++++++++++++++++- .../src/storage_mapper_get_at_address.rs | 26 +++++++ .../basic-features/wasm/src/lib.rs | 7 +- 3 files changed, 97 insertions(+), 3 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json index ffa1bbb620..3076c1e82b 100644 --- a/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/storage_mapper_get_at_address.scen.json @@ -303,6 +303,71 @@ "gas": "*", "refund": "*" } + }, + { + "step": "scCall", + "id": "fill unordered set mapper", + "tx": { + "from": "address:an_account", + "to": "sc:to-be-called", + "function": "fill_unordered_set_mapper", + "arguments": [ + "10" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "contains unordered at address", + "tx": { + "from": "address:an_account", + "to": "sc:caller", + "function": "contains_unordered_at_address", + "arguments": ["5"], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "get by index at address", + "tx": { + "from": "address:an_account", + "to": "sc:caller", + "function": "get_by_index", + "arguments": [ + "5" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "5" + ], + "status": "", + "logs": "*", + "gas": "*", + "refund": "*" + } } ] -} +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/src/storage_mapper_get_at_address.rs b/contracts/feature-tests/basic-features/src/storage_mapper_get_at_address.rs index 7970619957..35ef02b905 100644 --- a/contracts/feature-tests/basic-features/src/storage_mapper_get_at_address.rs +++ b/contracts/feature-tests/basic-features/src/storage_mapper_get_at_address.rs @@ -86,6 +86,22 @@ pub trait StorageMapperGetAtAddress { mapper.values().collect() } + #[endpoint] + fn contains_unordered_at_address(&self, item: u32) -> bool { + let address = self.contract_address().get(); + let mapper: UnorderedSetMapper = + UnorderedSetMapper::new_from_address(address, StorageKey::from("unordered_set_mapper")); + mapper.contains(&item) + } + + #[endpoint] + fn get_by_index(&self, index: usize) -> u32 { + let address = self.contract_address().get(); + let mapper: UnorderedSetMapper = + UnorderedSetMapper::new_from_address(address, StorageKey::from("unordered_set_mapper")); + mapper.get_by_index(index) + } + /// Storage to be called. For testing, this contract is deployed twice, /// and this module acts both as caller and receiver #[storage_mapper("set_mapper")] @@ -94,6 +110,9 @@ pub trait StorageMapperGetAtAddress { #[storage_mapper("map_mapper")] fn map_mapper(&self) -> MapMapper; + #[storage_mapper("unordered_set_mapper")] + fn unordered_set_mapper(&self) -> UnorderedSetMapper; + #[endpoint] fn fill_set_mapper(&self, value: u32) { for item in 1u32..=value { @@ -108,4 +127,11 @@ pub trait StorageMapperGetAtAddress { self.map_mapper().insert(key, item); } } + + #[endpoint] + fn fill_unordered_set_mapper(&self, value: u32) { + for item in 1u32..=value { + self.unordered_set_mapper().insert(item); + } + } } diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index de77a1fc25..6dcb5c59be 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 386 +// Endpoints: 389 // Async Callback: 1 -// Total number of exported functions: 388 +// Total number of exported functions: 391 #![no_std] @@ -402,8 +402,11 @@ multiversx_sc_wasm_adapter::endpoints! { back_at_address => back_at_address keys_at_address => keys_at_address values_at_address => values_at_address + contains_unordered_at_address => contains_unordered_at_address + get_by_index => get_by_index fill_set_mapper => fill_set_mapper fill_map_mapper => fill_map_mapper + fill_unordered_set_mapper => fill_unordered_set_mapper ) }