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

WIP

parent 72234aeb
No related branches found
No related tags found
1 merge request!129Draft: Remove duniter account
......@@ -302,6 +302,7 @@ 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));
}
......
......@@ -281,7 +281,8 @@ pub mod pallet {
}
// Apply phase //
frame_system::Pallet::<T>::inc_sufficients(&owner_key);
// WIP no more sufficient
// frame_system::Pallet::<T>::inc_sufficients(&owner_key);
<Identities<T>>::mutate_exists(creator, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt {
idty_val.next_creatable_identity_on =
......@@ -414,7 +415,7 @@ pub mod pallet {
T::CheckIdtyCallAllowed::check_change_identity_address(idty_index)?;
let block_number = frame_system::Pallet::<T>::block_number();
let maybe_old_old_owner_key =
let _maybe_old_old_owner_key =
if let Some((old_owner_key, last_change)) = idty_value.old_owner_key {
ensure!(
block_number >= last_change + T::ChangeOwnerKeyPeriod::get(),
......@@ -443,14 +444,16 @@ pub mod pallet {
);
// Apply phase
if let Some(old_old_owner_key) = maybe_old_old_owner_key {
frame_system::Pallet::<T>::dec_sufficients(&old_old_owner_key);
}
// WIP no more identity sufficient
// if let Some(old_old_owner_key) = maybe_old_old_owner_key {
// frame_system::Pallet::<T>::dec_sufficients(&old_old_owner_key);
// }
IdentityIndexOf::<T>::remove(&idty_value.owner_key);
idty_value.old_owner_key = Some((idty_value.owner_key.clone(), block_number));
idty_value.owner_key = new_key.clone();
frame_system::Pallet::<T>::inc_sufficients(&idty_value.owner_key);
// WIP not more sufficient
// frame_system::Pallet::<T>::inc_sufficients(&idty_value.owner_key);
IdentityIndexOf::<T>::insert(&idty_value.owner_key, idty_index);
Identities::<T>::insert(idty_index, idty_value);
Self::deposit_event(Event::IdtyChangedOwnerKey {
......@@ -546,6 +549,7 @@ pub mod pallet {
Ok(().into())
}
// WIP should not be needed anymore
#[pallet::weight(1_000_000_000)]
pub fn fix_sufficients(
origin: OriginFor<T>,
......@@ -631,10 +635,11 @@ pub mod pallet {
IdentityIndexOf::<T>::remove(&idty_val.owner_key);
// Identity should be removed after the consumers of the identity
Identities::<T>::remove(idty_index);
frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key);
if let Some((old_owner_key, _last_change)) = idty_val.old_owner_key {
frame_system::Pallet::<T>::dec_sufficients(&old_owner_key);
}
// WIP no more identity sufficient
// frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key);
// if let Some((old_owner_key, _last_change)) = idty_val.old_owner_key {
// frame_system::Pallet::<T>::dec_sufficients(&old_owner_key);
// }
Self::deposit_event(Event::IdtyRemoved { idty_index });
T::OnIdtyChange::on_idty_change(
idty_index,
......
......@@ -124,17 +124,27 @@ impl ExtBuilder {
pub fn build(self) -> sp_io::TestExternalities {
let Self {
initial_accounts: _initial_accounts,
initial_accounts,
initial_authorities_len,
initial_identities,
initial_smiths,
parameters,
} = self;
// compute initial monetary mass
let initial_monetary_mass = initial_accounts.iter().map(|(_id, balance)| balance).sum();
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();
// apply initial balances to accounts
pallet_balances::GenesisConfig::<Runtime> {
balances: initial_accounts,
}
.assimilate_storage(&mut t)
.unwrap();
pallet_authority_members::GenesisConfig::<Runtime> {
initial_authorities: initial_smiths
.iter()
......@@ -245,7 +255,7 @@ impl ExtBuilder {
pallet_universal_dividend::GenesisConfig::<Runtime> {
first_reeval: 100,
first_ud: 1_000,
initial_monetary_mass: 0,
initial_monetary_mass: initial_monetary_mass,
}
.assimilate_storage(&mut t)
.unwrap();
......
......@@ -305,12 +305,12 @@ fn test_create_new_idty() {
.execute_with(|| {
run_to_block(2);
// Should be able to create an identity
assert_ok!(Balances::transfer(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
MultiAddress::Id(AccountKeyring::Eve.to_account_id()),
200
500
));
// Should be able to create an identity
assert_ok!(Identity::create_identity(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Eve.to_account_id(),
......@@ -324,34 +324,32 @@ fn test_create_new_idty() {
}
#[test]
fn test_create_new_idty_without_founds() {
fn test_create_new_idty_without_funds() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 1_000)])
.build()
.execute_with(|| {
run_to_block(2);
// Should be able to create an identity without founds
// Should be able to create an identity without funds
assert_ok!(Identity::create_identity(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Eve.to_account_id(),
));
// At next block, nothing should be preleved
// At next block, nothing should be collected
run_to_block(3);
let events = System::events();
assert_eq!(events.len(), 0);
// Deposit some founds on the identity account,
// this should trigger the random id assignemt
// Deposit some funds on the identity account,
assert_ok!(Balances::transfer(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
MultiAddress::Id(AccountKeyring::Eve.to_account_id()),
200
));
// At next block, nothing should be preleved,
// and a random id request should be registered
// At next block, creation fees should be collected,
run_to_block(4);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment