Skip to content
Snippets Groups Projects
Commit c04ca2f3 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

fix(#125): test: ensure a Genesis identity can be revoked

parent d8451d24
No related branches found
No related tags found
No related merge requests found
Pipeline #33720 failed
...@@ -20,6 +20,7 @@ use crate::{ ...@@ -20,6 +20,7 @@ use crate::{
RevocationPayload, NEW_OWNER_KEY_PAYLOAD_PREFIX, REVOCATION_PAYLOAD_PREFIX, RevocationPayload, NEW_OWNER_KEY_PAYLOAD_PREFIX, REVOCATION_PAYLOAD_PREFIX,
}; };
use codec::Encode; use codec::Encode;
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::{assert_noop, assert_ok}; use frame_support::{assert_noop, assert_ok};
use sp_core::sr25519::Pair as KeyPair; use sp_core::sr25519::Pair as KeyPair;
use sp_core::Pair; use sp_core::Pair;
...@@ -545,7 +546,6 @@ fn test_idty_revocation() { ...@@ -545,7 +546,6 @@ fn test_idty_revocation() {
); );
}); });
} }
#[test] #[test]
fn test_inactive_genesis_members() { fn test_inactive_genesis_members() {
new_test_ext(IdentityConfig { new_test_ext(IdentityConfig {
...@@ -574,3 +574,53 @@ fn test_inactive_genesis_members() { ...@@ -574,3 +574,53 @@ fn test_inactive_genesis_members() {
})); }));
}); });
} }
#[test]
fn test_revocation_of_genesis_member() {
let alice = alice();
let bob = inactive_bob();
new_test_ext(IdentityConfig {
identities: vec![alice.clone(), bob.clone()],
})
.execute_with(|| {
assert!(pallet::Identities::<Test>::get(alice.index).is_some());
assert!(pallet::Identities::<Test>::get(bob.index).is_some());
assert!(pallet::IdentityIndexOf::<Test>::get(&alice.value.owner_key).is_some());
assert!(pallet::IdentityIndexOf::<Test>::get(&bob.value.owner_key).is_some());
// Necessary to go to block#1 to allow extrinsics consumption
run_to_block(1);
assert_ok!(revoke_self_identity(bob.clone()));
// alice identity remains untouched
assert!(pallet::Identities::<Test>::get(alice.index).is_some());
assert!(pallet::IdentityIndexOf::<Test>::get(&alice.value.owner_key).is_some());
// but bob identity has been removed
assert!(pallet::Identities::<Test>::get(bob.index).is_none());
assert!(pallet::IdentityIndexOf::<Test>::get(&bob.value.owner_key).is_none());
System::assert_has_event(RuntimeEvent::Identity(crate::Event::IdtyRemoved {
idty_index: bob.index,
reason: IdtyRemovalReason::Revoked,
}));
});
}
fn revoke_self_identity(idty: GenesisIdty<Test>) -> DispatchResultWithPostInfo {
Identity::revoke_identity(
RuntimeOrigin::signed(account(idty.index as u8).id),
idty.index,
account(idty.index as u8).id,
test_signature(
account(idty.index as u8).signer,
(
REVOCATION_PAYLOAD_PREFIX,
RevocationPayload {
idty_index: idty.index,
genesis_hash: System::block_hash(0),
},
)
.encode(),
),
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment