mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 15:07:59 +00:00
Add try_mutate_exists to StorageDoubleMap. (#6694)
This commit is contained in:
@@ -376,7 +376,7 @@ mod tests {
|
||||
DecodeDifferent, StorageEntryMetadata, StorageMetadata, StorageEntryType,
|
||||
StorageEntryModifier, DefaultByteGetter, StorageHasher,
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
use sp_std::{marker::PhantomData, result};
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
pub trait Trait {
|
||||
@@ -629,6 +629,36 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_map_try_mutate_exists_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = DataDM;
|
||||
type TestResult = result::Result<(), &'static str>;
|
||||
|
||||
let (key1, key2) = (11, 13);
|
||||
|
||||
// mutated if `Ok`
|
||||
assert_ok!(DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = Some(1);
|
||||
Ok(())
|
||||
}));
|
||||
assert_eq!(DoubleMap::get(&key1, key2), 1);
|
||||
|
||||
// no-op if `Err`
|
||||
assert_noop!(DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = Some(2);
|
||||
Err("nah")
|
||||
}), "nah");
|
||||
|
||||
// removed if mutated to`None`
|
||||
assert_ok!(DoubleMap::try_mutate_exists(key1, key2, |v| -> TestResult {
|
||||
*v = None;
|
||||
Ok(())
|
||||
}));
|
||||
assert!(!DoubleMap::contains_key(&key1, key2));
|
||||
});
|
||||
}
|
||||
|
||||
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
|
||||
prefix: DecodeDifferent::Encode("Test"),
|
||||
entries: DecodeDifferent::Encode(
|
||||
|
||||
Reference in New Issue
Block a user