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
4cf251fa
Unverified
Commit
4cf251fa
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
separate offences end2end tests
parent
f6083f92
No related branches found
No related tags found
1 merge request
!216
Add end2end test for offences
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
runtime/gdev/tests/integration_tests.rs
+0
-128
0 additions, 128 deletions
runtime/gdev/tests/integration_tests.rs
runtime/gdev/tests/offences_tests.rs
+150
-0
150 additions, 0 deletions
runtime/gdev/tests/offences_tests.rs
with
150 additions
and
128 deletions
runtime/gdev/tests/integration_tests.rs
+
0
−
128
View file @
4cf251fa
...
@@ -19,21 +19,15 @@ mod common;
...
@@ -19,21 +19,15 @@ mod common;
use
common
::
*
;
use
common
::
*
;
use
frame_support
::
instances
::
Instance1
;
use
frame_support
::
instances
::
Instance1
;
use
frame_support
::
traits
::
StoredMap
;
use
frame_support
::
traits
::
StoredMap
;
use
frame_support
::
traits
::
ValidatorSet
;
use
frame_support
::
traits
::
ValidatorSetWithIdentification
;
use
frame_support
::
traits
::{
Get
,
PalletInfo
,
StorageInfo
,
StorageInfoTrait
};
use
frame_support
::
traits
::{
Get
,
PalletInfo
,
StorageInfo
,
StorageInfoTrait
};
use
frame_support
::{
assert_noop
,
assert_ok
};
use
frame_support
::{
assert_noop
,
assert_ok
};
use
frame_support
::{
StorageHasher
,
Twox128
};
use
frame_support
::{
StorageHasher
,
Twox128
};
use
gdev_runtime
::
*
;
use
gdev_runtime
::
*
;
use
pallet_duniter_wot
::
IdtyRemovalWotReason
;
use
pallet_duniter_wot
::
IdtyRemovalWotReason
;
use
pallet_im_online
::
UnresponsivenessOffence
;
use
pallet_membership
::
MembershipRemovalReason
;
use
pallet_membership
::
MembershipRemovalReason
;
use
pallet_session
::
historical
::
IdentificationTuple
;
use
sp_core
::
Encode
;
use
sp_core
::
Encode
;
use
sp_keyring
::
AccountKeyring
;
use
sp_keyring
::
AccountKeyring
;
use
sp_runtime
::
traits
::
Convert
;
use
sp_runtime
::
MultiAddress
;
use
sp_runtime
::
MultiAddress
;
use
sp_staking
::
offence
::
ReportOffence
;
#[test]
#[test]
fn
verify_treasury_account
()
{
fn
verify_treasury_account
()
{
...
@@ -1313,125 +1307,3 @@ fn smith_data_problem() {
...
@@ -1313,125 +1307,3 @@ fn smith_data_problem() {
run_to_block
(
4
);
run_to_block
(
4
);
});
});
}
}
#[test]
fn
test_imonline_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
as
ValidatorSetWithIdentification
<
sp_runtime
::
AccountId32
>>
::
IdentificationOf
::
convert
(
id
.clone
()
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
offence
=
UnresponsivenessOffence
{
session_index
,
validator_set_count
,
offenders
};
let
_
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ReportUnresponsiveness
::
report_offence
(
vec!
[],
offence
);
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"im-online:offlin"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
],
},
));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
0
);
})
}
#[test]
fn
test_grandpa_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
mut
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<
Runtime
as
pallet_session
::
historical
::
Config
>
::
FullIdentificationOf
::
convert
(
id
.clone
(),
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
time_slot
=
pallet_grandpa
::
TimeSlot
{
set_id
:
0
,
round
:
0
,
};
let
offence
=
pallet_grandpa
::
EquivocationOffence
{
time_slot
,
session_index
,
validator_set_count
,
offender
:
offenders
.pop
()
.unwrap
(),
};
let
_
=
Offences
::
report_offence
(
vec!
[],
offence
);
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"grandpa:equivoca"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
}));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberAddedToBlacklist
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
1
);
})
}
#[test]
fn
test_babe_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
mut
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<
Runtime
as
pallet_session
::
historical
::
Config
>
::
FullIdentificationOf
::
convert
(
id
.clone
(),
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
offence
=
pallet_babe
::
EquivocationOffence
{
slot
:
0u64
.into
(),
session_index
,
validator_set_count
,
offender
:
offenders
.pop
()
.unwrap
(),
};
let
_
=
Offences
::
report_offence
(
vec!
[],
offence
);
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"babe:equivocatio"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
}));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberAddedToBlacklist
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
1
);
})
}
This diff is collapsed.
Click to expand it.
runtime/gdev/tests/offences_tests.rs
0 → 100644
+
150
−
0
View file @
4cf251fa
// Copyright 2021 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
mod
common
;
use
common
::
*
;
use
frame_support
::
assert_ok
;
use
frame_support
::
traits
::
ValidatorSet
;
use
frame_support
::
traits
::
ValidatorSetWithIdentification
;
use
gdev_runtime
::
*
;
use
pallet_im_online
::
UnresponsivenessOffence
;
use
pallet_session
::
historical
::
IdentificationTuple
;
use
sp_runtime
::
traits
::
Convert
;
use
sp_staking
::
offence
::
ReportOffence
;
#[test]
fn
test_imonline_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
as
ValidatorSetWithIdentification
<
sp_runtime
::
AccountId32
>>
::
IdentificationOf
::
convert
(
id
.clone
()
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
offence
=
UnresponsivenessOffence
{
session_index
,
validator_set_count
,
offenders
};
assert_ok!
(
<
Runtime
as
pallet_im_online
::
Config
>
::
ReportUnresponsiveness
::
report_offence
(
vec!
[],
offence
));
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"im-online:offlin"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
],
},
));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
0
);
})
}
#[test]
fn
test_grandpa_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
mut
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<
Runtime
as
pallet_session
::
historical
::
Config
>
::
FullIdentificationOf
::
convert
(
id
.clone
(),
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
time_slot
=
pallet_grandpa
::
TimeSlot
{
set_id
:
0
,
round
:
0
,
};
let
offence
=
pallet_grandpa
::
EquivocationOffence
{
time_slot
,
session_index
,
validator_set_count
,
offender
:
offenders
.pop
()
.unwrap
(),
};
assert_ok!
(
Offences
::
report_offence
(
vec!
[],
offence
));
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"grandpa:equivoca"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
}));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberAddedToBlacklist
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
1
);
})
}
#[test]
fn
test_babe_offence
()
{
ExtBuilder
::
new
(
1
,
3
,
4
)
.build
()
.execute_with
(||
{
run_to_block
(
1
);
let
session_index
=
Session
::
current_index
();
let
current_validators
=
<
Runtime
as
pallet_im_online
::
Config
>
::
ValidatorSet
::
validators
();
// Construct an offence where all validators (member: 1) are offenders
let
mut
offenders
=
current_validators
.into_iter
()
.enumerate
()
.filter_map
(|(
_
,
id
)|
{
<
Runtime
as
pallet_session
::
historical
::
Config
>
::
FullIdentificationOf
::
convert
(
id
.clone
(),
)
.map
(|
full_id
|
(
id
,
full_id
))
})
.collect
::
<
Vec
<
IdentificationTuple
<
Runtime
>>>
();
let
keys
=
ImOnline
::
keys
();
let
validator_set_count
=
keys
.len
()
as
u32
;
let
offence
=
pallet_babe
::
EquivocationOffence
{
slot
:
0u64
.into
(),
session_index
,
validator_set_count
,
offender
:
offenders
.pop
()
.unwrap
(),
};
assert_ok!
(
Offences
::
report_offence
(
vec!
[],
offence
));
// An offence is deposited
System
::
assert_has_event
(
RuntimeEvent
::
Offences
(
pallet_offences
::
Event
::
Offence
{
kind
:
*
b"babe:equivocatio"
,
timeslot
:
vec!
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
}));
// Offenders are punished
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberGoOffline
{
member
:
1
},
));
System
::
assert_has_event
(
RuntimeEvent
::
AuthorityMembers
(
pallet_authority_members
::
Event
::
MemberAddedToBlacklist
{
member
:
1
},
));
assert_eq!
(
AuthorityMembers
::
blacklist
()
.len
(),
1
);
})
}
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