mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 10:01:02 +00:00
Use array-bytes for All Array/Bytes/Hex Operations (#12190)
* Use `array-bytes` for All Array/Bytes/Hex Operations Signed-off-by: Xavier Lau <xavier@inv.cafe> * Reorder * Self Review * Format * Fix Tests * Bump `array-bytes` * Optimize large test res Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -22,7 +22,6 @@ use beefy_primitives::{
|
||||
ValidatorSet,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use hex_literal::hex;
|
||||
|
||||
use sp_core::H256;
|
||||
use sp_io::TestExternalities;
|
||||
@@ -70,9 +69,9 @@ fn should_contain_mmr_digest() {
|
||||
beefy_log(ConsensusLog::AuthoritiesChange(
|
||||
ValidatorSet::new(vec![mock_beefy_id(1), mock_beefy_id(2)], 1).unwrap()
|
||||
)),
|
||||
beefy_log(ConsensusLog::MmrRoot(
|
||||
hex!("95803defe6ea9f41e7ec6afa497064f21bfded027d8812efacbdf984e630cbdc").into()
|
||||
))
|
||||
beefy_log(ConsensusLog::MmrRoot(array_bytes::hex_n_into_unchecked(
|
||||
"95803defe6ea9f41e7ec6afa497064f21bfded027d8812efacbdf984e630cbdc"
|
||||
)))
|
||||
]
|
||||
);
|
||||
|
||||
@@ -85,15 +84,15 @@ fn should_contain_mmr_digest() {
|
||||
beefy_log(ConsensusLog::AuthoritiesChange(
|
||||
ValidatorSet::new(vec![mock_beefy_id(1), mock_beefy_id(2)], 1).unwrap()
|
||||
)),
|
||||
beefy_log(ConsensusLog::MmrRoot(
|
||||
hex!("95803defe6ea9f41e7ec6afa497064f21bfded027d8812efacbdf984e630cbdc").into()
|
||||
)),
|
||||
beefy_log(ConsensusLog::MmrRoot(array_bytes::hex_n_into_unchecked(
|
||||
"95803defe6ea9f41e7ec6afa497064f21bfded027d8812efacbdf984e630cbdc"
|
||||
))),
|
||||
beefy_log(ConsensusLog::AuthoritiesChange(
|
||||
ValidatorSet::new(vec![mock_beefy_id(3), mock_beefy_id(4)], 2).unwrap()
|
||||
)),
|
||||
beefy_log(ConsensusLog::MmrRoot(
|
||||
hex!("a73271a0974f1e67d6e9b8dd58e506177a2e556519a330796721e98279a753e2").into()
|
||||
)),
|
||||
beefy_log(ConsensusLog::MmrRoot(array_bytes::hex_n_into_unchecked(
|
||||
"a73271a0974f1e67d6e9b8dd58e506177a2e556519a330796721e98279a753e2"
|
||||
))),
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -120,11 +119,13 @@ fn should_contain_valid_leaf_data() {
|
||||
beefy_next_authority_set: BeefyNextAuthoritySet {
|
||||
id: 2,
|
||||
len: 2,
|
||||
root: hex!("9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5")
|
||||
.into(),
|
||||
root: array_bytes::hex_n_into_unchecked(
|
||||
"9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5"
|
||||
)
|
||||
},
|
||||
leaf_extra: hex!("55b8e9e1cc9f0db7776fac0ca66318ef8acfb8ec26db11e373120583e07ee648")
|
||||
.to_vec(),
|
||||
leaf_extra: array_bytes::hex2bytes_unchecked(
|
||||
"55b8e9e1cc9f0db7776fac0ca66318ef8acfb8ec26db11e373120583e07ee648"
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
@@ -143,11 +144,13 @@ fn should_contain_valid_leaf_data() {
|
||||
beefy_next_authority_set: BeefyNextAuthoritySet {
|
||||
id: 3,
|
||||
len: 2,
|
||||
root: hex!("9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5")
|
||||
.into(),
|
||||
root: array_bytes::hex_n_into_unchecked(
|
||||
"9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5"
|
||||
)
|
||||
},
|
||||
leaf_extra: hex!("55b8e9e1cc9f0db7776fac0ca66318ef8acfb8ec26db11e373120583e07ee648")
|
||||
.to_vec()
|
||||
leaf_extra: array_bytes::hex2bytes_unchecked(
|
||||
"55b8e9e1cc9f0db7776fac0ca66318ef8acfb8ec26db11e373120583e07ee648"
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -161,8 +164,9 @@ fn should_update_authorities() {
|
||||
// check current authority set
|
||||
assert_eq!(0, auth_set.id);
|
||||
assert_eq!(2, auth_set.len);
|
||||
let want: H256 =
|
||||
hex!("176e73f1bf656478b728e28dd1a7733c98621b8acf830bff585949763dca7a96").into();
|
||||
let want = array_bytes::hex_n_into_unchecked::<H256, 32>(
|
||||
"176e73f1bf656478b728e28dd1a7733c98621b8acf830bff585949763dca7a96",
|
||||
);
|
||||
assert_eq!(want, auth_set.root);
|
||||
|
||||
// next authority set should have same validators but different id
|
||||
@@ -180,8 +184,9 @@ fn should_update_authorities() {
|
||||
assert_eq!(1, auth_set.id);
|
||||
// check next auth set
|
||||
assert_eq!(2, next_auth_set.id);
|
||||
let want: H256 =
|
||||
hex!("9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5").into();
|
||||
let want = array_bytes::hex_n_into_unchecked::<H256, 32>(
|
||||
"9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5",
|
||||
);
|
||||
assert_eq!(2, next_auth_set.len);
|
||||
assert_eq!(want, next_auth_set.root);
|
||||
|
||||
@@ -195,8 +200,9 @@ fn should_update_authorities() {
|
||||
assert_eq!(2, auth_set.id);
|
||||
// check next auth set
|
||||
assert_eq!(3, next_auth_set.id);
|
||||
let want: H256 =
|
||||
hex!("9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5").into();
|
||||
let want = array_bytes::hex_n_into_unchecked::<H256, 32>(
|
||||
"9c6b2c1b0d0b25a008e6c882cc7b415f309965c72ad2b944ac0931048ca31cd5",
|
||||
);
|
||||
assert_eq!(2, next_auth_set.len);
|
||||
assert_eq!(want, next_auth_set.root);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user