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
3a292c7c
Commit
3a292c7c
authored
2 years ago
by
Éloïs
Committed by
Éloïs
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
tests(wot): add smith sub-wot tests
parent
4d0c7fd5
No related branches found
No related tags found
1 merge request
!58
Smith wot tests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/duniter-wot/src/mock.rs
+96
-2
96 additions, 2 deletions
pallets/duniter-wot/src/mock.rs
pallets/duniter-wot/src/tests.rs
+58
-44
58 additions, 44 deletions
pallets/duniter-wot/src/tests.rs
with
154 additions
and
46 deletions
pallets/duniter-wot/src/mock.rs
+
96
−
2
View file @
3a292c7c
...
@@ -41,6 +41,9 @@ frame_support::construct_runtime!(
...
@@ -41,6 +41,9 @@ frame_support::construct_runtime!(
Identity
:
pallet_identity
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Identity
:
pallet_identity
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Membership
:
pallet_membership
::
<
Instance1
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Membership
:
pallet_membership
::
<
Instance1
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Cert
:
pallet_certification
::
<
Instance1
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Cert
:
pallet_certification
::
<
Instance1
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
SmithsSubWot
:
pallet_duniter_wot
::
<
Instance2
>
::{
Pallet
},
SmithsMembership
:
pallet_membership
::
<
Instance2
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
SmithsCert
:
pallet_certification
::
<
Instance2
>
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
}
}
);
);
...
@@ -122,7 +125,7 @@ impl pallet_identity::Config for Test {
...
@@ -122,7 +125,7 @@ impl pallet_identity::Config for Test {
// Membership
// Membership
parameter_types!
{
parameter_types!
{
pub
const
MembershipPeriod
:
u64
=
5
;
pub
const
MembershipPeriod
:
u64
=
8
;
pub
const
PendingMembershipPeriod
:
u64
=
3
;
pub
const
PendingMembershipPeriod
:
u64
=
3
;
pub
const
RenewablePeriod
:
u64
=
2
;
pub
const
RenewablePeriod
:
u64
=
2
;
pub
const
RevocationPeriod
:
u64
=
4
;
pub
const
RevocationPeriod
:
u64
=
4
;
...
@@ -165,10 +168,72 @@ impl pallet_certification::Config<Instance1> for Test {
...
@@ -165,10 +168,72 @@ impl pallet_certification::Config<Instance1> for Test {
type
ValidityPeriod
=
ValidityPeriod
;
type
ValidityPeriod
=
ValidityPeriod
;
}
}
// SMITHS SUB-WOT //
parameter_types!
{
pub
const
SmithsMinCertForMembership
:
u32
=
2
;
pub
const
SmithsFirstIssuableOn
:
u64
=
2
;
}
impl
pallet_duniter_wot
::
Config
<
Instance2
>
for
Test
{
type
IsSubWot
=
frame_support
::
traits
::
ConstBool
<
true
>
;
type
MinCertForMembership
=
SmithsMinCertForMembership
;
type
MinCertForCreateIdtyRight
=
frame_support
::
traits
::
ConstU32
<
0
>
;
type
FirstIssuableOn
=
SmithsFirstIssuableOn
;
}
// SmithsMembership
parameter_types!
{
pub
const
SmithsMembershipPeriod
:
u64
=
20
;
pub
const
SmithsPendingMembershipPeriod
:
u64
=
3
;
pub
const
SmithsRenewablePeriod
:
u64
=
2
;
pub
const
SmithsRevocationPeriod
:
u64
=
4
;
}
impl
pallet_membership
::
Config
<
Instance2
>
for
Test
{
type
IsIdtyAllowedToRenewMembership
=
SmithsSubWot
;
type
IsIdtyAllowedToRequestMembership
=
SmithsSubWot
;
type
Event
=
Event
;
type
IdtyId
=
IdtyIndex
;
type
IdtyIdOf
=
Identity
;
type
MembershipPeriod
=
SmithsMembershipPeriod
;
type
MetaData
=
crate
::
MembershipMetaData
<
u64
>
;
type
OnEvent
=
SmithsSubWot
;
type
PendingMembershipPeriod
=
SmithsPendingMembershipPeriod
;
type
RenewablePeriod
=
SmithsRenewablePeriod
;
type
RevocationPeriod
=
SmithsRevocationPeriod
;
}
// SmithsCert
parameter_types!
{
pub
const
SmithsMaxByIssuer
:
u8
=
8
;
pub
const
SmithsMinReceivedCertToBeAbleToIssueCert
:
u32
=
2
;
pub
const
SmithsCertRenewablePeriod
:
u64
=
4
;
pub
const
SmithsCertPeriod
:
u64
=
2
;
pub
const
SmithsValidityPeriod
:
u64
=
10
;
}
impl
pallet_certification
::
Config
<
Instance2
>
for
Test
{
type
CertPeriod
=
SmithsCertPeriod
;
type
Event
=
Event
;
type
IdtyIndex
=
IdtyIndex
;
type
IdtyIndexOf
=
Identity
;
type
IsCertAllowed
=
DuniterWot
;
type
MaxByIssuer
=
SmithsMaxByIssuer
;
type
MinReceivedCertToBeAbleToIssueCert
=
SmithsMinReceivedCertToBeAbleToIssueCert
;
type
OnNewcert
=
DuniterWot
;
type
OnRemovedCert
=
DuniterWot
;
type
CertRenewablePeriod
=
SmithsCertRenewablePeriod
;
type
ValidityPeriod
=
SmithsValidityPeriod
;
}
pub
const
NAMES
:
[
&
str
;
6
]
=
[
"Alice"
,
"Bob"
,
"Charlie"
,
"Dave"
,
"Eve"
,
"Ferdie"
];
pub
const
NAMES
:
[
&
str
;
6
]
=
[
"Alice"
,
"Bob"
,
"Charlie"
,
"Dave"
,
"Eve"
,
"Ferdie"
];
// Build genesis storage according to the mock runtime.
// Build genesis storage according to the mock runtime.
pub
fn
new_test_ext
(
initial_identities_len
:
usize
)
->
sp_io
::
TestExternalities
{
pub
fn
new_test_ext
(
initial_identities_len
:
usize
,
initial_smiths_len
:
usize
,
)
->
sp_io
::
TestExternalities
{
let
mut
t
=
frame_system
::
GenesisConfig
::
default
()
let
mut
t
=
frame_system
::
GenesisConfig
::
default
()
.build_storage
::
<
Test
>
()
.build_storage
::
<
Test
>
()
.unwrap
();
.unwrap
();
...
@@ -213,6 +278,29 @@ pub fn new_test_ext(initial_identities_len: usize) -> sp_io::TestExternalities {
...
@@ -213,6 +278,29 @@ pub fn new_test_ext(initial_identities_len: usize) -> sp_io::TestExternalities {
.assimilate_storage
(
&
mut
t
)
.assimilate_storage
(
&
mut
t
)
.unwrap
();
.unwrap
();
pallet_membership
::
GenesisConfig
::
<
Test
,
Instance2
>
{
memberships
:
(
1
..=
initial_smiths_len
)
.map
(|
i
|
{
(
i
as
u32
,
sp_membership
::
MembershipData
{
expire_on
:
SmithsMembershipPeriod
::
get
(),
renewable_on
:
SmithsRenewablePeriod
::
get
(),
},
)
})
.collect
(),
}
.assimilate_storage
(
&
mut
t
)
.unwrap
();
pallet_certification
::
GenesisConfig
::
<
Test
,
Instance2
>
{
certs_by_issuer
:
clique_wot
(
initial_smiths_len
,
ValidityPeriod
::
get
()),
apply_cert_period_at_genesis
:
true
,
}
.assimilate_storage
(
&
mut
t
)
.unwrap
();
frame_support
::
BasicExternalities
::
execute_with_storage
(
&
mut
t
,
||
{
frame_support
::
BasicExternalities
::
execute_with_storage
(
&
mut
t
,
||
{
// manually increment genesis identities sufficient counter
// manually increment genesis identities sufficient counter
// In real world, this should be handle manually by genesis creator
// In real world, this should be handle manually by genesis creator
...
@@ -233,6 +321,9 @@ pub fn run_to_block(n: u64) {
...
@@ -233,6 +321,9 @@ pub fn run_to_block(n: u64) {
Identity
::
on_finalize
(
System
::
block_number
());
Identity
::
on_finalize
(
System
::
block_number
());
Membership
::
on_finalize
(
System
::
block_number
());
Membership
::
on_finalize
(
System
::
block_number
());
Cert
::
on_finalize
(
System
::
block_number
());
Cert
::
on_finalize
(
System
::
block_number
());
SmithsSubWot
::
on_finalize
(
System
::
block_number
());
SmithsMembership
::
on_finalize
(
System
::
block_number
());
SmithsCert
::
on_finalize
(
System
::
block_number
());
System
::
on_finalize
(
System
::
block_number
());
System
::
on_finalize
(
System
::
block_number
());
System
::
reset_events
();
System
::
reset_events
();
System
::
set_block_number
(
System
::
block_number
()
+
1
);
System
::
set_block_number
(
System
::
block_number
()
+
1
);
...
@@ -241,6 +332,9 @@ pub fn run_to_block(n: u64) {
...
@@ -241,6 +332,9 @@ pub fn run_to_block(n: u64) {
Identity
::
on_initialize
(
System
::
block_number
());
Identity
::
on_initialize
(
System
::
block_number
());
Membership
::
on_initialize
(
System
::
block_number
());
Membership
::
on_initialize
(
System
::
block_number
());
Cert
::
on_initialize
(
System
::
block_number
());
Cert
::
on_initialize
(
System
::
block_number
());
SmithsSubWot
::
on_initialize
(
System
::
block_number
());
SmithsMembership
::
on_initialize
(
System
::
block_number
());
SmithsCert
::
on_initialize
(
System
::
block_number
());
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pallets/duniter-wot/src/tests.rs
+
58
−
44
View file @
3a292c7c
...
@@ -24,7 +24,7 @@ use pallet_identity::{IdtyName, IdtyStatus};
...
@@ -24,7 +24,7 @@ use pallet_identity::{IdtyName, IdtyStatus};
#[test]
#[test]
fn
test_genesis_build
()
{
fn
test_genesis_build
()
{
new_test_ext
(
3
)
.execute_with
(||
{
new_test_ext
(
3
,
2
)
.execute_with
(||
{
run_to_block
(
1
);
run_to_block
(
1
);
// Verify state
// Verify state
assert_eq!
(
Identity
::
identities_count
(),
3
);
assert_eq!
(
Identity
::
identities_count
(),
3
);
...
@@ -38,7 +38,7 @@ fn test_genesis_build() {
...
@@ -38,7 +38,7 @@ fn test_genesis_build() {
#[test]
#[test]
fn
test_creator_not_allowed_to_create_idty
()
{
fn
test_creator_not_allowed_to_create_idty
()
{
new_test_ext
(
3
)
.execute_with
(||
{
new_test_ext
(
3
,
2
)
.execute_with
(||
{
run_to_block
(
1
);
run_to_block
(
1
);
// Alice should not be able te create an identity before block #2
// Alice should not be able te create an identity before block #2
...
@@ -50,9 +50,57 @@ fn test_creator_not_allowed_to_create_idty() {
...
@@ -50,9 +50,57 @@ fn test_creator_not_allowed_to_create_idty() {
});
});
}
}
#[test]
fn
test_join_smiths
()
{
new_test_ext
(
5
,
3
)
.execute_with
(||
{
run_to_block
(
2
);
// Dave shoud be able to requst smith membership
assert_ok!
(
SmithsMembership
::
request_membership
(
Origin
::
signed
(
4
),
crate
::
MembershipMetaData
(
4
)
));
run_to_block
(
3
);
// Then, Alice should be able to send a smith cert to Dave
assert_ok!
(
SmithsCert
::
add_cert
(
Origin
::
signed
(
1
),
4
));
});
}
#[test]
fn
test_revoke_smiths_them_rejoin
()
{
new_test_ext
(
5
,
4
)
.execute_with
(||
{
run_to_block
(
2
);
// Dave shoud be able to revoke is smith membership
assert_ok!
(
SmithsMembership
::
revoke_membership
(
Origin
::
signed
(
4
),
Some
(
4
)
));
// Dave should not be able te re-request membership before the RevocationPeriod end
run_to_block
(
3
);
assert_err!
(
SmithsMembership
::
request_membership
(
Origin
::
signed
(
4
),
crate
::
MembershipMetaData
(
4
)),
pallet_membership
::
Error
::
<
Test
,
crate
::
Instance2
>
::
MembershipRevokedRecently
);
// At bloc #6, Dave shoud be able to request smith membership
run_to_block
(
6
);
assert_ok!
(
SmithsMembership
::
request_membership
(
Origin
::
signed
(
4
),
crate
::
MembershipMetaData
(
4
)
));
// Then, Alice should be able to send a smith cert to Dave
assert_ok!
(
SmithsCert
::
add_cert
(
Origin
::
signed
(
1
),
4
));
});
}
#[test]
#[test]
fn
test_create_idty_ok
()
{
fn
test_create_idty_ok
()
{
new_test_ext
(
5
)
.execute_with
(||
{
new_test_ext
(
5
,
2
)
.execute_with
(||
{
run_to_block
(
2
);
run_to_block
(
2
);
// Alice should be able te create an identity at block #2
// Alice should be able te create an identity at block #2
...
@@ -91,7 +139,7 @@ fn test_create_idty_ok() {
...
@@ -91,7 +139,7 @@ fn test_create_idty_ok() {
#[test]
#[test]
fn
test_new_idty_validation
()
{
fn
test_new_idty_validation
()
{
new_test_ext
(
5
)
.execute_with
(||
{
new_test_ext
(
5
,
2
)
.execute_with
(||
{
// Alice create Ferdie identity
// Alice create Ferdie identity
run_to_block
(
2
);
run_to_block
(
2
);
assert_ok!
(
Identity
::
create_identity
(
Origin
::
signed
(
1
),
6
));
assert_ok!
(
Identity
::
create_identity
(
Origin
::
signed
(
1
),
6
));
...
@@ -144,7 +192,7 @@ fn test_new_idty_validation() {
...
@@ -144,7 +192,7 @@ fn test_new_idty_validation() {
#[test]
#[test]
fn
test_confirm_idty_ok
()
{
fn
test_confirm_idty_ok
()
{
new_test_ext
(
5
)
.execute_with
(||
{
new_test_ext
(
5
,
2
)
.execute_with
(||
{
run_to_block
(
2
);
run_to_block
(
2
);
// Alice create Ferdie identity
// Alice create Ferdie identity
...
@@ -186,7 +234,7 @@ fn test_confirm_idty_ok() {
...
@@ -186,7 +234,7 @@ fn test_confirm_idty_ok() {
#[test]
#[test]
fn
test_idty_membership_expire_them_requested
()
{
fn
test_idty_membership_expire_them_requested
()
{
new_test_ext
(
3
)
.execute_with
(||
{
new_test_ext
(
3
,
2
)
.execute_with
(||
{
run_to_block
(
4
);
run_to_block
(
4
);
// Alice renew her membership
// Alice renew her membership
...
@@ -194,10 +242,11 @@ fn test_idty_membership_expire_them_requested() {
...
@@ -194,10 +242,11 @@ fn test_idty_membership_expire_them_requested() {
// Bob renew his membership
// Bob renew his membership
assert_ok!
(
Membership
::
renew_membership
(
Origin
::
signed
(
2
),
None
));
assert_ok!
(
Membership
::
renew_membership
(
Origin
::
signed
(
2
),
None
));
// Charlie's membership should expire at block #
5
// Charlie's membership should expire at block #
8
run_to_block
(
5
);
run_to_block
(
8
);
assert!
(
Membership
::
membership
(
3
)
.is_none
());
assert!
(
Membership
::
membership
(
3
)
.is_none
());
let
events
=
System
::
events
();
let
events
=
System
::
events
();
println!
(
"{:?}"
,
events
);
assert_eq!
(
events
.len
(),
2
);
assert_eq!
(
events
.len
(),
2
);
assert_eq!
(
assert_eq!
(
events
[
0
],
events
[
0
],
...
@@ -216,7 +265,7 @@ fn test_idty_membership_expire_them_requested() {
...
@@ -216,7 +265,7 @@ fn test_idty_membership_expire_them_requested() {
}
}
);
);
// Charlie's identity should be removed at block #
5
// Charlie's identity should be removed at block #
8
assert!
(
Identity
::
identity
(
3
)
.is_none
());
assert!
(
Identity
::
identity
(
3
)
.is_none
());
// Alice can't renew it's cert to Charlie
// Alice can't renew it's cert to Charlie
...
@@ -224,40 +273,5 @@ fn test_idty_membership_expire_them_requested() {
...
@@ -224,40 +273,5 @@ fn test_idty_membership_expire_them_requested() {
Cert
::
add_cert
(
Origin
::
signed
(
1
),
3
),
Cert
::
add_cert
(
Origin
::
signed
(
1
),
3
),
pallet_certification
::
Error
::
<
Test
,
Instance1
>
::
CertNotAllowed
pallet_certification
::
Error
::
<
Test
,
Instance1
>
::
CertNotAllowed
);
);
/*// Charlie should be able to request membership
run_to_block(6);
assert_ok!(Membership::request_membership(
Origin::signed(3),
crate::MembershipMetaData(3)
));
// Charlie should re-enter in the wot immediatly
let events = System::events();
assert_eq!(events.len(), 3);
assert_eq!(
events[0],
EventRecord {
phase: Phase::Initialization,
event: Event::Membership(pallet_membership::Event::MembershipRequested(3)),
topics: vec![],
}
);
assert_eq!(
events[1],
EventRecord {
phase: Phase::Initialization,
event: Event::Membership(pallet_membership::Event::MembershipAcquired(3)),
topics: vec![],
}
);
assert_eq!(
events[2],
EventRecord {
phase: Phase::Initialization,
event: Event::Identity(pallet_identity::Event::IdtyValidated(3)),
topics: vec![],
}
);*/
});
});
}
}
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