Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

982 renaming issue #1052

Merged
merged 9 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions pallets/identity-management-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
// Events from this pallet
LinkIdentityRequested {
CreateIdentityRequested {
shard: ShardIdentifier,
},
UnlinkIdentityRequested {
RemoveIdentityRequested {
shard: ShardIdentifier,
},
VerifyIdentityRequested {
Expand All @@ -115,7 +115,7 @@ pub mod pallet {
UserShieldingKeySet {
account: AesOutput,
},
// link identity
// create identity
ChallengeCodeGeneratedPlain {
account: T::AccountId,
identity: Identity,
Expand All @@ -126,20 +126,20 @@ pub mod pallet {
identity: AesOutput,
code: AesOutput,
},
IdentityLinkedPlain {
IdentityCreatedPlain {
account: T::AccountId,
identity: Identity,
},
IdentityLinked {
IdentityCreated {
account: AesOutput,
identity: AesOutput,
},
// unlink identity
IdentityUnlinkedPlain {
// remove identity
IdentityRemovedPlain {
account: T::AccountId,
identity: Identity,
},
IdentityUnlinked {
IdentityRemoved {
account: AesOutput,
identity: AesOutput,
},
Expand Down Expand Up @@ -283,17 +283,17 @@ pub mod pallet {
Ok(())
}

/// Link an identity
/// Create an identity
#[pallet::weight(195_000_000)]
pub fn link_identity(
pub fn create_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
encrypted_metadata: Option<Vec<u8>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::LinkIdentityRequested { shard });
Self::deposit_event(Event::CreateIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
let identity = Identity::decode(&mut decrypted_identitty.as_slice())
Expand Down Expand Up @@ -330,35 +330,35 @@ pub mod pallet {
code: aes_encrypt_default(&key, code.as_ref()),
});

// emit the IdentityLinked event
// emit the IdentityCreated event
let context = IdentityContext {
metadata,
linking_request_block: Some(<frame_system::Pallet<T>>::block_number()),
verification_request_block: None,
is_verified: false,
};
IDGraphs::<T>::insert(&who, &identity, context);
Self::deposit_event(Event::<T>::IdentityLinkedPlain {
Self::deposit_event(Event::<T>::IdentityCreatedPlain {
account: who.clone(),
identity: identity.clone(),
});
Self::deposit_event(Event::<T>::IdentityLinked {
Self::deposit_event(Event::<T>::IdentityCreated {
account: aes_encrypt_default(&key, who.encode().as_slice()),
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
});
Ok(())
}

/// Unlink an identity
/// Remove an identity
#[pallet::weight(195_000_000)]
pub fn unlink_identity(
pub fn remove_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::UnlinkIdentityRequested { shard });
Self::deposit_event(Event::RemoveIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
let identity = Identity::decode(&mut decrypted_identitty.as_slice())
Expand All @@ -367,13 +367,13 @@ pub mod pallet {
ensure!(IDGraphs::<T>::contains_key(&who, &identity), Error::<T>::IdentityNotExist);
let key = UserShieldingKeys::<T>::get(&who).ok_or(Error::<T>::ShieldingKeyNotExist)?;

// emit the IdentityUnlinked event
// emit the IdentityRemoved event
IDGraphs::<T>::remove(&who, &identity);
Self::deposit_event(Event::<T>::IdentityUnlinkedPlain {
Self::deposit_event(Event::<T>::IdentityRemovedPlain {
account: who.clone(),
identity: identity.clone(),
});
Self::deposit_event(Event::<T>::IdentityUnlinked {
Self::deposit_event(Event::<T>::IdentityRemoved {
account: aes_encrypt_default(&key, who.encode().as_slice()),
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
});
Expand Down Expand Up @@ -480,24 +480,24 @@ pub mod pallet {
}

#[pallet::weight(195_000_000)]
pub fn identity_linked(
pub fn identity_created(
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityLinked { account, identity });
Self::deposit_event(Event::IdentityCreated { account, identity });
Ok(Pays::No.into())
}

#[pallet::weight(195_000_000)]
pub fn identity_unlinked(
pub fn identity_removed(
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityUnlinked { account, identity });
Self::deposit_event(Event::IdentityRemoved { account, identity });
Ok(Pays::No.into())
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/identity-management-mock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,20 @@ pub fn setup_user_shieding_key(
key
}

pub fn setup_link_identity(
pub fn setup_create_identity(
who: <Test as frame_system::Config>::AccountId,
identity: Identity,
bn: <Test as frame_system::Config>::BlockNumber,
) {
let key = setup_user_shieding_key(who);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
assert_ok!(IdentityManagementMock::link_identity(
assert_ok!(IdentityManagementMock::create_identity(
Origin::signed(who),
H256::random(),
encrypted_identity.to_vec(),
None
));
System::assert_has_event(Event::IdentityManagementMock(crate::Event::IdentityLinkedPlain {
System::assert_has_event(Event::IdentityManagementMock(crate::Event::IdentityCreatedPlain {
account: who,
identity: identity.clone(),
}));
Expand Down Expand Up @@ -274,7 +274,7 @@ pub fn setup_verify_twitter_identity(
identity: Identity,
bn: <Test as frame_system::Config>::BlockNumber,
) {
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let validation_data = match &identity.web_type {
IdentityWebType::Web2(Web2Network::Twitter) => create_mock_twitter_validation_data(),
Expand All @@ -294,7 +294,7 @@ pub fn setup_verify_polkadot_identity(
bn: <Test as frame_system::Config>::BlockNumber,
) {
let identity = create_mock_polkadot_identity(p.public().0);
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let code = IdentityManagementMock::challenge_codes(&who, &identity).unwrap();
let validation_data = match &identity.web_type {
Expand All @@ -321,7 +321,7 @@ pub fn setup_verify_eth_identity(
bn: <Test as frame_system::Config>::BlockNumber,
) {
let identity = create_mock_eth_identity(p.address().0);
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let code = IdentityManagementMock::challenge_codes(&who, &identity).unwrap();
let validation_data = match &identity.web_type {
Expand Down
22 changes: 11 additions & 11 deletions pallets/identity-management-mock/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ fn set_user_shielding_key_works() {
// TODO: maybe add more types

#[test]
fn link_twitter_identity_works() {
fn create_twitter_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(5);
setup_link_identity(2, create_mock_twitter_identity(b"alice"), 5);
setup_create_identity(2, create_mock_twitter_identity(b"alice"), 5);
});
}

#[test]
fn link_polkadot_identity_works() {
fn create_polkadot_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(3);
let p = sp_core::sr25519::Pair::from_string("//Alice", None).unwrap();
setup_link_identity(2, create_mock_polkadot_identity(p.public().0), 3);
setup_create_identity(2, create_mock_polkadot_identity(p.public().0), 3);
});
}

#[test]
fn link_eth_identity_works() {
fn create_eth_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(3);
let p = Random.generate();
setup_link_identity(2, create_mock_eth_identity(p.address().0), 3);
setup_create_identity(2, create_mock_eth_identity(p.address().0), 3);
});
}

Expand Down Expand Up @@ -102,14 +102,14 @@ fn verify_eth_identity_works() {
}

#[test]
fn double_link_twitter_identity_works() {
fn double_create_twitter_identity_works() {
new_test_ext().execute_with(|| {
// link and verify the first twitter handle
// create and verify the first twitter handle
System::set_block_number(3);
setup_verify_twitter_identity(2, create_mock_twitter_identity(b"alice"), 3);
// link second twitter handle works
// create second twitter handle works
System::set_block_number(4);
setup_link_identity(2, create_mock_twitter_identity(b"bob"), 4);
setup_create_identity(2, create_mock_twitter_identity(b"bob"), 4);
});
}

Expand All @@ -120,7 +120,7 @@ fn wrong_polkadot_verification_message_fails() {
let p = sp_core::sr25519::Pair::from_string("//Alice", None).unwrap();
let identity = create_mock_polkadot_identity(p.public().0);
let who = 2;
setup_link_identity(who, identity.clone(), 3);
setup_create_identity(who, identity.clone(), 3);

System::set_block_number(4);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
Expand Down
12 changes: 6 additions & 6 deletions pallets/identity-management/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {

benchmarks! {

// Benchmark `link_identity`. There are no worst conditions. The benchmark showed that
// Benchmark `create_identity`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
link_identity {
create_identity {
let caller = whitelisted_caller();
let shard = H256::from_slice(&TEST_MRENCLAVE);
let encrypted_did = vec![1u8; 2048];
let encrypted_metadata = Some(vec![1u8; 2048]);
}: _(RawOrigin::Signed(caller), shard, encrypted_did, encrypted_metadata)
verify {
assert_last_event::<T>(Event::LinkIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::CreateIdentityRequested{ shard }.into());
}

// Benchmark `unlink_identity`. There are no worst conditions. The benchmark showed that
// Benchmark `remove_identity`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
unlink_identity {
remove_identity {
let caller = whitelisted_caller();
let shard = H256::from_slice(&TEST_MRENCLAVE);
let encrypted_did = vec![1u8; 2048];
}: _(RawOrigin::Signed(caller), shard, encrypted_did )
verify {
assert_last_event::<T>(Event::UnlinkIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::RemoveIdentityRequested{ shard }.into());
}

// Benchmark `verify_identity`. There are no worst conditions. The benchmark showed that
Expand Down
Loading