mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 13:15:41 +00:00
update primitive-types and solve break changes (#1535)
This commit is contained in:
committed by
Bastian Köcher
parent
7c1f92b26f
commit
c0568ba3c6
+18
-17
@@ -585,6 +585,7 @@ fn read_forks<Block: BlockT, T: CacheItemT, S: Storage<Block, T>>(
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use test_client::runtime::H256;
|
||||
use runtime_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
|
||||
use runtime_primitives::traits::Header as HeaderT;
|
||||
use crate::cache::list_storage::tests::{DummyStorage, FaultyStorage, DummyTransaction};
|
||||
@@ -593,7 +594,7 @@ pub mod tests {
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
pub fn test_id(number: u64) -> ComplexBlockId<Block> {
|
||||
ComplexBlockId::new(From::from(number), number)
|
||||
ComplexBlockId::new(H256::from_low_u64_be(number), number)
|
||||
}
|
||||
|
||||
fn correct_id(number: u64) -> ComplexBlockId<Block> {
|
||||
@@ -621,7 +622,7 @@ pub mod tests {
|
||||
Header {
|
||||
parent_hash: fork_header(fork_nonce, fork_from, number - 1).hash(),
|
||||
number,
|
||||
state_root: (1 + fork_nonce).into(),
|
||||
state_root: H256::from_low_u64_be(1 + fork_nonce),
|
||||
extrinsics_root: Default::default(),
|
||||
digest: Default::default(),
|
||||
}
|
||||
@@ -640,7 +641,7 @@ pub mod tests {
|
||||
assert_eq!(ListCache::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(50, 50.into())
|
||||
.with_id(50, H256::from_low_u64_be(50))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: Some(100) })
|
||||
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: None }),
|
||||
1024, test_id(100)
|
||||
@@ -650,7 +651,7 @@ pub mod tests {
|
||||
assert_eq!(ListCache::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(50, 50.into())
|
||||
.with_id(50, H256::from_low_u64_be(50))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: Some(100) })
|
||||
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: Some(30) }),
|
||||
1024, test_id(100)
|
||||
@@ -660,7 +661,7 @@ pub mod tests {
|
||||
assert_eq!(ListCache::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(100, 100.into())
|
||||
.with_id(100, H256::from_low_u64_be(100))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: Some(100) })
|
||||
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: Some(30) }),
|
||||
1024, test_id(100)
|
||||
@@ -671,18 +672,18 @@ pub mod tests {
|
||||
assert_eq!(ListCache::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(50, 50.into())
|
||||
.with_id(50, H256::from_low_u64_be(50))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: Some(100) })
|
||||
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: Some(30) }),
|
||||
1024, test_id(100)
|
||||
).value_at_block(&ComplexBlockId::new(2.into(), 100)).unwrap(), None);
|
||||
).value_at_block(&ComplexBlockId::new(H256::from_low_u64_be(2), 100)).unwrap(), None);
|
||||
|
||||
// when block is later than last finalized block AND there are no forks AND finalized value is None
|
||||
// ---> [100] --- 200
|
||||
assert_eq!(ListCache::<_, u64, _>::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(50, 50.into())
|
||||
.with_id(50, H256::from_low_u64_be(50))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: None }),
|
||||
1024, test_id(100)
|
||||
).value_at_block(&test_id(200)).unwrap(), None);
|
||||
@@ -691,7 +692,7 @@ pub mod tests {
|
||||
assert_eq!(ListCache::new(
|
||||
DummyStorage::new()
|
||||
.with_meta(Some(test_id(100)), Vec::new())
|
||||
.with_id(50, 50.into())
|
||||
.with_id(50, H256::from_low_u64_be(50))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: Some(100) }),
|
||||
1024, test_id(100)
|
||||
).value_at_block(&test_id(200)).unwrap(), Some(100));
|
||||
@@ -1213,14 +1214,14 @@ pub mod tests {
|
||||
#[test]
|
||||
fn fork_destroy_works() {
|
||||
// when we reached finalized entry without iterations
|
||||
let storage = DummyStorage::new().with_id(100, 100.into());
|
||||
let storage = DummyStorage::new().with_id(100, H256::from_low_u64_be(100));
|
||||
let mut tx = DummyTransaction::new();
|
||||
Fork::<_, u64> { best_block: None, head: Entry { valid_from: test_id(100), value: None } }
|
||||
.destroy(&storage, &mut tx, Some(200)).unwrap();
|
||||
assert!(tx.removed_entries().is_empty());
|
||||
// when we reach finalized entry with iterations
|
||||
let storage = DummyStorage::new()
|
||||
.with_id(10, 10.into())
|
||||
.with_id(10, H256::from_low_u64_be(10))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(50)), value: Some(100) })
|
||||
.with_entry(test_id(50), StorageEntry { prev_valid_from: Some(test_id(20)), value: Some(50) })
|
||||
.with_entry(test_id(20), StorageEntry { prev_valid_from: Some(test_id(10)), value: Some(20) })
|
||||
@@ -1234,7 +1235,7 @@ pub mod tests {
|
||||
vec![test_id(100).hash, test_id(50).hash, test_id(20).hash].into_iter().collect());
|
||||
// when we reach beginning of fork before finalized block
|
||||
let storage = DummyStorage::new()
|
||||
.with_id(10, 10.into())
|
||||
.with_id(10, H256::from_low_u64_be(10))
|
||||
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(50)), value: Some(100) })
|
||||
.with_entry(test_id(50), StorageEntry { prev_valid_from: None, value: Some(50) });
|
||||
let mut tx = DummyTransaction::new();
|
||||
@@ -1303,10 +1304,10 @@ pub mod tests {
|
||||
assert_eq!(chain::is_finalized_block::<_, u64, _>(&DummyStorage::new(), &test_id(1), 100).unwrap(), false);
|
||||
// when there's different hash for this block number in the database
|
||||
assert_eq!(chain::is_finalized_block::<_, u64, _>(&DummyStorage::new()
|
||||
.with_id(1, From::from(2)), &test_id(1), 100).unwrap(), false);
|
||||
.with_id(1, H256::from_low_u64_be(2)), &test_id(1), 100).unwrap(), false);
|
||||
// when there's the same hash for this block number in the database
|
||||
assert_eq!(chain::is_finalized_block::<_, u64, _>(&DummyStorage::new()
|
||||
.with_id(1, From::from(1)), &test_id(1), 100).unwrap(), true);
|
||||
.with_id(1, H256::from_low_u64_be(1)), &test_id(1), 100).unwrap(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1356,9 +1357,9 @@ pub mod tests {
|
||||
#[test]
|
||||
fn ancient_entries_are_pruned() {
|
||||
let cache = ListCache::new(DummyStorage::new()
|
||||
.with_id(10, 10.into())
|
||||
.with_id(20, 20.into())
|
||||
.with_id(30, 30.into())
|
||||
.with_id(10, H256::from_low_u64_be(10))
|
||||
.with_id(20, H256::from_low_u64_be(20))
|
||||
.with_id(30, H256::from_low_u64_be(30))
|
||||
.with_entry(test_id(10), StorageEntry { prev_valid_from: None, value: Some(10) })
|
||||
.with_entry(test_id(20), StorageEntry { prev_valid_from: Some(test_id(10)), value: Some(20) })
|
||||
.with_entry(test_id(30), StorageEntry { prev_valid_from: Some(test_id(20)), value: Some(30) }),
|
||||
|
||||
@@ -554,7 +554,7 @@ pub(crate) mod tests {
|
||||
#[test]
|
||||
fn does_not_return_unknown_header() {
|
||||
let db = LightStorage::<Block>::new_test();
|
||||
assert!(db.header(BlockId::Hash(1.into())).unwrap().is_none());
|
||||
assert!(db.header(BlockId::Hash(Hash::from_low_u64_be(1))).unwrap().is_none());
|
||||
assert!(db.header(BlockId::Number(0)).unwrap().is_none());
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ pub(crate) mod tests {
|
||||
let genesis_hash = insert_block(&db, None, || default_header(&Default::default(), 0));
|
||||
assert_eq!(db.status(BlockId::Hash(genesis_hash)).unwrap(), BlockStatus::InChain);
|
||||
assert_eq!(db.status(BlockId::Number(0)).unwrap(), BlockStatus::InChain);
|
||||
assert_eq!(db.status(BlockId::Hash(1.into())).unwrap(), BlockStatus::Unknown);
|
||||
assert_eq!(db.status(BlockId::Hash(Hash::from_low_u64_be(1))).unwrap(), BlockStatus::Unknown);
|
||||
assert_eq!(db.status(BlockId::Number(1)).unwrap(), BlockStatus::Unknown);
|
||||
}
|
||||
|
||||
|
||||
@@ -339,20 +339,20 @@ mod tests {
|
||||
#[test]
|
||||
fn build_pairs_fails_when_no_enough_blocks() {
|
||||
assert!(build_pairs::<Header, _>(SIZE, 0,
|
||||
::std::iter::repeat_with(|| Ok(Some(1.into()))).take(SIZE as usize / 2)).is_err());
|
||||
::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize / 2)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_pairs_fails_when_missing_block() {
|
||||
assert!(build_pairs::<Header, _>(SIZE, 0, ::std::iter::repeat_with(|| Ok(Some(1.into()))).take(SIZE as usize / 2)
|
||||
assert!(build_pairs::<Header, _>(SIZE, 0, ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize / 2)
|
||||
.chain(::std::iter::once(Ok(None)))
|
||||
.chain(::std::iter::repeat_with(|| Ok(Some(2.into()))).take(SIZE as usize / 2 - 1))).is_err());
|
||||
.chain(::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(2)))).take(SIZE as usize / 2 - 1))).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compute_root_works() {
|
||||
assert!(compute_root::<Header, Blake2Hasher, _>(SIZE, 42,
|
||||
::std::iter::repeat_with(|| Ok(Some(1.into()))).take(SIZE as usize)).is_ok());
|
||||
::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -360,14 +360,14 @@ mod tests {
|
||||
fn build_proof_panics_when_querying_wrong_block() {
|
||||
assert!(build_proof::<Header, Blake2Hasher, _, _>(
|
||||
SIZE, 0, vec![(SIZE * 1000) as u64],
|
||||
::std::iter::repeat_with(|| Ok(Some(1.into()))).take(SIZE as usize)).is_err());
|
||||
::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_proof_works() {
|
||||
assert!(build_proof::<Header, Blake2Hasher, _, _>(
|
||||
SIZE, 0, vec![(SIZE / 2) as u64],
|
||||
::std::iter::repeat_with(|| Ok(Some(1.into()))).take(SIZE as usize)).is_ok());
|
||||
::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -213,10 +213,10 @@ mod tests {
|
||||
(vec![2], Some(vec![3])),
|
||||
(vec![3], None),
|
||||
];
|
||||
notifications.trigger(&1.into(), changeset.into_iter());
|
||||
notifications.trigger(&Hash::from_low_u64_be(1), changeset.into_iter());
|
||||
|
||||
// then
|
||||
assert_eq!(recv.next().unwrap(), Ok((1.into(), vec![
|
||||
assert_eq!(recv.next().unwrap(), Ok((Hash::from_low_u64_be(1), vec![
|
||||
(StorageKey(vec![2]), Some(StorageData(vec![3]))),
|
||||
(StorageKey(vec![3]), None),
|
||||
].into())));
|
||||
@@ -234,13 +234,13 @@ mod tests {
|
||||
(vec![2], Some(vec![3])),
|
||||
(vec![1], None),
|
||||
];
|
||||
notifications.trigger(&1.into(), changeset.into_iter());
|
||||
notifications.trigger(&Hash::from_low_u64_be(1), changeset.into_iter());
|
||||
|
||||
// then
|
||||
assert_eq!(recv1.next().unwrap(), Ok((1.into(), vec![
|
||||
assert_eq!(recv1.next().unwrap(), Ok((Hash::from_low_u64_be(1), vec![
|
||||
(StorageKey(vec![1]), None),
|
||||
].into())));
|
||||
assert_eq!(recv2.next().unwrap(), Ok((1.into(), vec![
|
||||
assert_eq!(recv2.next().unwrap(), Ok((Hash::from_low_u64_be(1), vec![
|
||||
(StorageKey(vec![2]), Some(StorageData(vec![3]))),
|
||||
].into())));
|
||||
}
|
||||
@@ -262,7 +262,7 @@ mod tests {
|
||||
(vec![2], Some(vec![3])),
|
||||
(vec![1], None),
|
||||
];
|
||||
notifications.trigger(&1.into(), changeset.into_iter());
|
||||
notifications.trigger(&Hash::from_low_u64_be(1), changeset.into_iter());
|
||||
|
||||
// then
|
||||
assert_eq!(notifications.listeners.len(), 0);
|
||||
@@ -278,7 +278,7 @@ mod tests {
|
||||
|
||||
// when
|
||||
let changeset = vec![];
|
||||
notifications.trigger(&1.into(), changeset.into_iter());
|
||||
notifications.trigger(&Hash::from_low_u64_be(1), changeset.into_iter());
|
||||
recv
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user