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
f9b04638
Commit
f9b04638
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
feat(smith-members): max stock of certifications per smith
parent
1cefacba
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/smith-members/src/lib.rs
+9
-4
9 additions, 4 deletions
pallets/smith-members/src/lib.rs
pallets/smith-members/src/mock.rs
+1
-1
1 addition, 1 deletion
pallets/smith-members/src/mock.rs
pallets/smith-members/src/tests.rs
+14
-0
14 additions, 0 deletions
pallets/smith-members/src/tests.rs
with
24 additions
and
5 deletions
pallets/smith-members/src/lib.rs
+
9
−
4
View file @
f9b04638
...
...
@@ -245,6 +245,8 @@ pub mod pallet {
ReceiverHasNotBeenInvited
,
/// Smith must be a member of the main WoT
NotAMember
,
/// A smith has a limited stock of certifications
TooMuchCertificationsIssued
,
}
#[pallet::call]
...
...
@@ -357,13 +359,16 @@ impl<T: Config> Pallet<T> {
receiver
:
T
::
IdtyIndex
,
)
->
DispatchResultWithPostInfo
{
ensure!
(
issuer
!=
receiver
,
Error
::
<
T
>
::
CannotCertifySelf
);
let
issuer_status
=
Smiths
::
<
T
>
::
get
(
issuer
)
.ok_or
(
Error
::
<
T
>
::
IssuerHasNoSmithStatus
)
?
.status
;
let
issuer
=
Smiths
::
<
T
>
::
get
(
issuer
)
.ok_or
(
Error
::
<
T
>
::
IssuerHasNoSmithStatus
)
?
;
ensure!
(
issuer
_
status
==
SmithStatus
::
Smith
,
issuer
.
status
==
SmithStatus
::
Smith
,
Error
::
<
T
>
::
IssuerIsNotASmith
);
let
issued_certs
=
issuer
.issued_certs
.len
()
as
u32
;
ensure!
(
issued_certs
<
T
::
MaxByIssuer
::
get
(),
Error
::
<
T
>
::
TooMuchCertificationsIssued
);
let
receiver_status
=
Smiths
::
<
T
>
::
get
(
receiver
)
.ok_or
(
Error
::
<
T
>
::
ReceiverHasNotBeenInvited
)
?
.status
;
...
...
This diff is collapsed.
Click to expand it.
pallets/smith-members/src/mock.rs
+
1
−
1
View file @
f9b04638
...
...
@@ -95,7 +95,7 @@ impl pallet_smith_members::Config for Runtime {
type
IdtyIdOf
=
ConvertInto
;
type
MinCertForMembership
=
ConstU32
<
2
>
;
type
MinCertForCreateIdtyRight
=
ConstU32
<
3
>
;
type
MaxByIssuer
=
ConstU32
<
5
>
;
type
MaxByIssuer
=
ConstU32
<
3
>
;
type
InactivityMaxDuration
=
ConstU32
<
5
>
;
type
OnSmithDelete
=
();
type
IdtyIdOfAuthorityId
=
ConvertInto
;
...
...
This diff is collapsed.
Click to expand it.
pallets/smith-members/src/tests.rs
+
14
−
0
View file @
f9b04638
...
...
@@ -387,5 +387,19 @@ fn smith_coming_back_recovers_its_issued_certs() {
received_certs
:
vec!
[
1
,
3
]
})
);
// We can verify it with the stock rule
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
2
),
3
));
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
2
),
4
));
// Max stock is reached (3 = 1 recovered + 2 new)
assert_err!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
2
),
5
),
Error
::
<
Runtime
>
::
TooMuchCertificationsIssued
);
});
}
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