Companion for Substrate#10655 (#4765)

* Companion for Substrate#10655

https://github.com/paritytech/substrate/pull/10655

This removes the last usages of `Default` in conjunction with `AccountId`

* More fixes

* More of them!

* FMT

* Update Substrate
This commit is contained in:
Bastian Köcher
2022-01-21 21:14:09 +01:00
committed by GitHub
parent cc1201ef27
commit ef13a0ab8d
6 changed files with 176 additions and 179 deletions
+163 -163
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -64,8 +64,7 @@ pub mod pallet {
+ MaybeSerializeDeserialize
+ Debug
+ MaybeDisplay
+ Ord
+ Default;
+ Ord;
/// Type of account public key on target chain.
type TargetChainAccountPublic: Parameter + IdentifyAccount<AccountId = Self::AccountId>;
/// Type of signature that may prove that the message has been signed by
@@ -409,11 +409,13 @@ pub fn account_info_storage_key(id: &AccountId) -> Vec<u8> {
#[cfg(test)]
mod tests {
use super::*;
use sp_runtime::codec::Encode;
use parity_scale_codec::Decode;
use sp_runtime::{codec::Encode, traits::TrailingZeroInput};
#[test]
fn maximal_encoded_account_id_size_is_correct() {
let actual_size = AccountId::default().encode().len();
let actual_size =
AccountId::decode(&mut TrailingZeroInput::new(&[])).unwrap().encode().len();
assert!(
actual_size <= MAXIMAL_ENCODED_ACCOUNT_ID_SIZE as usize,
"Actual size of encoded account id for Polkadot-like chains ({}) is larger than expected {}",
@@ -82,13 +82,8 @@ pub trait Chain: Send + Sync + 'static {
+ MaybeSerializeDeserialize;
/// The user account identifier type for the runtime.
type AccountId: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
+ MaybeDisplay
+ Ord
+ Default;
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord;
/// Balance of an account in native tokens.
///
/// The chain may support multiple tokens, but this particular type is for token that is used
+2 -2
View File
@@ -305,11 +305,11 @@ impl<'a> parity_scale_codec::Input for TrailingZeroInput<'a> {
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing
/// zeroes to fill [`AccountId`].
impl<T: Encode + Decode + Default> AccountIdConversion<T> for Id {
impl<T: Encode + Decode> AccountIdConversion<T> for Id {
fn into_account(&self) -> T {
(b"para", self)
.using_encoded(|b| T::decode(&mut TrailingZeroInput(b)))
.unwrap_or_default()
.expect("infinite length input; no invalid inputs for type; qed")
}
fn try_from_account(x: &T) -> Option<Self> {
+4 -3
View File
@@ -74,6 +74,7 @@ mod tests {
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
const TEST_ACCOUNT: AccountId = AccountId::new([1; 32]);
frame_support::construct_runtime!(
pub enum Test where
@@ -171,7 +172,7 @@ mod tests {
where
I: 'a,
{
Some(Default::default())
Some(TEST_ACCOUNT)
}
}
impl pallet_authorship::Config for Test {
@@ -197,12 +198,12 @@ mod tests {
let tip = Balances::issue(20);
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
assert_eq!(Balances::free_balance(AccountId::default()), 0);
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0);
DealWithFees::on_unbalanceds(vec![fee, tip].into_iter());
// Author gets 100% of tip and 20% of fee = 22
assert_eq!(Balances::free_balance(AccountId::default()), 22);
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 22);
// Treasury gets 80% of fee
assert_eq!(Balances::free_balance(Treasury::account_id()), 8);
});