mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-16 02:35:44 +00:00
fbd2ac8f3b
* session: runtime api for generating session membership proofs * grandpa: add runtime api for creating equivocation report txs * grandpa: submit signed equivocation report transactions * grandpa: use proper equivocation report type * grandpa: report equivocations * grandpa: validate equivocation proof * grandpa: update to finality-grandpa 0.9.1 * grandpa: fix encoding of session membership proof * grandpa: initialize set id session mapping for genesis session * grandpa: fix bug in set_id session validation * fix compilation * cleanup from merge conflicts * cleanup crate tomls * grandpa: refactor equivocation handling to separate trait * node-template: fix compilation * fix test compilation * bump finality-grandpa to v0.10.2 * rpc: fix runtime version test * CHERRY-PICK #4200: Add documentation to SubmitSignedTransaction and actually make it work Squashed commit of the following: commit 4f2cb0b1c588a06f2f3b478bb4b28b5cb29d54b9 Author: Tomasz Drwięga <tomasz@parity.io> Date: Tue Dec 3 16:29:33 2019 +0100 Split the method to avoid confusing type error message. commit c5bf24eeaaf902add89ed1b046b22c4a4aaeb2cd Author: Tomasz Drwięga <tomasz@parity.io> Date: Tue Dec 3 16:19:55 2019 +0100 Make accounts optional, fix logic. commit 97db1ef556e023cf6847e5ffdb036c0e3ea6fb0a Author: Tomasz Drwięga <tomasz@parity.io> Date: Tue Dec 3 10:06:20 2019 +0100 Remove warning. commit 535f5c116d1a2e826eaf90c3f7e6798e443d61d8 Merge: 5162572170f1a5f651Author: Tomasz Drwięga <tomasz@parity.io> Date: Tue Dec 3 07:08:05 2019 +0100 Merge branch 'master' into td-signed-transactions commit 516257217bac89fcebd083712f4ea68b7b23b55a Merge: ac98248c62e68c80c2Author: Tomasz Drwięga <tomasz@parity.io> Date: Mon Dec 2 13:57:25 2019 +0100 Merge branch 'master' into td-signed-transactions commit ac98248c6c56cff381130645a82a13d29933cf83 Author: Tomasz Drwięga <tomasz@parity.io> Date: Mon Nov 25 17:34:52 2019 +0100 Forgotten import. commit 67a3c19031506c28e31c6bc4a90fff62d467dd58 Author: Tomasz Drwięga <tomasz@parity.io> Date: Mon Nov 25 17:32:10 2019 +0100 Fix naming and bounds. commit 93e768ea9df97a4629fca1f9bc4b108fdb33f876 Author: Tomasz Drwięga <tomasz@parity.io> Date: Mon Nov 25 17:01:05 2019 +0100 Add documentation to signed transactions and actually make them work. * grandpa: skip block initialization on report submission method * primitives: allow transaction pool access by default for offchain calls * grandpa: unused parameters * grandpa: remove unused method * grandpa: enable equivocation reporting * grandpa: add workaround for parameter encoding * grandpa: fix localized_payload calls in tests * fix submit_report_equivocation_extrinsic in runtimes * node: fix submit transaction test compilation * node: bump spec_version * rpc: fix api version test * grandpa: allow custom equivocation offence type * grandpa: add test for authorities::next_change_height * grandpa: cleanup report_equivocation function * node: move reporting app crypto to node-primitives * grandpa: move equivocation traits to own module * grandpa: rename app-crypto crate import * grandpa: export equivocation types * node: bump spec_version * grandpa: rename EquivocationReport to EquivocationProof * grandpa: add missing docs to primitives * grandpa: add missing docs to equivocation * node: fix compilation * grandpa: add missing docs to pallet * node: bump spec_version * fix whitespace * grandpa: return error on offence reporting * grandpa: expose session and validator count in proofs through traits * grandpa: use strong key in module KeyOwnerProofSystem * grandpa: move key ownership proof to grandpa runtime api * grandpa: remove unnecessary cloning when checking equivocation proof * grandpa: make report_equivocation a method in Environment * support: implement KeyOwnerProofSystem for () * grandpa: move KeyOwnerProofSystem to module trait * test-utils: fix runtime compilation * grandpa: fix test compilation * grandpa: fix test compilation after merge * grandpa: simplify transaction submission types * grandpa: validate equivocation report in signed extension * client: fix test * node: use ValidateEquivocationReport signed extension * grandpa: expose key ownership proof under opaque type * grandpa: better docs on key ownership proofs * grandpa: add note about signed extension * grandpa: add ValidateEquivocationReport::new * grandpa: remove skip_initialize_block from runtime api * grandpa: use new offchain transaction submission API * grandpa: take set_id in generate_key_ownership_proof * grandpa: update to finality-grandpa v0.12.2 * grandpa: cleanup usages of AuthoritySet::current * grandpa: fix test * grandpa: add mocking utilities for equivocation reporting * grandpa: add test for equivocation reporting * grandpa: move SetIdSession initialization * grandpa: add more tests * node: enable historical session manager * node: bump spec_version * node: use strong key types in KeyOwnerProofSystem definitions * grandpa: export GrandpaEquivocationOffence type
638 lines
18 KiB
Rust
638 lines
18 KiB
Rust
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Support code for the runtime.
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
/// Export ourself as `frame_support` to make tests happy.
|
|
extern crate self as frame_support;
|
|
|
|
#[macro_use]
|
|
extern crate bitmask;
|
|
|
|
#[doc(hidden)]
|
|
pub use sp_tracing;
|
|
|
|
#[cfg(feature = "std")]
|
|
pub use serde;
|
|
#[doc(hidden)]
|
|
pub use sp_std;
|
|
#[doc(hidden)]
|
|
pub use codec;
|
|
use codec::{Decode, Encode};
|
|
#[cfg(feature = "std")]
|
|
#[doc(hidden)]
|
|
pub use once_cell;
|
|
#[doc(hidden)]
|
|
pub use paste;
|
|
#[cfg(feature = "std")]
|
|
#[doc(hidden)]
|
|
pub use sp_state_machine::BasicExternalities;
|
|
#[doc(hidden)]
|
|
pub use sp_io::storage::root as storage_root;
|
|
#[doc(hidden)]
|
|
pub use sp_runtime::RuntimeDebug;
|
|
|
|
#[macro_use]
|
|
pub mod debug;
|
|
#[macro_use]
|
|
pub mod dispatch;
|
|
pub mod storage;
|
|
mod hash;
|
|
#[macro_use]
|
|
pub mod event;
|
|
#[macro_use]
|
|
mod origin;
|
|
#[macro_use]
|
|
pub mod metadata;
|
|
#[macro_use]
|
|
pub mod inherent;
|
|
#[macro_use]
|
|
pub mod unsigned;
|
|
#[macro_use]
|
|
pub mod error;
|
|
pub mod traits;
|
|
pub mod weights;
|
|
|
|
pub use self::hash::{
|
|
Twox256, Twox128, Blake2_256, Blake2_128, Identity, Twox64Concat, Blake2_128Concat, Hashable,
|
|
StorageHasher, ReversibleStorageHasher
|
|
};
|
|
pub use self::storage::{
|
|
StorageValue, StorageMap, StorageDoubleMap, StoragePrefixedMap, IterableStorageMap,
|
|
IterableStorageDoubleMap, migration
|
|
};
|
|
pub use self::dispatch::{Parameter, Callable, IsSubType};
|
|
pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable};
|
|
|
|
/// A type that cannot be instantiated.
|
|
#[derive(Debug)]
|
|
pub enum Never {}
|
|
|
|
/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to
|
|
/// how you would declare a `const`:
|
|
///
|
|
/// ```no_compile
|
|
/// parameter_types! {
|
|
/// pub const Argument: u64 = 42;
|
|
/// }
|
|
/// trait Config {
|
|
/// type Parameter: Get<u64>;
|
|
/// }
|
|
/// struct Runtime;
|
|
/// impl Config for Runtime {
|
|
/// type Parameter = Argument;
|
|
/// }
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! parameter_types {
|
|
(
|
|
$( #[ $attr:meta ] )*
|
|
$vis:vis const $name:ident: $type:ty = $value:expr;
|
|
$( $rest:tt )*
|
|
) => (
|
|
$( #[ $attr ] )*
|
|
$vis struct $name;
|
|
$crate::parameter_types!{IMPL $name , $type , $value}
|
|
$crate::parameter_types!{ $( $rest )* }
|
|
);
|
|
() => ();
|
|
(IMPL $name:ident , $type:ty , $value:expr) => {
|
|
impl $name {
|
|
pub fn get() -> $type {
|
|
$value
|
|
}
|
|
}
|
|
impl<I: From<$type>> $crate::traits::Get<I> for $name {
|
|
fn get() -> I {
|
|
I::from($value)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Macro for easily creating a new implementation of both the `Get` and `Contains` traits. Use
|
|
/// exactly as with `parameter_types`, only the type must be `Ord`.
|
|
#[macro_export]
|
|
macro_rules! ord_parameter_types {
|
|
(
|
|
$( #[ $attr:meta ] )*
|
|
$vis:vis const $name:ident: $type:ty = $value:expr;
|
|
$( $rest:tt )*
|
|
) => (
|
|
$( #[ $attr ] )*
|
|
$vis struct $name;
|
|
$crate::parameter_types!{IMPL $name , $type , $value}
|
|
$crate::ord_parameter_types!{IMPL $name , $type , $value}
|
|
$crate::ord_parameter_types!{ $( $rest )* }
|
|
);
|
|
() => ();
|
|
(IMPL $name:ident , $type:ty , $value:expr) => {
|
|
impl $crate::traits::Contains<$type> for $name {
|
|
fn contains(t: &$type) -> bool { &$value == t }
|
|
fn sorted_members() -> $crate::sp_std::prelude::Vec<$type> { vec![$value] }
|
|
fn count() -> usize { 1 }
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
fn add(_: &$type) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[doc(inline)]
|
|
pub use frame_support_procedural::{decl_storage, construct_runtime};
|
|
|
|
/// Return Err of the expression: `return Err($expression);`.
|
|
///
|
|
/// Used as `fail!(expression)`.
|
|
#[macro_export]
|
|
macro_rules! fail {
|
|
( $y:expr ) => {{
|
|
return Err($y.into());
|
|
}}
|
|
}
|
|
|
|
/// Evaluate `$x:expr` and if not true return `Err($y:expr)`.
|
|
///
|
|
/// Used as `ensure!(expression_to_ensure, expression_to_return_on_false)`.
|
|
#[macro_export]
|
|
macro_rules! ensure {
|
|
( $x:expr, $y:expr $(,)? ) => {{
|
|
if !$x {
|
|
$crate::fail!($y);
|
|
}
|
|
}}
|
|
}
|
|
|
|
/// Evaluate an expression, assert it returns an expected `Err` value and that
|
|
/// runtime storage has not been mutated (i.e. expression is a no-operation).
|
|
///
|
|
/// Used as `assert_noop(expression_to_assert, expected_error_expression)`.
|
|
#[macro_export]
|
|
#[cfg(feature = "std")]
|
|
macro_rules! assert_noop {
|
|
(
|
|
$x:expr,
|
|
$y:expr $(,)?
|
|
) => {
|
|
let h = $crate::storage_root();
|
|
$crate::assert_err!($x, $y);
|
|
assert_eq!(h, $crate::storage_root());
|
|
}
|
|
}
|
|
|
|
/// Assert an expression returns an error specified.
|
|
///
|
|
/// Used as `assert_err!(expression_to_assert, expected_error_expression)`
|
|
#[macro_export]
|
|
#[cfg(feature = "std")]
|
|
macro_rules! assert_err {
|
|
( $x:expr , $y:expr $(,)? ) => {
|
|
assert_eq!($x, Err($y.into()));
|
|
}
|
|
}
|
|
|
|
/// Assert an expression returns an error specified.
|
|
///
|
|
/// This can be used on`DispatchResultWithPostInfo` when the post info should
|
|
/// be ignored.
|
|
#[macro_export]
|
|
#[cfg(feature = "std")]
|
|
macro_rules! assert_err_ignore_postinfo {
|
|
( $x:expr , $y:expr $(,)? ) => {
|
|
assert_err!($x.map(|_| ()).map_err(|e| e.error), $y);
|
|
}
|
|
}
|
|
|
|
/// Panic if an expression doesn't evaluate to `Ok`.
|
|
///
|
|
/// Used as `assert_ok!(expression_to_assert, expected_ok_expression)`,
|
|
/// or `assert_ok!(expression_to_assert)` which would assert against `Ok(())`.
|
|
#[macro_export]
|
|
#[cfg(feature = "std")]
|
|
macro_rules! assert_ok {
|
|
( $x:expr $(,)? ) => {
|
|
let is = $x;
|
|
match is {
|
|
Ok(_) => (),
|
|
_ => assert!(false, "Expected Ok(_). Got {:#?}", is),
|
|
}
|
|
};
|
|
( $x:expr, $y:expr $(,)? ) => {
|
|
assert_eq!($x, Ok($y));
|
|
}
|
|
}
|
|
|
|
/// The void type - it cannot exist.
|
|
// Oh rust, you crack me up...
|
|
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug)]
|
|
pub enum Void {}
|
|
|
|
#[cfg(feature = "std")]
|
|
#[doc(hidden)]
|
|
pub use serde::{Serialize, Deserialize};
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use codec::{Codec, EncodeLike};
|
|
use frame_metadata::{
|
|
DecodeDifferent, StorageEntryMetadata, StorageMetadata, StorageEntryType,
|
|
StorageEntryModifier, DefaultByteGetter, StorageHasher,
|
|
};
|
|
use sp_std::marker::PhantomData;
|
|
|
|
pub trait Trait {
|
|
type BlockNumber: Codec + EncodeLike + Default;
|
|
type Origin;
|
|
}
|
|
|
|
mod module {
|
|
#![allow(dead_code)]
|
|
|
|
use super::Trait;
|
|
|
|
decl_module! {
|
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
|
|
}
|
|
}
|
|
use self::module::Module;
|
|
|
|
decl_storage! {
|
|
trait Store for Module<T: Trait> as Test {
|
|
pub Data get(fn data) build(|_| vec![(15u32, 42u64)]):
|
|
map hasher(twox_64_concat) u32 => u64;
|
|
pub OptionLinkedMap: map hasher(blake2_128_concat) u32 => Option<u32>;
|
|
pub GenericData get(fn generic_data):
|
|
map hasher(identity) T::BlockNumber => T::BlockNumber;
|
|
pub GenericData2 get(fn generic_data2):
|
|
map hasher(blake2_128_concat) T::BlockNumber => Option<T::BlockNumber>;
|
|
pub DataDM config(test_config) build(|_| vec![(15u32, 16u32, 42u64)]):
|
|
double_map hasher(twox_64_concat) u32, hasher(blake2_128_concat) u32 => u64;
|
|
pub GenericDataDM:
|
|
double_map hasher(blake2_128_concat) T::BlockNumber, hasher(identity) T::BlockNumber
|
|
=> T::BlockNumber;
|
|
pub GenericData2DM:
|
|
double_map hasher(blake2_128_concat) T::BlockNumber, hasher(twox_64_concat) T::BlockNumber
|
|
=> Option<T::BlockNumber>;
|
|
pub AppendableDM:
|
|
double_map hasher(blake2_128_concat) u32, hasher(blake2_128_concat) T::BlockNumber => Vec<u32>;
|
|
}
|
|
}
|
|
|
|
struct Test;
|
|
impl Trait for Test {
|
|
type BlockNumber = u32;
|
|
type Origin = u32;
|
|
}
|
|
|
|
fn new_test_ext() -> sp_io::TestExternalities {
|
|
GenesisConfig::default().build_storage().unwrap().into()
|
|
}
|
|
|
|
type Map = Data;
|
|
|
|
trait Sorted { fn sorted(self) -> Self; }
|
|
impl<T: Ord> Sorted for Vec<T> {
|
|
fn sorted(mut self) -> Self {
|
|
self.sort();
|
|
self
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn map_issue_3318() {
|
|
new_test_ext().execute_with(|| {
|
|
OptionLinkedMap::insert(1, 1);
|
|
assert_eq!(OptionLinkedMap::get(1), Some(1));
|
|
OptionLinkedMap::insert(1, 2);
|
|
assert_eq!(OptionLinkedMap::get(1), Some(2));
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn map_swap_works() {
|
|
new_test_ext().execute_with(|| {
|
|
OptionLinkedMap::insert(0, 0);
|
|
OptionLinkedMap::insert(1, 1);
|
|
OptionLinkedMap::insert(2, 2);
|
|
OptionLinkedMap::insert(3, 3);
|
|
|
|
let collect = || OptionLinkedMap::iter().collect::<Vec<_>>().sorted();
|
|
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
|
|
|
// Two existing
|
|
OptionLinkedMap::swap(1, 2);
|
|
assert_eq!(collect(), vec![(0, 0), (1, 2), (2, 1), (3, 3)]);
|
|
|
|
// Back to normal
|
|
OptionLinkedMap::swap(2, 1);
|
|
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
|
|
|
// Left existing
|
|
OptionLinkedMap::swap(2, 5);
|
|
assert_eq!(collect(), vec![(0, 0), (1, 1), (3, 3), (5, 2)]);
|
|
|
|
// Right existing
|
|
OptionLinkedMap::swap(5, 2);
|
|
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn double_map_swap_works() {
|
|
new_test_ext().execute_with(|| {
|
|
DataDM::insert(0, 1, 1);
|
|
DataDM::insert(1, 0, 2);
|
|
DataDM::insert(1, 1, 3);
|
|
|
|
let get_all = || vec![
|
|
DataDM::get(0, 1),
|
|
DataDM::get(1, 0),
|
|
DataDM::get(1, 1),
|
|
DataDM::get(2, 0),
|
|
DataDM::get(2, 1),
|
|
];
|
|
assert_eq!(get_all(), vec![1, 2, 3, 0, 0]);
|
|
|
|
// Two existing
|
|
DataDM::swap(0, 1, 1, 0);
|
|
assert_eq!(get_all(), vec![2, 1, 3, 0, 0]);
|
|
|
|
// Left existing
|
|
DataDM::swap(1, 0, 2, 0);
|
|
assert_eq!(get_all(), vec![2, 0, 3, 1, 0]);
|
|
|
|
// Right existing
|
|
DataDM::swap(2, 1, 1, 1);
|
|
assert_eq!(get_all(), vec![2, 0, 0, 1, 3]);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn map_basic_insert_remove_should_work() {
|
|
new_test_ext().execute_with(|| {
|
|
// initialized during genesis
|
|
assert_eq!(Map::get(&15u32), 42u64);
|
|
|
|
// get / insert / take
|
|
let key = 17u32;
|
|
assert_eq!(Map::get(&key), 0u64);
|
|
Map::insert(key, 4u64);
|
|
assert_eq!(Map::get(&key), 4u64);
|
|
assert_eq!(Map::take(&key), 4u64);
|
|
assert_eq!(Map::get(&key), 0u64);
|
|
|
|
// mutate
|
|
Map::mutate(&key, |val| {
|
|
*val = 15;
|
|
});
|
|
assert_eq!(Map::get(&key), 15u64);
|
|
|
|
// remove
|
|
Map::remove(&key);
|
|
assert_eq!(Map::get(&key), 0u64);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn map_iteration_should_work() {
|
|
new_test_ext().execute_with(|| {
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42)]);
|
|
// insert / remove
|
|
let key = 17u32;
|
|
Map::insert(key, 4u64);
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42), (key, 4)]);
|
|
assert_eq!(Map::take(&15), 42u64);
|
|
assert_eq!(Map::take(&key), 4u64);
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);
|
|
|
|
// Add couple of more elements
|
|
Map::insert(key, 42u64);
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42)]);
|
|
Map::insert(key + 1, 43u64);
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42), (key + 1, 43)]);
|
|
|
|
// mutate
|
|
let key = key + 2;
|
|
Map::mutate(&key, |val| {
|
|
*val = 15;
|
|
});
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43), (key, 15)]);
|
|
Map::mutate(&key, |val| {
|
|
*val = 17;
|
|
});
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43), (key, 17)]);
|
|
|
|
// remove first
|
|
Map::remove(&key);
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43)]);
|
|
|
|
// remove last from the list
|
|
Map::remove(&(key - 2));
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 1, 43)]);
|
|
|
|
// remove the last element
|
|
Map::remove(&(key - 1));
|
|
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn double_map_basic_insert_remove_remove_prefix_should_work() {
|
|
new_test_ext().execute_with(|| {
|
|
type DoubleMap = DataDM;
|
|
// initialized during genesis
|
|
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
|
|
|
|
// get / insert / take
|
|
let key1 = 17u32;
|
|
let key2 = 18u32;
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
|
DoubleMap::insert(&key1, &key2, &4u64);
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 4u64);
|
|
assert_eq!(DoubleMap::take(&key1, &key2), 4u64);
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
|
|
|
// mutate
|
|
DoubleMap::mutate(&key1, &key2, |val| {
|
|
*val = 15;
|
|
});
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 15u64);
|
|
|
|
// remove
|
|
DoubleMap::remove(&key1, &key2);
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
|
|
|
// remove prefix
|
|
DoubleMap::insert(&key1, &key2, &4u64);
|
|
DoubleMap::insert(&key1, &(key2 + 1), &4u64);
|
|
DoubleMap::insert(&(key1 + 1), &key2, &4u64);
|
|
DoubleMap::insert(&(key1 + 1), &(key2 + 1), &4u64);
|
|
DoubleMap::remove_prefix(&key1);
|
|
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
|
|
assert_eq!(DoubleMap::get(&key1, &(key2 + 1)), 0u64);
|
|
assert_eq!(DoubleMap::get(&(key1 + 1), &key2), 4u64);
|
|
assert_eq!(DoubleMap::get(&(key1 + 1), &(key2 + 1)), 4u64);
|
|
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn double_map_append_should_work() {
|
|
new_test_ext().execute_with(|| {
|
|
type DoubleMap = AppendableDM<Test>;
|
|
|
|
let key1 = 17u32;
|
|
let key2 = 18u32;
|
|
|
|
DoubleMap::insert(&key1, &key2, &vec![1]);
|
|
DoubleMap::append(&key1, &key2, 2);
|
|
assert_eq!(DoubleMap::get(&key1, &key2), &[1, 2]);
|
|
});
|
|
}
|
|
|
|
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
|
|
prefix: DecodeDifferent::Encode("Test"),
|
|
entries: DecodeDifferent::Encode(
|
|
&[
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("Data"),
|
|
modifier: StorageEntryModifier::Default,
|
|
ty: StorageEntryType::Map{
|
|
hasher: StorageHasher::Twox64Concat,
|
|
key: DecodeDifferent::Encode("u32"),
|
|
value: DecodeDifferent::Encode("u64"),
|
|
unused: false,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructData(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("OptionLinkedMap"),
|
|
modifier: StorageEntryModifier::Optional,
|
|
ty: StorageEntryType::Map {
|
|
hasher: StorageHasher::Blake2_128Concat,
|
|
key: DecodeDifferent::Encode("u32"),
|
|
value: DecodeDifferent::Encode("u32"),
|
|
unused: false,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructOptionLinkedMap(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("GenericData"),
|
|
modifier: StorageEntryModifier::Default,
|
|
ty: StorageEntryType::Map{
|
|
hasher: StorageHasher::Identity,
|
|
key: DecodeDifferent::Encode("T::BlockNumber"),
|
|
value: DecodeDifferent::Encode("T::BlockNumber"),
|
|
unused: false
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructGenericData(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("GenericData2"),
|
|
modifier: StorageEntryModifier::Optional,
|
|
ty: StorageEntryType::Map{
|
|
hasher: StorageHasher::Blake2_128Concat,
|
|
key: DecodeDifferent::Encode("T::BlockNumber"),
|
|
value: DecodeDifferent::Encode("T::BlockNumber"),
|
|
unused: false
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructGenericData2(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("DataDM"),
|
|
modifier: StorageEntryModifier::Default,
|
|
ty: StorageEntryType::DoubleMap{
|
|
hasher: StorageHasher::Twox64Concat,
|
|
key1: DecodeDifferent::Encode("u32"),
|
|
key2: DecodeDifferent::Encode("u32"),
|
|
value: DecodeDifferent::Encode("u64"),
|
|
key2_hasher: StorageHasher::Blake2_128Concat,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructDataDM(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("GenericDataDM"),
|
|
modifier: StorageEntryModifier::Default,
|
|
ty: StorageEntryType::DoubleMap{
|
|
hasher: StorageHasher::Blake2_128Concat,
|
|
key1: DecodeDifferent::Encode("T::BlockNumber"),
|
|
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
|
value: DecodeDifferent::Encode("T::BlockNumber"),
|
|
key2_hasher: StorageHasher::Identity,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructGenericDataDM(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("GenericData2DM"),
|
|
modifier: StorageEntryModifier::Optional,
|
|
ty: StorageEntryType::DoubleMap{
|
|
hasher: StorageHasher::Blake2_128Concat,
|
|
key1: DecodeDifferent::Encode("T::BlockNumber"),
|
|
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
|
value: DecodeDifferent::Encode("T::BlockNumber"),
|
|
key2_hasher: StorageHasher::Twox64Concat,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructGenericData2DM(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
StorageEntryMetadata {
|
|
name: DecodeDifferent::Encode("AppendableDM"),
|
|
modifier: StorageEntryModifier::Default,
|
|
ty: StorageEntryType::DoubleMap{
|
|
hasher: StorageHasher::Blake2_128Concat,
|
|
key1: DecodeDifferent::Encode("u32"),
|
|
key2: DecodeDifferent::Encode("T::BlockNumber"),
|
|
value: DecodeDifferent::Encode("Vec<u32>"),
|
|
key2_hasher: StorageHasher::Blake2_128Concat,
|
|
},
|
|
default: DecodeDifferent::Encode(
|
|
DefaultByteGetter(&__GetByteStructGenericData2DM(PhantomData::<Test>))
|
|
),
|
|
documentation: DecodeDifferent::Encode(&[]),
|
|
},
|
|
]
|
|
),
|
|
};
|
|
|
|
#[test]
|
|
fn store_metadata() {
|
|
let metadata = Module::<Test>::storage_metadata();
|
|
pretty_assertions::assert_eq!(EXPECTED_METADATA, metadata);
|
|
}
|
|
}
|