Skip to content
Snippets Groups Projects
Commit 45e6eb44 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add change owner key test

parent f78c17f9
No related branches found
No related tags found
No related merge requests found
Pipeline #33519 waiting for manual action
...@@ -21,6 +21,7 @@ use frame_support::traits::{Get, PalletInfo, StorageInfo, StorageInfoTrait}; ...@@ -21,6 +21,7 @@ use frame_support::traits::{Get, PalletInfo, StorageInfo, StorageInfoTrait};
use frame_support::{assert_noop, assert_ok}; use frame_support::{assert_noop, assert_ok};
use frame_support::{StorageHasher, Twox128}; use frame_support::{StorageHasher, Twox128};
use gdev_runtime::*; use gdev_runtime::*;
use sp_core::Encode;
use sp_keyring::AccountKeyring; use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress; use sp_runtime::MultiAddress;
...@@ -1088,3 +1089,40 @@ fn test_oneshot_accounts() { ...@@ -1088,3 +1089,40 @@ fn test_oneshot_accounts() {
); );
}); });
} }
/// test change owner key
// Dave identity should be able to transfer his identity to Eve pubkey
#[test]
fn test_change_owner_key() {
ExtBuilder::new(1, 3, 4).build().execute_with(|| {
// payload
let genesis_hash = System::block_hash(0); // 0x454545454545...
let old_owner_key = AccountKeyring::Dave.to_account_id();
let new_owner_key = AccountKeyring::Eve.to_account_id();
let payload = pallet_identity::NewOwnerKeyPayload {
genesis_hash: &genesis_hash,
idty_index: 4u64,
old_owner_key: &old_owner_key,
};
// check that Dave identity index is actually 4
assert_eq!(
Identity::identity_index_of(AccountKeyring::Dave.to_account_id()),
Some(4)
);
// Dave can change his owner key
assert_ok!(Identity::change_owner_key(
// origin is Dave (current identity)
frame_system::RawOrigin::Signed(AccountKeyring::Dave.to_account_id()).into(),
// new key is Eve's key (no identity)
new_owner_key.clone(),
// payload is signed by Eve
AccountKeyring::Eve
.sign(
// payload is prefixed by "icok"
&(pallet_identity::NEW_OWNER_KEY_PAYLOAD_PREFIX, payload).encode()
)
.into()
));
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment