Add mutate_exists to StorageDoubleMap. (#6704)

This commit is contained in:
Shaopeng Wang
2020-08-04 20:02:24 +12:00
committed by GitHub
parent c7d6a11460
commit 3a853d4dde
3 changed files with 33 additions and 0 deletions
+17
View File
@@ -629,6 +629,23 @@ mod tests {
});
}
#[test]
fn double_map_mutate_exists_should_work() {
new_test_ext().execute_with(|| {
type DoubleMap = DataDM;
let (key1, key2) = (11, 13);
// mutated
DoubleMap::mutate_exists(key1, key2, |v| *v = Some(1));
assert_eq!(DoubleMap::get(&key1, key2), 1);
// removed if mutated to `None`
DoubleMap::mutate_exists(key1, key2, |v| *v = None);
assert!(!DoubleMap::contains_key(&key1, key2));
});
}
#[test]
fn double_map_try_mutate_exists_should_work() {
new_test_ext().execute_with(|| {