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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
93111e98
Commit
93111e98
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
feat(smith-members): only online smiths can invite/certify other smiths
parent
1a837959
No related branches found
No related tags found
No related merge requests found
Pipeline
#34961
passed
1 year ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/smith-members/src/lib.rs
+14
-4
14 additions, 4 deletions
pallets/smith-members/src/lib.rs
pallets/smith-members/src/tests.rs
+24
-9
24 additions, 9 deletions
pallets/smith-members/src/tests.rs
with
38 additions
and
13 deletions
pallets/smith-members/src/lib.rs
+
14
−
4
View file @
93111e98
...
@@ -232,6 +232,8 @@ pub mod pallet {
...
@@ -232,6 +232,8 @@ pub mod pallet {
OriginHasNeverBeenInvited
,
OriginHasNeverBeenInvited
,
/// Invitation is reseverd to smiths
/// Invitation is reseverd to smiths
InvitationIsASmithPrivilege
,
InvitationIsASmithPrivilege
,
/// Invitation is reseverd to online smiths
InvitationIsAOnlineSmithPrivilege
,
/// Invitation must not have been accepted yet
/// Invitation must not have been accepted yet
InvitationAlreadyAccepted
,
InvitationAlreadyAccepted
,
/// Invitation of an already known smith is forbidden except if it has been excluded
/// Invitation of an already known smith is forbidden except if it has been excluded
...
@@ -244,6 +246,8 @@ pub mod pallet {
...
@@ -244,6 +246,8 @@ pub mod pallet {
CertificationOnExcludedIsForbidden
,
CertificationOnExcludedIsForbidden
,
/// Issuer must be a smith
/// Issuer must be a smith
CertificationIsASmithPrivilege
,
CertificationIsASmithPrivilege
,
/// Only online smiths can certify
CertificationIsAOnlineSmithPrivilege
,
/// Smith cannot certify itself
/// Smith cannot certify itself
CertificationOfSelfIsForbidden
,
CertificationOfSelfIsForbidden
,
/// Receiver must be invited by another smith
/// Receiver must be invited by another smith
...
@@ -300,13 +304,15 @@ impl<T: Config> Pallet<T> {
...
@@ -300,13 +304,15 @@ impl<T: Config> Pallet<T> {
issuer
:
T
::
IdtyIndex
,
issuer
:
T
::
IdtyIndex
,
receiver
:
T
::
IdtyIndex
,
receiver
:
T
::
IdtyIndex
,
)
->
DispatchResultWithPostInfo
{
)
->
DispatchResultWithPostInfo
{
let
issuer_status
=
Smiths
::
<
T
>
::
get
(
issuer
)
let
issuer
=
Smiths
::
<
T
>
::
get
(
issuer
)
.ok_or
(
Error
::
<
T
>
::
OriginHasNeverBeenInvited
)
?
;
.ok_or
(
Error
::
<
T
>
::
OriginHasNeverBeenInvited
)
?
.status
;
ensure!
(
ensure!
(
issuer
_
status
==
SmithStatus
::
Smith
,
issuer
.
status
==
SmithStatus
::
Smith
,
Error
::
<
T
>
::
InvitationIsASmithPrivilege
Error
::
<
T
>
::
InvitationIsASmithPrivilege
);
);
ensure!
(
issuer
.expires_on
.is_none
(),
Error
::
<
T
>
::
InvitationIsAOnlineSmithPrivilege
);
if
let
Some
(
receiver_meta
)
=
Smiths
::
<
T
>
::
get
(
receiver
)
{
if
let
Some
(
receiver_meta
)
=
Smiths
::
<
T
>
::
get
(
receiver
)
{
ensure!
(
ensure!
(
receiver_meta
.status
==
SmithStatus
::
Excluded
,
receiver_meta
.status
==
SmithStatus
::
Excluded
,
...
@@ -384,6 +390,10 @@ impl<T: Config> Pallet<T> {
...
@@ -384,6 +390,10 @@ impl<T: Config> Pallet<T> {
issuer
.status
==
SmithStatus
::
Smith
,
issuer
.status
==
SmithStatus
::
Smith
,
Error
::
<
T
>
::
CertificationIsASmithPrivilege
Error
::
<
T
>
::
CertificationIsASmithPrivilege
);
);
ensure!
(
issuer
.expires_on
.is_none
(),
Error
::
<
T
>
::
CertificationIsAOnlineSmithPrivilege
);
let
issued_certs
=
issuer
.issued_certs
.len
()
as
u32
;
let
issued_certs
=
issuer
.issued_certs
.len
()
as
u32
;
ensure!
(
ensure!
(
issued_certs
<
T
::
MaxByIssuer
::
get
(),
issued_certs
<
T
::
MaxByIssuer
::
get
(),
...
...
This diff is collapsed.
Click to expand it.
pallets/smith-members/src/tests.rs
+
24
−
9
View file @
93111e98
...
@@ -36,6 +36,9 @@ fn process_to_become_a_smith_and_lose_it() {
...
@@ -36,6 +36,9 @@ fn process_to_become_a_smith_and_lose_it() {
],
],
})
})
.execute_with
(||
{
.execute_with
(||
{
// Go online to be able to invite+certify
Pallet
::
<
Runtime
>
::
smith_goes_online
(
1
);
Pallet
::
<
Runtime
>
::
smith_goes_online
(
2
);
// Events cannot be recorded on genesis
// Events cannot be recorded on genesis
run_to_block
(
1
);
run_to_block
(
1
);
// State before
// State before
...
@@ -106,6 +109,9 @@ fn process_to_become_a_smith_and_lose_it() {
...
@@ -106,6 +109,9 @@ fn process_to_become_a_smith_and_lose_it() {
received_certs
:
vec!
[
1
,
2
],
received_certs
:
vec!
[
1
,
2
],
}
}
);
);
// Go online to be able to invite+certify
Pallet
::
<
Runtime
>
::
smith_goes_offline
(
1
);
Pallet
::
<
Runtime
>
::
smith_goes_offline
(
2
);
// On session 4 everything if fine
// On session 4 everything if fine
Pallet
::
<
Runtime
>
::
on_new_session
(
4
);
Pallet
::
<
Runtime
>
::
on_new_session
(
4
);
...
@@ -164,12 +170,14 @@ fn should_have_checks_on_certify() {
...
@@ -164,12 +170,14 @@ fn should_have_checks_on_certify() {
],
],
})
})
.execute_with
(||
{
.execute_with
(||
{
// Go online to be able to invite+certify
Pallet
::
<
Runtime
>
::
smith_goes_online
(
1
);
// Initially
// Initially
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
1
)
.unwrap
(),
Smiths
::
<
Runtime
>
::
get
(
1
)
.unwrap
(),
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
Smith
,
expires_on
:
Some
(
5
)
,
expires_on
:
None
,
issued_certs
:
vec!
[
4
],
issued_certs
:
vec!
[
4
],
received_certs
:
vec!
[
2
,
3
,
4
],
received_certs
:
vec!
[
2
,
3
,
4
],
}
}
...
@@ -177,7 +185,7 @@ fn should_have_checks_on_certify() {
...
@@ -177,7 +185,7 @@ fn should_have_checks_on_certify() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
)
.unwrap
(),
Smiths
::
<
Runtime
>
::
get
(
2
)
.unwrap
(),
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
Smith
,
expires_on
:
Some
(
5
),
expires_on
:
Some
(
5
),
issued_certs
:
vec!
[
1
,
4
],
issued_certs
:
vec!
[
1
,
4
],
received_certs
:
vec!
[
3
,
4
],
received_certs
:
vec!
[
3
,
4
],
...
@@ -186,7 +194,7 @@ fn should_have_checks_on_certify() {
...
@@ -186,7 +194,7 @@ fn should_have_checks_on_certify() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Pending
,
status
:
Pending
,
expires_on
:
Some
(
5
),
expires_on
:
Some
(
5
),
issued_certs
:
vec!
[
1
,
2
],
issued_certs
:
vec!
[
1
,
2
],
received_certs
:
vec!
[
4
],
received_certs
:
vec!
[
4
],
...
@@ -195,7 +203,7 @@ fn should_have_checks_on_certify() {
...
@@ -195,7 +203,7 @@ fn should_have_checks_on_certify() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
4
)
.unwrap
(),
Smiths
::
<
Runtime
>
::
get
(
4
)
.unwrap
(),
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
Smith
,
expires_on
:
Some
(
5
),
expires_on
:
Some
(
5
),
issued_certs
:
vec!
[
1
,
2
,
3
],
issued_certs
:
vec!
[
1
,
2
,
3
],
received_certs
:
vec!
[
1
,
2
],
received_certs
:
vec!
[
1
,
2
],
...
@@ -224,8 +232,8 @@ fn should_have_checks_on_certify() {
...
@@ -224,8 +232,8 @@ fn should_have_checks_on_certify() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Pending
,
status
:
Pending
,
expires_on
:
Some
(
5
),
expires_on
:
Some
(
5
),
// TODO: hmmm?
issued_certs
:
vec!
[
1
,
2
],
issued_certs
:
vec!
[
1
,
2
],
received_certs
:
vec!
[
4
],
received_certs
:
vec!
[
4
],
}
}
...
@@ -356,7 +364,7 @@ fn smith_coming_back_recovers_its_issued_certs() {
...
@@ -356,7 +364,7 @@ fn smith_coming_back_recovers_its_issued_certs() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
),
Smiths
::
<
Runtime
>
::
get
(
2
),
Some
(
SmithMeta
{
Some
(
SmithMeta
{
status
:
SmithStatus
::
Excluded
,
status
:
Excluded
,
expires_on
:
None
,
expires_on
:
None
,
issued_certs
:
vec!
[
1
],
issued_certs
:
vec!
[
1
],
received_certs
:
vec!
[]
received_certs
:
vec!
[]
...
@@ -379,12 +387,13 @@ fn smith_coming_back_recovers_its_issued_certs() {
...
@@ -379,12 +387,13 @@ fn smith_coming_back_recovers_its_issued_certs() {
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
),
Smiths
::
<
Runtime
>
::
get
(
2
),
Some
(
SmithMeta
{
Some
(
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
Smith
,
expires_on
:
Some
(
10
),
expires_on
:
Some
(
10
),
issued_certs
:
vec!
[
1
],
issued_certs
:
vec!
[
1
],
received_certs
:
vec!
[
1
,
3
]
received_certs
:
vec!
[
1
,
3
]
})
})
);
);
Pallet
::
<
Runtime
>
::
smith_goes_online
(
2
);
// We can verify it with the stock rule
// We can verify it with the stock rule
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
2
),
RuntimeOrigin
::
signed
(
2
),
...
@@ -413,6 +422,10 @@ fn certifying_on_different_status() {
...
@@ -413,6 +422,10 @@ fn certifying_on_different_status() {
],
],
})
})
.execute_with
(||
{
.execute_with
(||
{
// Go online to be able to invite+certify
Pallet
::
<
Runtime
>
::
smith_goes_online
(
1
);
Pallet
::
<
Runtime
>
::
smith_goes_online
(
2
);
Pallet
::
<
Runtime
>
::
smith_goes_online
(
3
);
// State before
// State before
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
assert_err!
(
assert_err!
(
...
@@ -476,6 +489,8 @@ fn invitation_on_non_wot_member() {
...
@@ -476,6 +489,8 @@ fn invitation_on_non_wot_member() {
],
],
})
})
.execute_with
(||
{
.execute_with
(||
{
// Go online to be able to invite+certify
Pallet
::
<
Runtime
>
::
smith_goes_online
(
1
);
// State before
// State before
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
10
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
10
),
None
);
...
...
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