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:
Xavier Lau
2022-09-21 14:12:20 +08:00
committed by GitHub
parent e4b6f4a66d
commit 86198c5471
79 changed files with 520 additions and 510 deletions
@@ -356,7 +356,6 @@ impl sp_externalities::ExtensionStore for BasicExternalities {
#[cfg(test)]
mod tests {
use super::*;
use hex_literal::hex;
use sp_core::{
map,
storage::{well_known_keys::CODE, Storage, StorageChild},
@@ -368,10 +367,11 @@ mod tests {
ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec());
ext.set_storage(b"dog".to_vec(), b"puppy".to_vec());
ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec());
const ROOT: [u8; 32] =
hex!("39245109cef3758c2eed2ccba8d9b370a917850af3824bc8348d505df2c298fa");
let root = array_bytes::hex2bytes_unchecked(
"39245109cef3758c2eed2ccba8d9b370a917850af3824bc8348d505df2c298fa",
);
assert_eq!(&ext.storage_root(StateVersion::default())[..], &ROOT);
assert_eq!(&ext.storage_root(StateVersion::default())[..], &root);
}
#[test]
@@ -743,7 +743,6 @@ impl<'a> OverlayedExtensions<'a> {
mod tests {
use super::*;
use crate::{ext::Ext, InMemoryBackend};
use hex_literal::hex;
use sp_core::{traits::Externalities, Blake2Hasher};
use std::collections::BTreeMap;
@@ -870,10 +869,11 @@ mod tests {
let mut cache = StorageTransactionCache::default();
let mut ext = Ext::new(&mut overlay, &mut cache, &backend, None);
const ROOT: [u8; 32] =
hex!("39245109cef3758c2eed2ccba8d9b370a917850af3824bc8348d505df2c298fa");
let root = array_bytes::hex2bytes_unchecked(
"39245109cef3758c2eed2ccba8d9b370a917850af3824bc8348d505df2c298fa",
);
assert_eq!(&ext.storage_root(state_version)[..], &ROOT);
assert_eq!(&ext.storage_root(state_version)[..], &root);
}
#[test]
@@ -334,7 +334,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use hex_literal::hex;
use sp_core::{storage::ChildInfo, traits::Externalities, H256};
use sp_runtime::traits::BlakeTwo256;
@@ -346,8 +345,9 @@ mod tests {
ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec());
ext.set_storage(b"dog".to_vec(), b"puppy".to_vec());
ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec());
let root =
H256::from(hex!("ed4d8c799d996add422395a6abd7545491d40bd838d738afafa1b8a4de625489"));
let root = array_bytes::hex_n_into_unchecked::<H256, 32>(
"ed4d8c799d996add422395a6abd7545491d40bd838d738afafa1b8a4de625489",
);
assert_eq!(H256::from_slice(ext.storage_root(Default::default()).as_slice()), root);
}