From 74992c2e684a3d30c938f2bc42b824e56c2cbd86 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Thu, 9 Feb 2023 10:28:15 +0100 Subject: [PATCH] WIP --- pallets/duniter-wot/src/mock.rs | 8 +- pallets/identity/src/mock.rs | 3 +- pallets/identity/src/tests.rs | 20 ++-- runtime/gdev/tests/common/mod.rs | 9 +- runtime/gdev/tests/integration_tests.rs | 132 +++++++++++++----------- 5 files changed, 97 insertions(+), 75 deletions(-) diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index ca4dcafa5..03048b6fd 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -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)); diff --git a/pallets/identity/src/mock.rs b/pallets/identity/src/mock.rs index 53b8f4ec3..38c082cae 100644 --- a/pallets/identity/src/mock.rs +++ b/pallets/identity/src/mock.rs @@ -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); }); diff --git a/pallets/identity/src/tests.rs b/pallets/identity/src/tests.rs index ea4954790..5575e7850 100644 --- a/pallets/identity/src/tests.rs +++ b/pallets/identity/src/tests.rs @@ -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, })); diff --git a/runtime/gdev/tests/common/mod.rs b/runtime/gdev/tests/common/mod.rs index e75b8a7b1..34091e574 100644 --- a/runtime/gdev/tests/common/mod.rs +++ b/runtime/gdev/tests/common/mod.rs @@ -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| { diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index 0d8451f32..c391d8e34 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -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 + // ); }); } -- GitLab