mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 14:15:44 +00:00
Fix Places where AccountId Uses Default (#10556)
* fix places where accountid is default * Update frame/system/src/lib.rs * fmt * add simple test Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -820,7 +820,7 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct EnsureSigned<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
pub struct EnsureSigned<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
||||||
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Default>
|
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>
|
||||||
EnsureOrigin<O> for EnsureSigned<AccountId>
|
EnsureOrigin<O> for EnsureSigned<AccountId>
|
||||||
{
|
{
|
||||||
type Success = AccountId;
|
type Success = AccountId;
|
||||||
@@ -833,7 +833,10 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
|
|||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
fn successful_origin() -> O {
|
fn successful_origin() -> O {
|
||||||
O::from(RawOrigin::Signed(Default::default()))
|
let zero_account_id =
|
||||||
|
AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
|
||||||
|
.expect("infinite length input; no invalid inputs for type; qed");
|
||||||
|
O::from(RawOrigin::Signed(zero_account_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,7 +844,7 @@ pub struct EnsureSignedBy<Who, AccountId>(sp_std::marker::PhantomData<(Who, Acco
|
|||||||
impl<
|
impl<
|
||||||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
||||||
Who: SortedMembers<AccountId>,
|
Who: SortedMembers<AccountId>,
|
||||||
AccountId: PartialEq + Clone + Ord + Default,
|
AccountId: PartialEq + Clone + Ord + Decode,
|
||||||
> EnsureOrigin<O> for EnsureSignedBy<Who, AccountId>
|
> EnsureOrigin<O> for EnsureSignedBy<Who, AccountId>
|
||||||
{
|
{
|
||||||
type Success = AccountId;
|
type Success = AccountId;
|
||||||
@@ -854,10 +857,13 @@ impl<
|
|||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
fn successful_origin() -> O {
|
fn successful_origin() -> O {
|
||||||
|
let zero_account_id =
|
||||||
|
AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
|
||||||
|
.expect("infinite length input; no invalid inputs for type; qed");
|
||||||
let members = Who::sorted_members();
|
let members = Who::sorted_members();
|
||||||
let first_member = match members.get(0) {
|
let first_member = match members.get(0) {
|
||||||
Some(account) => account.clone(),
|
Some(account) => account.clone(),
|
||||||
None => Default::default(),
|
None => zero_account_id,
|
||||||
};
|
};
|
||||||
O::from(RawOrigin::Signed(first_member.clone()))
|
O::from(RawOrigin::Signed(first_member.clone()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,3 +486,26 @@ fn runtime_updated_digest_emitted_when_heap_pages_changed() {
|
|||||||
assert_runtime_updated_digest(1);
|
assert_runtime_updated_digest(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ensure_signed_stuff_works() {
|
||||||
|
struct Members;
|
||||||
|
impl SortedMembers<u64> for Members {
|
||||||
|
fn sorted_members() -> Vec<u64> {
|
||||||
|
(0..10).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let signed_origin = Origin::signed(0u64);
|
||||||
|
assert_ok!(EnsureSigned::try_origin(signed_origin.clone()));
|
||||||
|
assert_ok!(EnsureSignedBy::<Members, _>::try_origin(signed_origin));
|
||||||
|
|
||||||
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
|
{
|
||||||
|
let successful_origin: Origin = EnsureSigned::successful_origin();
|
||||||
|
assert_ok!(EnsureSigned::try_origin(successful_origin));
|
||||||
|
|
||||||
|
let successful_origin: Origin = EnsureSignedBy::<Members, _>::successful_origin();
|
||||||
|
assert_ok!(EnsureSignedBy::<Members, _>::try_origin(successful_origin));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user