Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+6 -12
View File
@@ -20,20 +20,18 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks, account, impl_benchmark_test_suite};
use sp_runtime::traits::Bounded;
use core::convert::TryInto;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
use crate::Pallet as Multisig;
const SEED: u32 = 0;
fn setup_multi<T: Config>(s: u32, z: u32)
-> Result<(Vec<T::AccountId>, Vec<u8>), &'static str>
{
fn setup_multi<T: Config>(s: u32, z: u32) -> Result<(Vec<T::AccountId>, Vec<u8>), &'static str> {
let mut signatories: Vec<T::AccountId> = Vec::new();
for i in 0 .. s {
for i in 0..s {
let signatory = account("signatory", i, SEED);
// Give them some balance for a possible deposit
let balance = BalanceOf::<T>::max_value();
@@ -298,8 +296,4 @@ benchmarks! {
}
}
impl_benchmark_test_suite!(
Multisig,
crate::tests::new_test_ext(),
crate::tests::Test,
);
impl_benchmark_test_suite!(Multisig, crate::tests::new_test_ext(), crate::tests::Test,);
+130 -83
View File
@@ -46,25 +46,33 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
mod tests;
mod benchmarking;
mod tests;
pub mod weights;
use sp_std::prelude::*;
use codec::{Encode, Decode};
use sp_io::hashing::blake2_256;
use frame_support::{ensure, RuntimeDebug};
use frame_support::{traits::{Get, ReservableCurrency, Currency},
weights::{Weight, GetDispatchInfo},
dispatch::{DispatchResultWithPostInfo, DispatchResult, DispatchErrorWithPostInfo, PostDispatchInfo},
use codec::{Decode, Encode};
use frame_support::{
dispatch::{
DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, PostDispatchInfo,
},
ensure,
traits::{Currency, Get, ReservableCurrency},
weights::{GetDispatchInfo, Weight},
RuntimeDebug,
};
use frame_system::{self as system, RawOrigin};
use sp_runtime::{DispatchError, traits::{Dispatchable, Zero}};
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{Dispatchable, Zero},
DispatchError,
};
use sp_std::prelude::*;
pub use weights::WeightInfo;
pub use pallet::*;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// Just a bunch of bytes, but they should decode to a valid `Call`.
pub type OpaqueCall = Vec<u8>;
@@ -100,10 +108,10 @@ enum CallOrHash {
}
#[frame_support::pallet]
pub mod pallet{
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
#[pallet::config]
pub trait Config: frame_system::Config {
@@ -111,8 +119,10 @@ pub mod pallet{
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
/// The overarching call type.
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
+ GetDispatchInfo + From<frame_system::Call<Self>>;
type Call: Parameter
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
+ GetDispatchInfo
+ From<frame_system::Call<Self>>;
/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -156,12 +166,8 @@ pub mod pallet{
>;
#[pallet::storage]
pub type Calls<T: Config> = StorageMap<
_,
Identity,
[u8; 32],
(OpaqueCall, T::AccountId, BalanceOf<T>),
>;
pub type Calls<T: Config> =
StorageMap<_, Identity, [u8; 32], (OpaqueCall, T::AccountId, BalanceOf<T>)>;
#[pallet::error]
pub enum Error<T> {
@@ -209,9 +215,15 @@ pub mod pallet{
/// \[approving, timepoint, multisig, call_hash\]
MultisigApproval(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash),
/// A multisig operation has been executed. \[approving, timepoint, multisig, call_hash\]
MultisigExecuted(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash, DispatchResult),
MultisigExecuted(
T::AccountId,
Timepoint<T::BlockNumber>,
T::AccountId,
CallHash,
DispatchResult,
),
/// A multisig operation has been cancelled. \[cancelling, timepoint, multisig, call_hash\]
MultisigCancelled(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash)
MultisigCancelled(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash),
}
#[pallet::hooks]
@@ -262,21 +274,26 @@ pub mod pallet{
let call_len = call.using_encoded(|c| c.len());
let result = call.dispatch(RawOrigin::Signed(id).into());
result.map(|post_dispatch_info| post_dispatch_info.actual_weight
.map(|actual_weight|
T::WeightInfo::as_multi_threshold_1(call_len as u32)
.saturating_add(actual_weight)
).into()
).map_err(|err| match err.post_info.actual_weight {
Some(actual_weight) => {
let weight_used = T::WeightInfo::as_multi_threshold_1(call_len as u32)
.saturating_add(actual_weight);
let post_info = Some(weight_used).into();
let error = err.error.into();
DispatchErrorWithPostInfo { post_info, error }
},
None => err,
})
result
.map(|post_dispatch_info| {
post_dispatch_info
.actual_weight
.map(|actual_weight| {
T::WeightInfo::as_multi_threshold_1(call_len as u32)
.saturating_add(actual_weight)
})
.into()
})
.map_err(|err| match err.post_info.actual_weight {
Some(actual_weight) => {
let weight_used = T::WeightInfo::as_multi_threshold_1(call_len as u32)
.saturating_add(actual_weight);
let post_info = Some(weight_used).into();
let error = err.error.into();
DispatchErrorWithPostInfo { post_info, error }
},
None => err,
})
}
/// Register approval for a dispatch to be made from a deterministic composite account if
@@ -345,7 +362,14 @@ pub mod pallet{
max_weight: Weight,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Self::operate(who, threshold, other_signatories, maybe_timepoint, CallOrHash::Call(call, store_call), max_weight)
Self::operate(
who,
threshold,
other_signatories,
maybe_timepoint,
CallOrHash::Call(call, store_call),
max_weight,
)
}
/// Register approval for a dispatch to be made from a deterministic composite account if
@@ -401,7 +425,14 @@ pub mod pallet{
max_weight: Weight,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Self::operate(who, threshold, other_signatories, maybe_timepoint, CallOrHash::Hash(call_hash), max_weight)
Self::operate(
who,
threshold,
other_signatories,
maybe_timepoint,
CallOrHash::Hash(call_hash),
max_weight,
)
}
/// Cancel a pre-existing, on-going multisig transaction. Any deposit reserved previously
@@ -447,8 +478,7 @@ pub mod pallet{
let id = Self::multi_account_id(&signatories, threshold);
let m = <Multisigs<T>>::get(&id, call_hash)
.ok_or(Error::<T>::NotFound)?;
let m = <Multisigs<T>>::get(&id, call_hash).ok_or(Error::<T>::NotFound)?;
ensure!(m.when == timepoint, Error::<T>::WrongTimepoint);
ensure!(m.depositor == who, Error::<T>::NotOwner);
@@ -496,7 +526,7 @@ impl<T: Config> Pallet<T> {
let call_hash = blake2_256(&call);
let call_len = call.len();
(call_hash, call_len, Some(call), should_store)
}
},
CallOrHash::Hash(h) => (h, 0, None, false),
};
@@ -511,12 +541,16 @@ impl<T: Config> Pallet<T> {
// We only bother with the approval if we're below threshold.
let maybe_pos = m.approvals.binary_search(&who).err().filter(|_| approvals < threshold);
// Bump approvals if not yet voted and the vote is needed.
if maybe_pos.is_some() { approvals += 1; }
if maybe_pos.is_some() {
approvals += 1;
}
// We only bother fetching/decoding call if we know that we're ready to execute.
let maybe_approved_call = if approvals >= threshold {
Self::get_call(&call_hash, maybe_call.as_ref().map(|c| c.as_ref()))
} else { None };
} else {
None
};
if let Some((call, call_len)) = maybe_approved_call {
// verify weight
@@ -530,21 +564,33 @@ impl<T: Config> Pallet<T> {
let result = call.dispatch(RawOrigin::Signed(id.clone()).into());
Self::deposit_event(Event::MultisigExecuted(
who, timepoint, id, call_hash, result.map(|_| ()).map_err(|e| e.error)
who,
timepoint,
id,
call_hash,
result.map(|_| ()).map_err(|e| e.error),
));
Ok(get_result_weight(result).map(|actual_weight|
T::WeightInfo::as_multi_complete(
other_signatories_len as u32,
call_len as u32
).saturating_add(actual_weight)
).into())
Ok(get_result_weight(result)
.map(|actual_weight| {
T::WeightInfo::as_multi_complete(
other_signatories_len as u32,
call_len as u32,
)
.saturating_add(actual_weight)
})
.into())
} else {
// We cannot dispatch the call now; either it isn't available, or it is, but we
// don't have threshold approvals even with our signature.
// Store the call if desired.
let stored = if let Some(data) = maybe_call.filter(|_| store) {
Self::store_call_and_reserve(who.clone(), &call_hash, data, BalanceOf::<T>::zero())?;
Self::store_call_and_reserve(
who.clone(),
&call_hash,
data,
BalanceOf::<T>::zero(),
)?;
true
} else {
false
@@ -567,10 +613,7 @@ impl<T: Config> Pallet<T> {
call_len as u32,
)
} else {
T::WeightInfo::as_multi_approve(
other_signatories_len as u32,
call_len as u32,
)
T::WeightInfo::as_multi_approve(other_signatories_len as u32, call_len as u32)
};
// Call is not made, so the actual weight does not include call
Ok(Some(final_weight).into())
@@ -591,24 +634,22 @@ impl<T: Config> Pallet<T> {
false
};
<Multisigs<T>>::insert(&id, call_hash, Multisig {
when: Self::timepoint(),
deposit,
depositor: who.clone(),
approvals: vec![who.clone()],
});
<Multisigs<T>>::insert(
&id,
call_hash,
Multisig {
when: Self::timepoint(),
deposit,
depositor: who.clone(),
approvals: vec![who.clone()],
},
);
Self::deposit_event(Event::NewMultisig(who, id, call_hash));
let final_weight = if stored {
T::WeightInfo::as_multi_create_store(
other_signatories_len as u32,
call_len as u32,
)
T::WeightInfo::as_multi_create_store(other_signatories_len as u32, call_len as u32)
} else {
T::WeightInfo::as_multi_create(
other_signatories_len as u32,
call_len as u32,
)
T::WeightInfo::as_multi_create(other_signatories_len as u32, call_len as u32)
};
// Call is not made, so the actual weight does not include call
Ok(Some(final_weight).into())
@@ -627,22 +668,27 @@ impl<T: Config> Pallet<T> {
other_deposit: BalanceOf<T>,
) -> DispatchResult {
ensure!(!Calls::<T>::contains_key(hash), Error::<T>::AlreadyStored);
let deposit = other_deposit + T::DepositBase::get()
+ T::DepositFactor::get() * BalanceOf::<T>::from(((data.len() + 31) / 32) as u32);
let deposit = other_deposit +
T::DepositBase::get() +
T::DepositFactor::get() * BalanceOf::<T>::from(((data.len() + 31) / 32) as u32);
T::Currency::reserve(&who, deposit)?;
Calls::<T>::insert(&hash, (data, who, deposit));
Ok(())
}
/// Attempt to decode and return the call, provided by the user or from storage.
fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(<T as Config>::Call, usize)> {
maybe_known.map_or_else(|| {
Calls::<T>::get(hash).and_then(|(data, ..)| {
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
})
}, |data| {
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
})
fn get_call(
hash: &[u8; 32],
maybe_known: Option<&[u8]>,
) -> Option<(<T as Config>::Call, usize)> {
maybe_known.map_or_else(
|| {
Calls::<T>::get(hash).and_then(|(data, ..)| {
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
})
},
|data| Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())),
)
}
/// Attempt to remove a call from storage, returning any deposit on it to the owner.
@@ -661,9 +707,10 @@ impl<T: Config> Pallet<T> {
}
/// Check that signatories is sorted and doesn't contain sender, then insert sender.
fn ensure_sorted_and_insert(other_signatories: Vec<T::AccountId>, who: T::AccountId)
-> Result<Vec<T::AccountId>, DispatchError>
{
fn ensure_sorted_and_insert(
other_signatories: Vec<T::AccountId>,
who: T::AccountId,
) -> Result<Vec<T::AccountId>, DispatchError> {
let mut signatories = other_signatories;
let mut maybe_last = None;
let mut index = 0;
+366 -58
View File
@@ -21,12 +21,13 @@
use super::*;
use frame_support::{
assert_ok, assert_noop, parameter_types, traits::Filter,
};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use crate as pallet_multisig;
use frame_support::{assert_noop, assert_ok, parameter_types, traits::Filter};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -113,14 +114,15 @@ impl Config for Test {
type WeightInfo = ();
}
use pallet_balances::Call as BalancesCall;
use pallet_balances::Error as BalancesError;
use pallet_balances::{Call as BalancesCall, Error as BalancesError};
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)],
}.assimilate_storage(&mut t).unwrap();
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
@@ -141,11 +143,27 @@ fn multisig_deposit_is_taken_and_returned() {
let call = Call::Balances(BalancesCall::transfer(6, 15));
let call_weight = call.get_dispatch_info().weight;
let data = call.encode();
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data.clone(), false, 0));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data.clone(),
false,
0
));
assert_eq!(Balances::free_balance(1), 2);
assert_eq!(Balances::reserved_balance(1), 3);
assert_ok!(Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), data, false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
data,
false,
call_weight
));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::reserved_balance(1), 0);
});
@@ -167,7 +185,14 @@ fn multisig_deposit_is_taken_and_returned_with_call_storage() {
assert_eq!(Balances::free_balance(1), 0);
assert_eq!(Balances::reserved_balance(1), 5);
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), hash, call_weight));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
hash,
call_weight
));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::reserved_balance(1), 0);
});
@@ -186,17 +211,39 @@ fn multisig_deposit_is_taken_and_returned_with_alt_call_storage() {
let data = call.encode();
let hash = blake2_256(&data);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_eq!(Balances::free_balance(1), 1);
assert_eq!(Balances::reserved_balance(1), 4);
assert_ok!(Multisig::as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), data, true, 0));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
data,
true,
0
));
assert_eq!(Balances::free_balance(2), 3);
assert_eq!(Balances::reserved_balance(2), 2);
assert_eq!(Balances::free_balance(1), 1);
assert_eq!(Balances::reserved_balance(1), 4);
assert_ok!(Multisig::approve_as_multi(Origin::signed(3), 3, vec![1, 2], Some(now()), hash, call_weight));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(3),
3,
vec![1, 2],
Some(now()),
hash,
call_weight
));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::free_balance(2), 5);
@@ -209,13 +256,31 @@ fn cancel_multisig_returns_deposit() {
new_test_ext().execute_with(|| {
let call = Call::Balances(BalancesCall::transfer(6, 15)).encode();
let hash = blake2_256(&call);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_eq!(Balances::free_balance(1), 6);
assert_eq!(Balances::reserved_balance(1), 4);
assert_ok!(
Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash.clone()),
);
assert_ok!(Multisig::cancel_as_multi(
Origin::signed(1),
3,
vec![2, 3],
now(),
hash.clone()
),);
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::reserved_balance(1), 0);
});
@@ -233,7 +298,14 @@ fn timepoint_checking_works() {
let hash = blake2_256(&call);
assert_noop!(
Multisig::approve_as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), hash.clone(), 0),
Multisig::approve_as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
hash.clone(),
0
),
Error::<Test>::UnexpectedTimepoint,
);
@@ -243,9 +315,17 @@ fn timepoint_checking_works() {
Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], None, call.clone(), false, 0),
Error::<Test>::NoTimepoint,
);
let later = Timepoint { index: 1, .. now() };
let later = Timepoint { index: 1, ..now() };
assert_noop!(
Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], Some(later), call.clone(), false, 0),
Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(later),
call.clone(),
false,
0
),
Error::<Test>::WrongTimepoint,
);
});
@@ -266,7 +346,14 @@ fn multisig_2_of_3_works_with_call_storing() {
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data, true, 0));
assert_eq!(Balances::free_balance(6), 0);
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), hash, call_weight));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
hash,
call_weight
));
assert_eq!(Balances::free_balance(6), 15);
});
}
@@ -286,7 +373,15 @@ fn multisig_2_of_3_works() {
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 2, vec![2, 3], None, hash, 0));
assert_eq!(Balances::free_balance(6), 0);
assert_ok!(Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), data, false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
data,
false,
call_weight
));
assert_eq!(Balances::free_balance(6), 15);
});
}
@@ -303,11 +398,33 @@ fn multisig_3_of_3_works() {
let call_weight = call.get_dispatch_info().weight;
let data = call.encode();
let hash = blake2_256(&data);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_eq!(Balances::free_balance(6), 0);
assert_ok!(Multisig::as_multi(Origin::signed(3), 3, vec![1, 2], Some(now()), data, false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(3),
3,
vec![1, 2],
Some(now()),
data,
false,
call_weight
));
assert_eq!(Balances::free_balance(6), 15);
});
}
@@ -317,15 +434,33 @@ fn cancel_multisig_works() {
new_test_ext().execute_with(|| {
let call = Call::Balances(BalancesCall::transfer(6, 15)).encode();
let hash = blake2_256(&call);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_noop!(
Multisig::cancel_as_multi(Origin::signed(2), 3, vec![1, 3], now(), hash.clone()),
Error::<Test>::NotOwner,
);
assert_ok!(
Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash.clone()),
);
assert_ok!(Multisig::cancel_as_multi(
Origin::signed(1),
3,
vec![2, 3],
now(),
hash.clone()
),);
});
}
@@ -336,14 +471,25 @@ fn cancel_multisig_with_call_storage_works() {
let hash = blake2_256(&call);
assert_ok!(Multisig::as_multi(Origin::signed(1), 3, vec![2, 3], None, call, true, 0));
assert_eq!(Balances::free_balance(1), 4);
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_noop!(
Multisig::cancel_as_multi(Origin::signed(2), 3, vec![1, 3], now(), hash.clone()),
Error::<Test>::NotOwner,
);
assert_ok!(
Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash.clone()),
);
assert_ok!(Multisig::cancel_as_multi(
Origin::signed(1),
3,
vec![2, 3],
now(),
hash.clone()
),);
assert_eq!(Balances::free_balance(1), 10);
});
}
@@ -353,9 +499,24 @@ fn cancel_multisig_with_alt_call_storage_works() {
new_test_ext().execute_with(|| {
let call = Call::Balances(BalancesCall::transfer(6, 15)).encode();
let hash = blake2_256(&call);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_eq!(Balances::free_balance(1), 6);
assert_ok!(Multisig::as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), call, true, 0));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
call,
true,
0
));
assert_eq!(Balances::free_balance(2), 8);
assert_ok!(Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash));
assert_eq!(Balances::free_balance(1), 10);
@@ -374,10 +535,26 @@ fn multisig_2_of_3_as_multi_works() {
let call = Call::Balances(BalancesCall::transfer(6, 15));
let call_weight = call.get_dispatch_info().weight;
let data = call.encode();
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data.clone(), false, 0));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data.clone(),
false,
0
));
assert_eq!(Balances::free_balance(6), 0);
assert_ok!(Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), data, false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
data,
false,
call_weight
));
assert_eq!(Balances::free_balance(6), 15);
});
}
@@ -397,10 +574,42 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
let call2_weight = call2.get_dispatch_info().weight;
let data2 = call2.encode();
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data1.clone(), false, 0));
assert_ok!(Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], None, data2.clone(), false, 0));
assert_ok!(Multisig::as_multi(Origin::signed(3), 2, vec![1, 2], Some(now()), data1, false, call1_weight));
assert_ok!(Multisig::as_multi(Origin::signed(3), 2, vec![1, 2], Some(now()), data2, false, call2_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data1.clone(),
false,
0
));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
None,
data2.clone(),
false,
0
));
assert_ok!(Multisig::as_multi(
Origin::signed(3),
2,
vec![1, 2],
Some(now()),
data1,
false,
call1_weight
));
assert_ok!(Multisig::as_multi(
Origin::signed(3),
2,
vec![1, 2],
Some(now()),
data2,
false,
call2_weight
));
assert_eq!(Balances::free_balance(6), 10);
assert_eq!(Balances::free_balance(7), 5);
@@ -419,15 +628,49 @@ fn multisig_2_of_3_cannot_reissue_same_call() {
let call_weight = call.get_dispatch_info().weight;
let data = call.encode();
let hash = blake2_256(&data);
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data.clone(), false, 0));
assert_ok!(Multisig::as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), data.clone(), false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data.clone(),
false,
0
));
assert_ok!(Multisig::as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
data.clone(),
false,
call_weight
));
assert_eq!(Balances::free_balance(multi), 5);
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data.clone(), false, 0));
assert_ok!(Multisig::as_multi(Origin::signed(3), 2, vec![1, 2], Some(now()), data.clone(), false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data.clone(),
false,
0
));
assert_ok!(Multisig::as_multi(
Origin::signed(3),
2,
vec![1, 2],
Some(now()),
data.clone(),
false,
call_weight
));
let err = DispatchError::from(BalancesError::<Test, _>::InsufficientBalance).stripped();
System::assert_last_event(pallet_multisig::Event::MultisigExecuted(3, now(), multi, hash, Err(err)).into());
System::assert_last_event(
pallet_multisig::Event::MultisigExecuted(3, now(), multi, hash, Err(err)).into(),
);
});
}
@@ -462,14 +705,42 @@ fn duplicate_approvals_are_ignored() {
new_test_ext().execute_with(|| {
let call = Call::Balances(BalancesCall::transfer(6, 15)).encode();
let hash = blake2_256(&call);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 2, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
hash.clone(),
0
));
assert_noop!(
Multisig::approve_as_multi(Origin::signed(1), 2, vec![2, 3], Some(now()), hash.clone(), 0),
Multisig::approve_as_multi(
Origin::signed(1),
2,
vec![2, 3],
Some(now()),
hash.clone(),
0
),
Error::<Test>::AlreadyApproved,
);
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 2, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
2,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_noop!(
Multisig::approve_as_multi(Origin::signed(3), 2, vec![1, 2], Some(now()), hash.clone(), 0),
Multisig::approve_as_multi(
Origin::signed(3),
2,
vec![1, 2],
Some(now()),
hash.clone(),
0
),
Error::<Test>::AlreadyApproved,
);
});
@@ -521,7 +792,15 @@ fn weight_check_works() {
let call = Call::Balances(BalancesCall::transfer(6, 15));
let data = call.encode();
assert_ok!(Multisig::as_multi(Origin::signed(1), 2, vec![2, 3], None, data.clone(), false, 0));
assert_ok!(Multisig::as_multi(
Origin::signed(1),
2,
vec![2, 3],
None,
data.clone(),
false,
0
));
assert_eq!(Balances::free_balance(6), 0);
assert_noop!(
@@ -545,12 +824,41 @@ fn multisig_handles_no_preimage_after_all_approve() {
let call_weight = call.get_dispatch_info().weight;
let data = call.encode();
let hash = blake2_256(&data);
assert_ok!(Multisig::approve_as_multi(Origin::signed(1), 3, vec![2, 3], None, hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(Origin::signed(2), 3, vec![1, 3], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(Origin::signed(3), 3, vec![1, 2], Some(now()), hash.clone(), 0));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(1),
3,
vec![2, 3],
None,
hash.clone(),
0
));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(2),
3,
vec![1, 3],
Some(now()),
hash.clone(),
0
));
assert_ok!(Multisig::approve_as_multi(
Origin::signed(3),
3,
vec![1, 2],
Some(now()),
hash.clone(),
0
));
assert_eq!(Balances::free_balance(6), 0);
assert_ok!(Multisig::as_multi(Origin::signed(3), 3, vec![1, 2], Some(now()), data, false, call_weight));
assert_ok!(Multisig::as_multi(
Origin::signed(3),
3,
vec![1, 2],
Some(now()),
data,
false,
call_weight
));
assert_eq!(Balances::free_balance(6), 15);
});
}
+1
View File
@@ -36,6 +36,7 @@
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]