diff --git a/pallets/identity/Cargo.toml b/pallets/identity/Cargo.toml index d4099cefcb53496035d01b4c20e1e6f976252cea..8d7f3a9f86142482731d1c1c058f6249b96c7bbb 100644 --- a/pallets/identity/Cargo.toml +++ b/pallets/identity/Cargo.toml @@ -76,3 +76,4 @@ branch = 'duniter-substrate-v0.9.32' [dev-dependencies] serde = '1.0.119' sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' } +sp-keystore = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' } diff --git a/pallets/identity/src/mock.rs b/pallets/identity/src/mock.rs index 53b8f4ec35c27c5f4ac2749326b4244c948a36ab..3a78a4356ff8408525b4073280902fc0f966a606 100644 --- a/pallets/identity/src/mock.rs +++ b/pallets/identity/src/mock.rs @@ -22,14 +22,25 @@ use frame_support::{ }; use frame_system as system; use sp_core::H256; +use sp_keystore::{testing::KeyStore, KeystoreExt}; use sp_runtime::{ - testing::{Header, TestSignature, UintAuthorityId}, + testing::{Header, UintAuthorityId}, traits::{BlakeTwo256, IdentityLookup}, + MultiSignature, }; +use std::sync::Arc; -type AccountId = u64; type Block = frame_system::mocking::MockBlock<Test>; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; +pub type Signature = MultiSignature; +pub type AccountPublic = <Signature as Verify>::Signer; +pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId; + +type AccountIdOf<Test> = <Test as frame_system::Config>::AccountId; + +fn account(id: u8) -> AccountIdOf<Test> { + [id; 32].into() +} // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( @@ -98,12 +109,12 @@ impl pallet_identity::Config for Test { type IdtyData = (); type IdtyNameValidator = IdtyNameValidatorTestImpl; type IdtyIndex = u64; - type NewOwnerKeySigner = UintAuthorityId; - type NewOwnerKeySignature = TestSignature; + type NewOwnerKeySigner = AccountPublic; + type NewOwnerKeySignature = Signature; type OnIdtyChange = (); type RemoveIdentityConsumers = (); - type RevocationSigner = UintAuthorityId; - type RevocationSignature = TestSignature; + type RevocationSigner = AccountPublic; + type RevocationSignature = Signature; type RuntimeEvent = RuntimeEvent; } @@ -117,12 +128,16 @@ 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); - frame_system::Pallet::<Test>::inc_providers(&2); - frame_system::Pallet::<Test>::inc_providers(&3); + frame_system::Pallet::<Test>::inc_sufficients(&account(1)); + frame_system::Pallet::<Test>::inc_providers(&account(2)); + frame_system::Pallet::<Test>::inc_providers(&account(3)); }); - sp_io::TestExternalities::new(t) + let keystore = KeyStore::new(); + let mut ext = sp_io::TestExternalities::new(t); + ext.register_extension(KeystoreExt(Arc::new(keystore))); + ext.execute_with(|| System::set_block_number(1)); + ext } pub fn run_to_block(n: u64) {