From a6d61d4b1deb6280e124ec379196a46519cc4f8c Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 8 Feb 2023 22:47:29 +0100 Subject: [PATCH] WIP --- pallets/duniter-wot/src/mock.rs | 1 + pallets/identity/src/lib.rs | 25 +++++++++++++++---------- runtime/gdev/tests/common/mod.rs | 14 ++++++++++++-- runtime/gdev/tests/integration_tests.rs | 16 +++++++--------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index ef15c5518..ca4dcafa5 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -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)); } diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index fc2dfe4e5..bba412be5 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -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, diff --git a/runtime/gdev/tests/common/mod.rs b/runtime/gdev/tests/common/mod.rs index 0cc296bea..e75b8a7b1 100644 --- a/runtime/gdev/tests/common/mod.rs +++ b/runtime/gdev/tests/common/mod.rs @@ -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(); diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index 2938d7f82..0d8451f32 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -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()), -- GitLab