Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
e35d3f19
Commit
e35d3f19
authored
2 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat(identity): allow to reuse same account id after confirm expiration
parent
e6642974
No related branches found
No related tags found
1 merge request
!52
feat(identity): allow to reuse same account id after confirm expiration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/identity/src/lib.rs
+12
-5
12 additions, 5 deletions
pallets/identity/src/lib.rs
pallets/identity/src/tests.rs
+44
-0
44 additions, 0 deletions
pallets/identity/src/tests.rs
with
56 additions
and
5 deletions
pallets/identity/src/lib.rs
+
12
−
5
View file @
e35d3f19
...
...
@@ -378,8 +378,8 @@ pub mod pallet {
payload
.using_encoded
(|
bytes
|
payload_sig
.verify
(
bytes
,
&
payload
.owner_key
)),
Error
::
<
T
>
::
InvalidRevocationProof
);
if
let
Some
(
idty_index
)
=
<
IdentityIndexOf
<
T
>>
::
take
(
payload
.owner_key
)
{
Self
::
do_remove_identity
(
idty_index
);
if
let
Some
(
idty_index
)
=
<
IdentityIndexOf
<
T
>>
::
take
(
&
payload
.owner_key
)
{
Self
::
do_remove_identity
(
idty_index
,
Some
(
&
payload
.owner_key
)
);
Ok
(()
.into
())
}
else
{
Err
(
Error
::
<
T
>
::
IdtyNotFound
.into
())
...
...
@@ -394,7 +394,7 @@ pub mod pallet {
)
->
DispatchResultWithPostInfo
{
ensure_root
(
origin
)
?
;
Self
::
do_remove_identity
(
idty_index
);
Self
::
do_remove_identity
(
idty_index
,
None
);
if
let
Some
(
idty_name
)
=
idty_name
{
<
IdentitiesNames
<
T
>>
::
remove
(
idty_name
);
}
...
...
@@ -499,9 +499,15 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
impl
<
T
:
Config
>
Pallet
<
T
>
{
pub
(
super
)
fn
do_remove_identity
(
idty_index
:
T
::
IdtyIndex
)
->
Weight
{
pub
(
super
)
fn
do_remove_identity
(
idty_index
:
T
::
IdtyIndex
,
maybe_owner_key
:
Option
<&
T
::
AccountId
>
,
)
->
Weight
{
if
let
Some
(
idty_val
)
=
Identities
::
<
T
>
::
take
(
idty_index
)
{
T
::
RemoveIdentityConsumers
::
remove_idty_consumers
(
idty_index
);
if
let
Some
(
owner_key
)
=
maybe_owner_key
{
IdentityIndexOf
::
<
T
>
::
remove
(
owner_key
);
}
frame_system
::
Pallet
::
<
T
>
::
dec_sufficients
(
&
idty_val
.owner_key
);
Self
::
deposit_event
(
Event
::
IdtyRemoved
{
idty_index
});
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
IdtyEvent
::
Removed
);
...
...
@@ -523,7 +529,8 @@ pub mod pallet {
for
(
idty_index
,
idty_status
)
in
IdentitiesRemovableOn
::
<
T
>
::
take
(
block_number
)
{
if
let
Ok
(
idty_val
)
=
<
Identities
<
T
>>
::
try_get
(
idty_index
)
{
if
idty_val
.removable_on
==
block_number
&&
idty_val
.status
==
idty_status
{
total_weight
+=
Self
::
do_remove_identity
(
idty_index
)
total_weight
+=
Self
::
do_remove_identity
(
idty_index
,
Some
(
&
idty_val
.owner_key
))
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pallets/identity/src/tests.rs
+
44
−
0
View file @
e35d3f19
...
...
@@ -74,6 +74,50 @@ fn test_create_identity_ok() {
});
}
#[test]
fn
test_create_identity_but_not_confirm_it
()
{
new_test_ext
(
IdentityConfig
{
identities
:
vec!
[
alice
()],
})
.execute_with
(||
{
// We need to initialize at least one block before any call
run_to_block
(
1
);
// Alice should be able te create an identity
assert_ok!
(
Identity
::
create_identity
(
Origin
::
signed
(
1
),
2
));
// The identity shoud expire in blocs #3
run_to_block
(
3
);
let
events
=
System
::
events
();
assert_eq!
(
events
.len
(),
1
);
assert_eq!
(
events
[
0
],
EventRecord
{
phase
:
Phase
::
Initialization
,
event
:
Event
::
Identity
(
crate
::
Event
::
IdtyRemoved
{
idty_index
:
2
}),
topics
:
vec!
[],
}
);
// We shoud be able to recreate the identity
run_to_block
(
4
);
assert_ok!
(
Identity
::
create_identity
(
Origin
::
signed
(
1
),
2
));
let
events
=
System
::
events
();
assert_eq!
(
events
.len
(),
1
);
assert_eq!
(
events
[
0
],
EventRecord
{
phase
:
Phase
::
Initialization
,
event
:
Event
::
Identity
(
crate
::
Event
::
IdtyCreated
{
idty_index
:
3
,
owner_key
:
2
,
}),
topics
:
vec!
[],
}
);
});
}
#[test]
fn
test_idty_creation_period
()
{
new_test_ext
(
IdentityConfig
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment