Skip to content
Snippets Groups Projects
Commit 74992c2e authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

WIP

parent a6d61d4b
No related branches found
No related tags found
1 merge request!129Draft: Remove duniter account
......@@ -302,10 +302,10 @@ pub fn new_test_ext(
frame_support::BasicExternalities::execute_with_storage(&mut t, || {
// manually increment genesis identities sufficient counter
// In real world, this should be handle manually by genesis creator
// TODO do not increase sufficients but provide existential deposit intead
for i in 1..=initial_identities_len {
frame_system::Pallet::<Test>::inc_sufficients(&(i as u64));
}
// TODO do not increase sufficients but provide existential deposit instead
// for i in 1..=initial_identities_len {
// frame_system::Pallet::<Test>::inc_sufficients(&(i as u64));
// }
// Some dedicated test account
frame_system::Pallet::<Test>::inc_providers(&(initial_identities_len as u64));
frame_system::Pallet::<Test>::inc_providers(&(initial_identities_len as u64 + 1));
......
......@@ -117,7 +117,8 @@ pub fn new_test_ext(gen_conf: pallet_identity::GenesisConfig<Test>) -> sp_io::Te
frame_support::BasicExternalities::execute_with_storage(&mut t, || {
// Some dedicated test account
frame_system::Pallet::<Test>::inc_sufficients(&1);
// WIP not more sufficient
// frame_system::Pallet::<Test>::inc_sufficients(&1);
frame_system::Pallet::<Test>::inc_providers(&2);
frame_system::Pallet::<Test>::inc_providers(&3);
});
......
......@@ -169,7 +169,8 @@ fn test_change_owner_key() {
run_to_block(1);
// Verify genesis data
assert_eq!(System::sufficients(&1), 1);
// WIP not more sufficient
assert_eq!(System::sufficients(&1), 0);
assert_eq!(System::sufficients(&10), 0);
// Caller should have an associated identity
......@@ -229,10 +230,11 @@ fn test_change_owner_key() {
status: crate::IdtyStatus::Validated,
})
);
// WIP not more sufficient
// Alice still sufficient
assert_eq!(System::sufficients(&1), 1);
assert_eq!(System::sufficients(&1), 0);
// New owner key should become a sufficient account
assert_eq!(System::sufficients(&10), 1);
assert_eq!(System::sufficients(&10), 0);
run_to_block(2);
......@@ -260,12 +262,13 @@ fn test_change_owner_key() {
(NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode()
)
));
// WIP not more sufficient
// Old old owner key should not be sufficient anymore
assert_eq!(System::sufficients(&1), 0);
// Old owner key should still sufficient
assert_eq!(System::sufficients(&10), 1);
assert_eq!(System::sufficients(&10), 0);
// New owner key should become a sufficient account
assert_eq!(System::sufficients(&100), 1);
assert_eq!(System::sufficients(&100), 0);
// Revoke identity 1
assert_ok!(Identity::revoke_identity(
......@@ -424,9 +427,10 @@ fn test_idty_revocation() {
TestSignature(1, (REVOCATION_PAYLOAD_PREFIX, revocation_payload).encode())
));
System::assert_has_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
account: 1,
}));
// WIP Alice account should not be killed anymore since it still has existential deposit
// System::assert_has_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
// account: 1,
// }));
System::assert_has_event(RuntimeEvent::Identity(crate::Event::IdtyRemoved {
idty_index: 1,
}));
......
......@@ -55,6 +55,8 @@ pub struct ExtBuilder {
parameters: GenesisParameters<u32, u32, Balance>,
}
const STARTING_BALANCE: Balance = 1000;
impl ExtBuilder {
pub fn new(
initial_authorities_len: usize,
......@@ -66,7 +68,12 @@ impl ExtBuilder {
assert!(initial_authorities_len <= initial_smiths_len);
let initial_accounts = (0..initial_identities_len)
.map(|i| (get_account_id_from_seed::<sr25519::Public>(NAMES[i]), 0))
.map(|i| {
(
get_account_id_from_seed::<sr25519::Public>(NAMES[i]),
STARTING_BALANCE,
)
})
.collect();
let initial_identities = (0..initial_identities_len)
.map(|i| {
......
......@@ -24,6 +24,9 @@ use gdev_runtime::*;
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
// TODO move this const somewhere else
const INITIAL_BALANCE: Balance = 1000;
#[test]
fn verify_treasury_account() {
println!("{}", Treasury::account_id());
......@@ -95,15 +98,18 @@ fn test_remove_identity() {
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRevoked(4),
));
System::assert_has_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
account: AccountKeyring::Dave.to_account_id(),
}));
System::assert_has_event(RuntimeEvent::Identity(
pallet_identity::Event::IdtyRemoved { idty_index: 4 },
));
// WIP Dave should not be killed anymore since he still has existential deposit
// System::assert_has_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
// account: AccountKeyring::Dave.to_account_id(),
// }));
// System::assert_has_event(RuntimeEvent::Identity(
// pallet_identity::Event::IdtyRemoved { idty_index: 4 },
// ));
});
}
#[test]
// check that a removed identity still get its due UD
fn test_remove_identity_after_one_ud() {
ExtBuilder::new(1, 3, 4).build().execute_with(|| {
//println!("UdCreationPeriod={}", <Runtime as pallet_universal_dividend::Config>::UdCreationPeriod::get());
......@@ -123,10 +129,11 @@ fn test_remove_identity_after_one_ud() {
who: AccountKeyring::Dave.to_account_id(),
amount: 1_000,
}));
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed {
account: AccountKeyring::Dave.to_account_id(),
free_balance: 1_000,
}));
// WIP there is no more endowed event since the account already has balance before universal dividend
// System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed {
// account: AccountKeyring::Dave.to_account_id(),
// free_balance: 1_000,
// }));
System::assert_has_event(RuntimeEvent::UniversalDividend(
pallet_universal_dividend::Event::UdsAutoPaidAtRemoval {
count: 1,
......@@ -142,7 +149,7 @@ fn test_remove_identity_after_one_ud() {
assert!(Identity::identity(4).is_none());
assert_eq!(
Balances::free_balance(AccountKeyring::Dave.to_account_id()),
1_000
INITIAL_BALANCE + 1_000
);
});
}
......@@ -201,23 +208,24 @@ fn test_create_new_account_with_insufficient_balance() {
amount: 400,
}));
// WIP not more new account tax
// At next block, the new account must be reaped because its balance is not sufficient
// to pay the "new account tax"
run_to_block(3);
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
who: Treasury::account_id(),
amount: 400,
}));
System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
value: 400,
}));
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
0
);
assert_eq!(Balances::free_balance(Treasury::account_id()), 600);
// run_to_block(3);
// System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
// who: Treasury::account_id(),
// amount: 400,
// }));
// System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
// value: 400,
// }));
// assert_eq!(
// Balances::free_balance(AccountKeyring::Eve.to_account_id()),
// 0
// );
// assert_eq!(Balances::free_balance(Treasury::account_id()), 600);
});
}
......@@ -253,47 +261,49 @@ fn test_create_new_account() {
// and new account tax should be collected and deposited in the treasury
run_to_block(3);
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Withdraw {
who: AccountKeyring::Eve.to_account_id(),
amount: 300,
}));
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
who: Treasury::account_id(),
amount: 300,
}));
System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
value: 300,
}));
// WIP no more creation tax
// System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Withdraw {
// who: AccountKeyring::Eve.to_account_id(),
// amount: 300,
// }));
// System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
// who: Treasury::account_id(),
// amount: 300,
// }));
// System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
// value: 300,
// }));
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
200
500
);
assert_eq!(Balances::free_balance(Treasury::account_id()), 500);
// assert_eq!(Balances::free_balance(Treasury::account_id()), 500);
// WIP no more random id
// We can't remove the account until the random id is assigned
run_to_block(4);
assert_noop!(
Balances::transfer(
frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
MultiAddress::Id(AccountKeyring::Alice.to_account_id()),
200
),
pallet_balances::Error::<Runtime>::KeepAlive,
);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
200
);
assert_ok!(Balances::transfer_all(
frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
MultiAddress::Id(AccountKeyring::Alice.to_account_id()),
false
),);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
200
);
// run_to_block(4);
// assert_noop!(
// Balances::transfer(
// frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
// MultiAddress::Id(AccountKeyring::Alice.to_account_id()),
// 200
// ),
// pallet_balances::Error::<Runtime>::KeepAlive,
// );
// assert_eq!(
// Balances::free_balance(AccountKeyring::Eve.to_account_id()),
// 200
// );
// assert_ok!(Balances::transfer_all(
// frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
// MultiAddress::Id(AccountKeyring::Alice.to_account_id()),
// false
// ),);
// assert_eq!(
// Balances::free_balance(AccountKeyring::Eve.to_account_id()),
// 200
// );
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment