Skip to content
Snippets Groups Projects

Fix #196 forbid empty linked account

Merged Benjamin Gallois requested to merge 196-fix-empty-linked-accounts into master
@@ -19,9 +19,12 @@
@@ -19,9 +19,12 @@
mod common;
mod common;
use common::*;
use common::*;
 
use frame_support::traits::StoredMap;
use frame_support::{assert_noop, assert_ok};
use frame_support::{assert_noop, assert_ok};
use gdev_runtime::*;
use gdev_runtime::*;
 
use sp_core::Encode;
use sp_keyring::AccountKeyring;
use sp_keyring::AccountKeyring;
 
use sp_runtime::MultiAddress;
/// test currency transfer
/// test currency transfer
/// (does not take fees into account because it's only calls, not extrinsics)
/// (does not take fees into account because it's only calls, not extrinsics)
@@ -115,3 +118,48 @@ fn test_transfer_funds_unavailable() {
@@ -115,3 +118,48 @@ fn test_transfer_funds_unavailable() {
);
);
})
})
}
}
 
 
/// test balance transfer all with linked account not member
 
#[test]
 
fn test_transfer_all_linked_no_member() {
 
ExtBuilder::new(1, 3, 4)
 
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 5_000)])
 
.build()
 
.execute_with(|| {
 
run_to_block(1);
 
 
let genesis_hash = System::block_hash(0);
 
let alice = AccountKeyring::Alice.to_account_id();
 
let ferdie = AccountKeyring::Ferdie.to_account_id();
 
let payload = (b"link", genesis_hash, 1u32, ferdie.clone()).encode();
 
let signature = AccountKeyring::Ferdie.sign(&payload);
 
 
assert_ok!(Balances::transfer_allow_death(
 
frame_system::RawOrigin::Signed(alice.clone()).into(),
 
MultiAddress::Id(ferdie.clone()),
 
1_000
 
));
 
// Ferdie's account can be linked to Alice identity
 
assert_ok!(Identity::link_account(
 
frame_system::RawOrigin::Signed(alice).into(),
 
ferdie.clone(),
 
signature.into()
 
));
 
assert_eq!(
 
frame_system::Pallet::<Runtime>::get(&AccountKeyring::Alice.to_account_id())
 
.linked_idty,
 
Some(1)
 
);
 
assert_ok!(Balances::transfer_all(
 
frame_system::RawOrigin::Signed(ferdie.clone()).into(),
 
AccountKeyring::Bob.to_account_id().into(),
 
false
 
),);
 
assert_eq!(Balances::free_balance(ferdie), 0);
 
assert!(
 
frame_system::Pallet::<Runtime>::get(&AccountKeyring::Alice.to_account_id())
 
.linked_idty
 
.is_none()
 
);
 
})
 
}
Loading