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
e3211e89
Commit
e3211e89
authored
1 year ago
by
Hugo Trentesaux
Committed by
Pascal Engélibert
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix certification period on renewal (
!165
)
* fix certification period on renewal
parent
0ee70682
No related branches found
No related tags found
1 merge request
!165
fix certification period on renewal
Pipeline
#31753
failed
1 year ago
Stage: build
Stage: tests
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/certification/src/lib.rs
+8
-1
8 additions, 1 deletion
pallets/certification/src/lib.rs
pallets/certification/src/mock.rs
+1
-0
1 addition, 0 deletions
pallets/certification/src/mock.rs
pallets/certification/src/tests.rs
+106
-1
106 additions, 1 deletion
pallets/certification/src/tests.rs
with
115 additions
and
2 deletions
pallets/certification/src/lib.rs
+
8
−
1
View file @
e3211e89
...
@@ -392,7 +392,7 @@ pub mod pallet {
...
@@ -392,7 +392,7 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
// INTERNAL FUNCTIONS //
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
Pallet
<
T
,
I
>
{
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
Pallet
<
T
,
I
>
{
/// perform cert add
/// perform cert add
ition or renewal
fn
do_add_cert
(
fn
do_add_cert
(
block_number
:
T
::
BlockNumber
,
block_number
:
T
::
BlockNumber
,
issuer
:
T
::
IdtyIndex
,
issuer
:
T
::
IdtyIndex
,
...
@@ -438,6 +438,7 @@ pub mod pallet {
...
@@ -438,6 +438,7 @@ pub mod pallet {
cert_meta
.received_count
cert_meta
.received_count
});
});
// emit NewCert event
Self
::
deposit_event
(
Event
::
NewCert
{
Self
::
deposit_event
(
Event
::
NewCert
{
issuer
,
issuer
,
issuer_issued_count
,
issuer_issued_count
,
...
@@ -451,12 +452,18 @@ pub mod pallet {
...
@@ -451,12 +452,18 @@ pub mod pallet {
receiver_received_count
,
receiver_received_count
,
);
);
}
else
{
}
else
{
// Update next_issuable_on in StorageIdtyCertMeta for issuer
StorageIdtyCertMeta
::
<
T
,
I
>
::
mutate
(
issuer
,
|
issuer_idty_cert_meta
|
{
issuer_idty_cert_meta
.next_issuable_on
=
block_number
+
T
::
CertPeriod
::
get
();
});
// emit RenewedCert event
Self
::
deposit_event
(
Event
::
RenewedCert
{
issuer
,
receiver
});
Self
::
deposit_event
(
Event
::
RenewedCert
{
issuer
,
receiver
});
}
}
Ok
(()
.into
())
Ok
(()
.into
())
}
}
/// remove the certifications due to expire on the given block
/// remove the certifications due to expire on the given block
// (run at on_initialize step)
fn
prune_certifications
(
block_number
:
T
::
BlockNumber
)
->
Weight
{
fn
prune_certifications
(
block_number
:
T
::
BlockNumber
)
->
Weight
{
let
mut
total_weight
=
Weight
::
zero
();
let
mut
total_weight
=
Weight
::
zero
();
...
...
This diff is collapsed.
Click to expand it.
pallets/certification/src/mock.rs
+
1
−
0
View file @
e3211e89
...
@@ -129,6 +129,7 @@ pub fn run_to_block(n: u64) {
...
@@ -129,6 +129,7 @@ pub fn run_to_block(n: u64) {
while
System
::
block_number
()
<
n
{
while
System
::
block_number
()
<
n
{
DefaultCertification
::
on_finalize
(
System
::
block_number
());
DefaultCertification
::
on_finalize
(
System
::
block_number
());
System
::
on_finalize
(
System
::
block_number
());
System
::
on_finalize
(
System
::
block_number
());
System
::
reset_events
();
System
::
set_block_number
(
System
::
block_number
()
+
1
);
System
::
set_block_number
(
System
::
block_number
()
+
1
);
System
::
on_initialize
(
System
::
block_number
());
System
::
on_initialize
(
System
::
block_number
());
DefaultCertification
::
on_initialize
(
System
::
block_number
());
DefaultCertification
::
on_initialize
(
System
::
block_number
());
...
...
This diff is collapsed.
Click to expand it.
pallets/certification/src/tests.rs
+
106
−
1
View file @
e3211e89
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
use
crate
::
mock
::
*
;
use
crate
::
mock
::
*
;
use
crate
::{
Error
,
Event
};
use
crate
::{
Error
,
Event
};
use
frame_support
::
assert_ok
;
use
frame_support
::
{
assert_noop
,
assert_ok
}
;
use
maplit
::
btreemap
;
use
maplit
::
btreemap
;
use
sp_std
::
collections
::
btree_map
::
BTreeMap
;
use
sp_std
::
collections
::
btree_map
::
BTreeMap
;
...
@@ -261,3 +261,108 @@ fn test_cert_renewal() {
...
@@ -261,3 +261,108 @@ fn test_cert_renewal() {
}));
}));
});
});
}
}
// when renewing a certification, issuer should not be able to emit a new cert before certification delay
#[test]
fn
test_cert_renewal_cert_delay
()
{
new_test_ext
(
DefaultCertificationConfig
{
apply_cert_period_at_genesis
:
false
,
certs_by_receiver
:
btreemap!
[
0
=>
btreemap!
[
1
=>
Some
(
5
),
2
=>
Some
(
20
),
],
1
=>
btreemap!
[
0
=>
Some
(
20
),
2
=>
Some
(
20
),
],
2
=>
btreemap!
[
0
=>
Some
(
20
),
1
=>
Some
(
20
),
],
],
})
.execute_with
(||
{
run_to_block
(
2
);
// renew certification from bob to alice
assert_eq!
(
DefaultCertification
::
add_cert
(
RuntimeOrigin
::
signed
(
1
),
1
,
0
),
Ok
(()
.into
())
);
System
::
assert_last_event
(
RuntimeEvent
::
DefaultCertification
(
Event
::
RenewedCert
{
issuer
:
1
,
receiver
:
0
,
}));
run_to_block
(
3
);
// try to renew again
assert_noop!
(
DefaultCertification
::
add_cert
(
RuntimeOrigin
::
signed
(
1
),
1
,
0
),
Error
::
<
Test
,
_
>
::
NotRespectCertPeriod
,
);
// no renewal event should be emitted
assert_eq!
(
System
::
events
()
.last
(),
None
);
});
}
// when renewing a certification, the certification should not expire before new expiration
#[test]
fn
test_cert_renewal_expiration
()
{
new_test_ext
(
DefaultCertificationConfig
{
apply_cert_period_at_genesis
:
false
,
certs_by_receiver
:
btreemap!
[
0
=>
btreemap!
[
1
=>
Some
(
5
),
2
=>
Some
(
20
),
],
1
=>
btreemap!
[
0
=>
Some
(
20
),
2
=>
Some
(
20
),
],
2
=>
btreemap!
[
0
=>
Some
(
20
),
1
=>
Some
(
20
),
],
],
})
.execute_with
(||
{
run_to_block
(
2
);
// renew certification from bob to alice
// this certification should expire 10 blocks later (at block 12)
assert_eq!
(
DefaultCertification
::
add_cert
(
RuntimeOrigin
::
signed
(
1
),
1
,
0
),
Ok
(()
.into
())
);
System
::
assert_last_event
(
RuntimeEvent
::
DefaultCertification
(
Event
::
RenewedCert
{
issuer
:
1
,
receiver
:
0
,
}));
run_to_block
(
4
);
// renew certification from bob to alice again
// this certification should expire 10 blocks later (at block 14)
assert_eq!
(
DefaultCertification
::
add_cert
(
RuntimeOrigin
::
signed
(
1
),
1
,
0
),
Ok
(()
.into
())
);
System
::
assert_last_event
(
RuntimeEvent
::
DefaultCertification
(
Event
::
RenewedCert
{
issuer
:
1
,
receiver
:
0
,
}));
// no certification should expire at these blocks
// hint : prune_certifications checks that the certification has not been renewed
run_to_block
(
12
);
assert_eq!
(
System
::
events
()
.last
(),
None
);
run_to_block
(
14
);
// expiry of previously renewed cert
System
::
assert_last_event
(
RuntimeEvent
::
DefaultCertification
(
Event
::
RemovedCert
{
issuer
:
1
,
issuer_issued_count
:
1
,
receiver
:
0
,
receiver_received_count
:
1
,
expiration
:
true
,
}));
});
}
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