mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 01:01:03 +00:00
Make BEEFY client keystore generic over BEEFY AuthorityId type (#2258)
This is the significant step to make BEEFY client able to handle both ECDSA and (ECDSA, BLS) type signature. The idea is having BEEFY Client generic on crypto types makes migration to new types smoother. This makes the BEEFY Keystore generic over AuthorityId and extends its tests to cover the case when the AuthorityId is of type (ECDSA, BLS12-377) --------- Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
This commit is contained in:
@@ -207,7 +207,7 @@ mod tests {
|
||||
use sc_network_test::Block;
|
||||
|
||||
use sp_consensus_beefy::{
|
||||
known_payloads::MMR_ROOT_ID, Commitment, EquivocationProof, Keyring, Payload,
|
||||
known_payloads::MMR_ROOT_ID, test_utils::Keyring, Commitment, EquivocationProof, Payload,
|
||||
SignedCommitment, ValidatorSet, VoteMessage,
|
||||
};
|
||||
|
||||
@@ -226,7 +226,7 @@ mod tests {
|
||||
#[test]
|
||||
fn round_tracker() {
|
||||
let mut rt = RoundTracker::default();
|
||||
let bob_vote = (Keyring::Bob.public(), Keyring::Bob.sign(b"I am committed"));
|
||||
let bob_vote = (Keyring::Bob.public(), Keyring::<AuthorityId>::Bob.sign(b"I am committed"));
|
||||
let threshold = 2;
|
||||
|
||||
// adding new vote allowed
|
||||
@@ -237,7 +237,8 @@ mod tests {
|
||||
// vote is not done
|
||||
assert!(!rt.is_done(threshold));
|
||||
|
||||
let alice_vote = (Keyring::Alice.public(), Keyring::Alice.sign(b"I am committed"));
|
||||
let alice_vote =
|
||||
(Keyring::Alice.public(), Keyring::<AuthorityId>::Alice.sign(b"I am committed"));
|
||||
// adding new vote (self vote this time) allowed
|
||||
assert!(rt.add_vote(alice_vote));
|
||||
|
||||
@@ -271,7 +272,11 @@ mod tests {
|
||||
assert_eq!(42, rounds.validator_set_id());
|
||||
assert_eq!(1, rounds.session_start());
|
||||
assert_eq!(
|
||||
&vec![Keyring::Alice.public(), Keyring::Bob.public(), Keyring::Charlie.public()],
|
||||
&vec![
|
||||
Keyring::<AuthorityId>::Alice.public(),
|
||||
Keyring::<AuthorityId>::Bob.public(),
|
||||
Keyring::<AuthorityId>::Charlie.public()
|
||||
],
|
||||
rounds.validators()
|
||||
);
|
||||
}
|
||||
@@ -301,7 +306,7 @@ mod tests {
|
||||
let mut vote = VoteMessage {
|
||||
id: Keyring::Alice.public(),
|
||||
commitment: commitment.clone(),
|
||||
signature: Keyring::Alice.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Alice.sign(b"I am committed"),
|
||||
};
|
||||
// add 1st good vote
|
||||
assert_eq!(rounds.add_vote(vote.clone()), VoteImportResult::Ok);
|
||||
@@ -310,26 +315,26 @@ mod tests {
|
||||
assert_eq!(rounds.add_vote(vote.clone()), VoteImportResult::Ok);
|
||||
|
||||
vote.id = Keyring::Dave.public();
|
||||
vote.signature = Keyring::Dave.sign(b"I am committed");
|
||||
vote.signature = Keyring::<AuthorityId>::Dave.sign(b"I am committed");
|
||||
// invalid vote (Dave is not a validator)
|
||||
assert_eq!(rounds.add_vote(vote.clone()), VoteImportResult::Invalid);
|
||||
|
||||
vote.id = Keyring::Bob.public();
|
||||
vote.signature = Keyring::Bob.sign(b"I am committed");
|
||||
vote.signature = Keyring::<AuthorityId>::Bob.sign(b"I am committed");
|
||||
// add 2nd good vote
|
||||
assert_eq!(rounds.add_vote(vote.clone()), VoteImportResult::Ok);
|
||||
|
||||
vote.id = Keyring::Charlie.public();
|
||||
vote.signature = Keyring::Charlie.sign(b"I am committed");
|
||||
vote.signature = Keyring::<AuthorityId>::Charlie.sign(b"I am committed");
|
||||
// add 3rd good vote -> round concluded -> signatures present
|
||||
assert_eq!(
|
||||
rounds.add_vote(vote.clone()),
|
||||
VoteImportResult::RoundConcluded(SignedCommitment {
|
||||
commitment,
|
||||
signatures: vec![
|
||||
Some(Keyring::Alice.sign(b"I am committed")),
|
||||
Some(Keyring::Bob.sign(b"I am committed")),
|
||||
Some(Keyring::Charlie.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Alice.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Bob.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Charlie.sign(b"I am committed")),
|
||||
None,
|
||||
]
|
||||
})
|
||||
@@ -337,7 +342,7 @@ mod tests {
|
||||
rounds.conclude(block_number);
|
||||
|
||||
vote.id = Keyring::Eve.public();
|
||||
vote.signature = Keyring::Eve.sign(b"I am committed");
|
||||
vote.signature = Keyring::<AuthorityId>::Eve.sign(b"I am committed");
|
||||
// Eve is a validator, but round was concluded, adding vote disallowed
|
||||
assert_eq!(rounds.add_vote(vote), VoteImportResult::Stale);
|
||||
}
|
||||
@@ -364,7 +369,7 @@ mod tests {
|
||||
let mut vote = VoteMessage {
|
||||
id: Keyring::Alice.public(),
|
||||
commitment,
|
||||
signature: Keyring::Alice.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Alice.sign(b"I am committed"),
|
||||
};
|
||||
// add vote for previous session, should fail
|
||||
assert_eq!(rounds.add_vote(vote.clone()), VoteImportResult::Stale);
|
||||
@@ -407,22 +412,22 @@ mod tests {
|
||||
let mut alice_vote = VoteMessage {
|
||||
id: Keyring::Alice.public(),
|
||||
commitment: commitment.clone(),
|
||||
signature: Keyring::Alice.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Alice.sign(b"I am committed"),
|
||||
};
|
||||
let mut bob_vote = VoteMessage {
|
||||
id: Keyring::Bob.public(),
|
||||
commitment: commitment.clone(),
|
||||
signature: Keyring::Bob.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Bob.sign(b"I am committed"),
|
||||
};
|
||||
let mut charlie_vote = VoteMessage {
|
||||
id: Keyring::Charlie.public(),
|
||||
commitment,
|
||||
signature: Keyring::Charlie.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Charlie.sign(b"I am committed"),
|
||||
};
|
||||
let expected_signatures = vec![
|
||||
Some(Keyring::Alice.sign(b"I am committed")),
|
||||
Some(Keyring::Bob.sign(b"I am committed")),
|
||||
Some(Keyring::Charlie.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Alice.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Bob.sign(b"I am committed")),
|
||||
Some(Keyring::<AuthorityId>::Charlie.sign(b"I am committed")),
|
||||
];
|
||||
|
||||
// round 1 - only 2 out of 3 vote
|
||||
@@ -484,7 +489,7 @@ mod tests {
|
||||
let alice_vote1 = VoteMessage {
|
||||
id: Keyring::Alice.public(),
|
||||
commitment: commitment1,
|
||||
signature: Keyring::Alice.sign(b"I am committed"),
|
||||
signature: Keyring::<AuthorityId>::Alice.sign(b"I am committed"),
|
||||
};
|
||||
let mut alice_vote2 = alice_vote1.clone();
|
||||
alice_vote2.commitment = commitment2;
|
||||
|
||||
Reference in New Issue
Block a user