Skip to content
Snippets Groups Projects
Commit 75f7f7a4 authored by Éloïs's avatar Éloïs
Browse files

fix(idty): we must inc account ref to prevent nonce reset

parent 649bd1c5
No related branches found
No related tags found
No related merge requests found
......@@ -310,10 +310,10 @@ fn gen_genesis_conf(
.enumerate()
.map(|(i, (name, owner_key))| GenesisIdty {
index: i as u32 + 1,
owner_key: owner_key.clone(),
name: name.clone(),
value: IdtyValue {
next_creatable_identity_on: Default::default(),
owner_key: owner_key.clone(),
removable_on: 0,
status: IdtyStatus::Validated,
},
......@@ -440,10 +440,10 @@ fn genesis_data_to_gdev_genesis_conf(
.enumerate()
.map(|(i, (name, pubkey))| common_runtime::GenesisIdty {
index: i as u32 + 1,
owner_key: pubkey,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
next_creatable_identity_on: 0,
owner_key: pubkey,
removable_on: 0,
status: IdtyStatus::Validated,
},
......
......@@ -178,10 +178,10 @@ pub fn new_test_ext(initial_identities_len: usize) -> sp_io::TestExternalities {
identities: (1..=initial_identities_len)
.map(|i| pallet_identity::GenesisIdty {
index: i as u32,
owner_key: i as u64,
name: pallet_identity::IdtyName::from(NAMES[i - 1]),
value: pallet_identity::IdtyValue {
next_creatable_identity_on: 0,
owner_key: i as u64,
removable_on: 0,
status: pallet_identity::IdtyStatus::Validated,
},
......
......@@ -60,17 +60,25 @@ fn test_create_idty_ok() {
assert_ok!(Identity::create_identity(Origin::signed(1), 6));
// 2 events should have occurred: IdtyCreated and NewCert
let events = System::events();
assert_eq!(events.len(), 2);
assert_eq!(events.len(), 3);
assert_eq!(
events[0],
EventRecord {
phase: Phase::Initialization,
event: Event::Identity(pallet_identity::Event::IdtyCreated(6, 6)),
event: Event::System(frame_system::Event::NewAccount { account: 6 }),
topics: vec![],
}
);
assert_eq!(
events[1],
EventRecord {
phase: Phase::Initialization,
event: Event::Identity(pallet_identity::Event::IdtyCreated(6, 6)),
topics: vec![],
}
);
assert_eq!(
events[2],
EventRecord {
phase: Phase::Initialization,
event: Event::Cert(pallet_certification::Event::NewCert {
......
......@@ -98,9 +98,8 @@ pub mod pallet {
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
pub struct GenesisIdty<T: Config> {
pub index: T::IdtyIndex,
pub owner_key: T::AccountId,
pub name: IdtyName,
pub value: IdtyValue<T::BlockNumber>,
pub value: IdtyValue<T::BlockNumber, T::AccountId>,
}
#[pallet::genesis_config]
......@@ -144,7 +143,7 @@ pub mod pallet {
}
<Identities<T>>::insert(idty_index, idty.value.clone());
IdentitiesNames::<T>::insert(idty.name.clone(), ());
IdentityIndexOf::<T>::insert(idty.owner_key, idty_index);
IdentityIndexOf::<T>::insert(idty.value.owner_key, idty_index);
}
}
}
......@@ -153,8 +152,13 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn identity)]
pub type Identities<T: Config> =
CountedStorageMap<_, Twox64Concat, T::IdtyIndex, IdtyValue<T::BlockNumber>, OptionQuery>;
pub type Identities<T: Config> = CountedStorageMap<
_,
Twox64Concat,
T::IdtyIndex,
IdtyValue<T::BlockNumber, T::AccountId>,
OptionQuery,
>;
#[pallet::storage]
#[pallet::getter(fn identity_index_of)]
......@@ -240,7 +244,7 @@ pub mod pallet {
}
// Apply phase //
frame_system::Pallet::<T>::inc_sufficients(&owner_key);
<Identities<T>>::mutate_exists(creator, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt {
idty_val.next_creatable_identity_on =
......@@ -255,6 +259,7 @@ pub mod pallet {
idty_index,
IdtyValue {
next_creatable_identity_on: T::BlockNumber::zero(),
owner_key: owner_key.clone(),
removable_on,
status: IdtyStatus::Created,
},
......@@ -440,9 +445,10 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub(super) fn do_remove_identity(idty_index: T::IdtyIndex) -> Weight {
<Identities<T>>::remove(idty_index);
if let Some(idty_val) = Identities::<T>::take(idty_index) {
frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key);
}
T::OnIdtyChange::on_idty_change(idty_index, IdtyEvent::Removed);
0
}
fn get_next_idty_index() -> T::IdtyIndex {
......
......@@ -20,15 +20,15 @@ use crate::{Error, GenesisIdty, IdtyName, IdtyValue};
use frame_support::assert_ok;
use frame_system::{EventRecord, Phase};
type IdtyVal = IdtyValue<u64>;
type IdtyVal = IdtyValue<u64, u64>;
fn alice() -> GenesisIdty<Test> {
GenesisIdty {
index: 1,
owner_key: 1,
name: IdtyName::from("Alice"),
value: IdtyVal {
next_creatable_identity_on: 0,
owner_key: 1,
removable_on: 0,
status: crate::IdtyStatus::Validated,
},
......
......@@ -79,8 +79,9 @@ impl Default for IdtyStatus {
#[cfg_attr(feature = "std", derive(Deserialize, Serialize))]
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
pub struct IdtyValue<BlockNumber: Decode + Encode + TypeInfo> {
pub struct IdtyValue<BlockNumber, AccountId> {
pub next_creatable_identity_on: BlockNumber,
pub owner_key: AccountId,
pub removable_on: BlockNumber,
pub status: IdtyStatus,
}
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