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
Work on some tests, clean up imports
  • Loading branch information
shawntabrizi committed Jan 9, 2020
commit 087bc6c49f7aa943c350bd5ffa5bb3d7fe1b2cd0
9 changes: 4 additions & 5 deletions frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@

use sp_std::prelude::*;
use sp_runtime::{
traits::{StaticLookup, Dispatchable, SaturatedConversion, Zero, CheckedAdd, CheckedMul},
DispatchError, DispatchResult
traits::{Dispatchable, SaturatedConversion, CheckedAdd, CheckedMul},
DispatchResult
};
use codec::{Encode, Decode};

use frame_support::{
decl_module, decl_event, decl_storage, decl_error, ensure,
Parameter, RuntimeDebug,
weights::{
SimpleDispatchInfo, GetDispatchInfo, PaysFee, WeighData, Weight,
ClassifyDispatch, DispatchClass
GetDispatchInfo,
},
traits::{Currency, ReservableCurrency, Get},
};
Expand Down Expand Up @@ -188,7 +187,7 @@ decl_module! {
}

/// Allow Sudo to bypass the recovery process and set an alias account.
fn set_recovered_account(origin, lost: T::AccountId, rescuer: T::AccountId) {
fn set_recovered(origin, lost: T::AccountId, rescuer: T::AccountId) {
ensure_root(origin)?;

// Create the recovery storage item.
Expand Down
8 changes: 4 additions & 4 deletions frame/recovery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

use super::*;

use frame_support::{impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types};
use frame_support::{
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
weights::Weight,
};
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! {
Expand Down Expand Up @@ -117,8 +119,6 @@ pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;

pub type BalancesCall = pallet_balances::Call<Test>;
pub type BalancesError<T, I> = pallet_balances::Error<T, I>;

pub type RecoveryCall = super::Call<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
80 changes: 72 additions & 8 deletions frame/recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

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

#[test]
Expand All @@ -41,12 +40,12 @@ fn basic_setup_works() {
}

#[test]
fn set_recovered_account_works() {
fn set_recovered_works() {
new_test_ext().execute_with(|| {
// Not accessible by a normal user
assert_noop!(Recovery::set_recovered_account(Origin::signed(1), 5, 1), DispatchError::BadOrigin);
assert_noop!(Recovery::set_recovered(Origin::signed(1), 5, 1), BadOrigin);
// Root can set a recovered account though
assert_ok!(Recovery::set_recovered_account(Origin::ROOT, 5, 1));
assert_ok!(Recovery::set_recovered(Origin::ROOT, 5, 1));
// Account 1 should now be able to make a call through account 5
let call = Box::new(Call::Balances(BalancesCall::transfer(1, 100)));
assert_ok!(Recovery::as_recovered(Origin::signed(1), 5, call));
Expand Down Expand Up @@ -198,3 +197,68 @@ fn create_recovery_works() {
assert_eq!(Recovery::recovery_config(5), Some(recovery_config));
});
}

#[test]
fn initiate_recovery_handles_basic_errors() {
new_test_ext().execute_with(|| {
// No recovery process set up for the account
assert_noop!(
Recovery::initiate_recovery(Origin::signed(1), 5),
Error::<Test>::NotRecoverable
);
// Create a recovery process for next test
let friends = vec![2, 3, 4];
let threshold = 3;
let delay_period = 10;
assert_ok!(Recovery::create_recovery(Origin::signed(5), friends.clone(), threshold, delay_period));

// Same user cannot recover same account twice
assert_ok!(Recovery::initiate_recovery(Origin::signed(1), 5));
assert_noop!(Recovery::initiate_recovery(Origin::signed(1), 5), Error::<Test>::AlreadyStarted);

// No double deposit
assert_eq!(Balances::reserved_balance(&1), 10);
});
}

#[test]
fn initiate_recovery_works() {
new_test_ext().execute_with(|| {
// Create a recovery process for the test
let friends = vec![2, 3, 4];
let threshold = 3;
let delay_period = 10;
assert_ok!(Recovery::create_recovery(Origin::signed(5), friends.clone(), threshold, delay_period));

// Recovery can be initiated
assert_ok!(Recovery::initiate_recovery(Origin::signed(1), 5));
// Deposit is reserved
assert_eq!(Balances::reserved_balance(&1), 10);
// Recovery status object is created correctly
let recovery_status = ActiveRecovery {
created: 1,
deposit: 10,
friends: vec![],
};
assert_eq!(<ActiveRecoveries<Test>>::get(&5, &1), Some(recovery_status));

// Multiple users can attempt to recover the same account
assert_ok!(Recovery::initiate_recovery(Origin::signed(2), 5));
});
}

#[test]
fn vouch_recovery_handles_basic_errors() {
new_test_ext().execute_with(|| {
// Cannot vouch for non-recoverable account


// Create and initiate a recovery process for next tests
let friends = vec![2, 3, 4];
let threshold = 3;
let delay_period = 10;
assert_ok!(Recovery::create_recovery(Origin::signed(5), friends.clone(), threshold, delay_period));
assert_ok!(Recovery::initiate_recovery(Origin::signed(1), 5));

});
}