Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
43e6eac
Initial sketch of social recovery pallet
shawntabrizi Jan 4, 2020
ccda36c
Fix compilation issues
shawntabrizi Jan 4, 2020
a57fb0e
Use a single total delay, rename stuff
shawntabrizi Jan 5, 2020
95b0c3a
Check possible overflow
shawntabrizi Jan 5, 2020
f41abcf
Copyright bump
shawntabrizi Jan 5, 2020
e8a911b
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 6, 2020
27e1034
Add mock for tests
shawntabrizi Jan 6, 2020
58aff40
Add basic end to end test
shawntabrizi Jan 6, 2020
8e7b7f2
Add `create_recovery` tests
shawntabrizi Jan 6, 2020
49fb230
Add malicious recovery lifecycle test
shawntabrizi Jan 6, 2020
b68f1fd
Make clear we check for sorted and unique friends
shawntabrizi Jan 6, 2020
087bc6c
Work on some tests, clean up imports
shawntabrizi Jan 9, 2020
8bb69ee
Change `if let Some(_)` to `ok_or()`
shawntabrizi Jan 9, 2020
4829182
More tests
shawntabrizi Jan 9, 2020
1f2f53a
Finish tests, except issue with `on_free_balance_zero`
shawntabrizi Jan 9, 2020
08a648d
Fix `on_free_balance_zero`
shawntabrizi Jan 9, 2020
5d9def8
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 10, 2020
28db6a7
Pallet docs
shawntabrizi Jan 10, 2020
e8c40d0
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 10, 2020
29986ec
Add function/weight docs
shawntabrizi Jan 10, 2020
3c28263
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 10, 2020
95c4513
Fix merge master
shawntabrizi Jan 10, 2020
38048db
OnReapAccount for System too
shawntabrizi Jan 10, 2020
5206825
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 10, 2020
a60a4a7
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 13, 2020
8f1f02f
Update weight docs
shawntabrizi Jan 13, 2020
b88f4a4
Merge remote-tracking branch 'upstream/master' into shawntabrizi-reco…
shawntabrizi Jan 13, 2020
29bef12
Allow passthrough to support fee-less extrinsics
shawntabrizi Jan 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add mock for tests
  • Loading branch information
shawntabrizi committed Jan 6, 2020
commit 27e10340a9e2b496125be3e92bbee12f681b6965
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ members = [
"frame/nicks",
"frame/offences",
"frame/randomness-collective-flip",
"frame/recover",
"frame/recovery",
"frame/scored-pool",
"frame/session",
"frame/staking",
Expand Down
2 changes: 1 addition & 1 deletion frame/recover/Cargo.toml → frame/recovery/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "pallet-recover"
name = "pallet-recovery"
version = "2.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
Expand Down
9 changes: 7 additions & 2 deletions frame/recover/src/lib.rs → frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -35,6 +35,11 @@ use frame_support::{
};
use frame_system::{self as system, ensure_signed, ensure_root};

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;

Expand Down Expand Up @@ -98,7 +103,7 @@ pub struct RecoveryConfig<BlockNumber, Balance, AccountId> {
}

decl_storage! {
trait Store for Module<T: Trait> as Utility {
trait Store for Module<T: Trait> as Recovery {
/// The set of recoverable accounts and their recovery configuration.
pub Recoverable get(fn recovery_config):
map T::AccountId => Option<RecoveryConfig<T::BlockNumber, BalanceOf<T>, T::AccountId>>;
Expand Down
140 changes: 140 additions & 0 deletions frame/recovery/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 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/>.

//! Test utilities

use super::*;

use frame_support::{impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types};
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{
Perbill, traits::{BlakeTwo256, IdentityLookup, OnInitialize, OnFinalize}, testing::Header,
};
use frame_system::EnsureSignedBy;
use crate as recovery;

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}

impl_outer_event! {
pub enum TestEvent for Test {
pallet_balances<T>,
recovery<T>,
}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
pallet_balances::Balances,
recovery::Recovery,
}
}

// For testing the module, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of modules we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

impl frame_system::Trait for Test {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Call = Call;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
}

parameter_types! {
pub const ExistentialDeposit: u64 = 0;
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
}

impl pallet_balances::Trait for Test {
type Balance = u128;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = TestEvent;
type TransferPayment = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const ConfigDepositBase: u64 = 10;
pub const FriendDepositFactor: u64 = 1;
pub const MaxFriends: u16 = 3;
pub const RecoveryDeposit: u64 = 10;
}

impl Trait for Test {
type Event = TestEvent;
type Call = Call;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
type MaxFriends = MaxFriends;
type RecoveryDeposit = RecoveryDeposit;
}

use pallet_balances::Call as BalancesCall;
use pallet_balances::Error as BalancesError;

pub type Recovery = Module<Test>;
pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;

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, 100), (2, 100), (3, 100), (4, 100), (5, 100)],
vesting: vec![],
}.assimilate_storage(&mut t).unwrap();
t.into()
}

/// Run until a particular block.
pub fn run_to_block(n: u64) {
while System::block_number() < n {
if System::block_number() > 1 {
System::on_finalize(System::block_number());
}
System::set_block_number(System::block_number() + 1);
System::on_initialize(System::block_number());
}
}
35 changes: 35 additions & 0 deletions frame/recovery/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 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/>.

//! Tests for the module.

use super::*;
use mock::{Recovery, Balances, Test, System, new_test_ext, run_to_block};
use sp_runtime::traits::{SignedExtension, BadOrigin};
use frame_support::{
assert_noop, assert_ok, assert_err,
traits::{LockableCurrency, LockIdentifier, WithdrawReason, WithdrawReasons,
Currency, ReservableCurrency, ExistenceRequirement::AllowDeath}
};

#[test]
fn basic_setup_works() {
new_test_ext().execute_with(|| {
assert_eq!(Recovery::recovered_account(&1), None);
assert_eq!(Recovery::active_recovery(&1, &2), None);
assert_eq!(Recovery::recovery_config(&1), None);
});
}