mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Fix beefy mock ecdsa keys (#10854)
Compressed ECDSA keys requires to have 0x02 or 0x03 as their first byte in order to allow public key recovery. Nevertheless the test was working because of the `unwrap_or_default()` at the end of the conversion routine (i.e. the invalid keys were converted to an empty vector).
This commit is contained in:
@@ -158,9 +158,12 @@ impl pallet_session::SessionManager<u64> for MockSessionManager {
|
|||||||
|
|
||||||
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
|
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
|
||||||
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
|
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
|
||||||
// ed25519 and sr25519 but *not* for ecdsa. An ecdsa public key is 33 bytes.
|
// ed25519 and sr25519 but *not* for ecdsa. A compressed ecdsa public key is 33 bytes,
|
||||||
|
// with the first one containing information to reconstruct the uncompressed key.
|
||||||
pub fn mock_beefy_id(id: u8) -> BeefyId {
|
pub fn mock_beefy_id(id: u8) -> BeefyId {
|
||||||
let buf: [u8; 33] = [id; 33];
|
let mut buf: [u8; 33] = [id; 33];
|
||||||
|
// Set to something valid.
|
||||||
|
buf[0] = 0x02;
|
||||||
let pk = Public::from_raw(buf);
|
let pk = Public::from_raw(buf);
|
||||||
BeefyId::from(pk)
|
BeefyId::from(pk)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ fn should_contain_mmr_digest() {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
System::digest().logs,
|
System::digest().logs,
|
||||||
vec![beefy_log(ConsensusLog::MmrRoot(
|
vec![beefy_log(ConsensusLog::MmrRoot(
|
||||||
hex!("f3e3afbfa69e89cd1e99f8d3570155962f3346d1d8758dc079be49ef70387758").into()
|
hex!("969d516e5279540ef38e4a710fb0645cab4c3b01e528be7285b85ec9c5fb55c8").into()
|
||||||
))]
|
))]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -82,13 +82,13 @@ fn should_contain_mmr_digest() {
|
|||||||
System::digest().logs,
|
System::digest().logs,
|
||||||
vec![
|
vec![
|
||||||
beefy_log(ConsensusLog::MmrRoot(
|
beefy_log(ConsensusLog::MmrRoot(
|
||||||
hex!("f3e3afbfa69e89cd1e99f8d3570155962f3346d1d8758dc079be49ef70387758").into()
|
hex!("969d516e5279540ef38e4a710fb0645cab4c3b01e528be7285b85ec9c5fb55c8").into()
|
||||||
)),
|
)),
|
||||||
beefy_log(ConsensusLog::AuthoritiesChange(
|
beefy_log(ConsensusLog::AuthoritiesChange(
|
||||||
ValidatorSet::new(vec![mock_beefy_id(3), mock_beefy_id(4),], 1,).unwrap()
|
ValidatorSet::new(vec![mock_beefy_id(3), mock_beefy_id(4),], 1,).unwrap()
|
||||||
)),
|
)),
|
||||||
beefy_log(ConsensusLog::MmrRoot(
|
beefy_log(ConsensusLog::MmrRoot(
|
||||||
hex!("7d4ae4524bae75d52b63f08eab173b0c263eb95ae2c55c3a1d871241bd0cc559").into()
|
hex!("8c42b7b040d262f7f2e26abeb61ab0c3c448f60c7f2f19e6ca0035d9bb3ae7e2").into()
|
||||||
)),
|
)),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -111,7 +111,7 @@ fn should_contain_valid_leaf_data() {
|
|||||||
beefy_next_authority_set: BeefyNextAuthoritySet {
|
beefy_next_authority_set: BeefyNextAuthoritySet {
|
||||||
id: 1,
|
id: 1,
|
||||||
len: 2,
|
len: 2,
|
||||||
root: hex!("01b1a742589773fc054c8f5021a456316ffcec0370b25678b0696e116d1ef9ae")
|
root: hex!("176e73f1bf656478b728e28dd1a7733c98621b8acf830bff585949763dca7a96")
|
||||||
.into(),
|
.into(),
|
||||||
},
|
},
|
||||||
parachain_heads: hex!(
|
parachain_heads: hex!(
|
||||||
|
|||||||
@@ -122,9 +122,12 @@ impl pallet_session::SessionManager<u64> for MockSessionManager {
|
|||||||
|
|
||||||
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
|
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
|
||||||
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
|
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
|
||||||
// ed25519 and sr25519 but *not* for ecdsa. An ecdsa public key is 33 bytes.
|
// ed25519 and sr25519 but *not* for ecdsa. A compressed ecdsa public key is 33 bytes,
|
||||||
|
// with the first one containing information to reconstruct the uncompressed key.
|
||||||
pub fn mock_beefy_id(id: u8) -> BeefyId {
|
pub fn mock_beefy_id(id: u8) -> BeefyId {
|
||||||
let buf: [u8; 33] = [id; 33];
|
let mut buf: [u8; 33] = [id; 33];
|
||||||
|
// Set to something valid.
|
||||||
|
buf[0] = 0x02;
|
||||||
let pk = Public::from_raw(buf);
|
let pk = Public::from_raw(buf);
|
||||||
BeefyId::from(pk)
|
BeefyId::from(pk)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user