Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
update primitive-types and solve break changes (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 authored and bkchr committed Jan 23, 2019
1 parent 9650ffb commit 9040ca9
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 99 deletions.
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 18 additions & 17 deletions core/client/db/src/cache/list_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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> {
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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) })
Expand All @@ -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();
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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) }),
Expand Down
4 changes: 2 additions & 2 deletions core/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions core/client/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,35 +339,35 @@ 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]
#[should_panic]
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]
Expand Down
14 changes: 7 additions & 7 deletions core/client/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand All @@ -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())));
}
Expand All @@ -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);
Expand All @@ -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
};

Expand Down
8 changes: 4 additions & 4 deletions core/finality-grandpa/src/finality_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ mod tests {
0 => Default::default(),
_ => header(number - 1).hash(),
};
Header::new(number, 0.into(), 0.into(), parent_hash, Default::default())
Header::new(number, H256::from_low_u64_be(0), H256::from_low_u64_be(0), parent_hash, Default::default())
}

fn side_header(number: u64) -> Header {
Header::new(number, 0.into(), 1.into(), header(number - 1).hash(), Default::default())
Header::new(number, H256::from_low_u64_be(0), H256::from_low_u64_be(1), header(number - 1).hash(), Default::default())
}

fn test_blockchain() -> InMemoryBlockchain<Block> {
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
blockchain.insert(header(5).hash(), header(5), Some(vec![5]), None, NewBlockState::Final).unwrap();

// when asking for finality of side-block 42, None is returned
let proof_of_side_4_fails = prove_finality(&blockchain, |_, _, _| Ok(vec![vec![42]]), 42.into()).is_err();
let proof_of_side_4_fails = prove_finality(&blockchain, |_, _, _| Ok(vec![vec![42]]), H256::from_low_u64_be(42)).is_err();
assert_eq!(proof_of_side_4_fails, true);
}

Expand All @@ -314,7 +314,7 @@ mod tests {
blockchain.insert(header(4).hash(), header(4), None, None, NewBlockState::Final).unwrap();

// when asking for finality of block 4, search for justification failing
let proof_of_4_fails = prove_finality(&blockchain, |_, _, _| Ok(vec![vec![42]]), 42.into()).is_err();
let proof_of_4_fails = prove_finality(&blockchain, |_, _, _| Ok(vec![vec![42]]), H256::from_low_u64_be(42)).is_err();
assert_eq!(proof_of_4_fails, true);
}

Expand Down
16 changes: 8 additions & 8 deletions core/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,18 @@ fn consensus_changes_works() {
let mut changes = ConsensusChanges::<H256, u64>::empty();

// pending changes are not finalized
changes.note_change((10, 1.into()));
assert_eq!(changes.finalize((5, 5.into()), |_| Ok(None)).unwrap(), (false, false));
changes.note_change((10, H256::from_low_u64_be(1)));
assert_eq!(changes.finalize((5, H256::from_low_u64_be(5)), |_| Ok(None)).unwrap(), (false, false));

// no change is selected from competing pending changes
changes.note_change((1, 1.into()));
changes.note_change((1, 101.into()));
assert_eq!(changes.finalize((10, 10.into()), |_| Ok(Some(1001.into()))).unwrap(), (true, false));
changes.note_change((1, H256::from_low_u64_be(1)));
changes.note_change((1, H256::from_low_u64_be(101)));
assert_eq!(changes.finalize((10, H256::from_low_u64_be(10)), |_| Ok(Some(H256::from_low_u64_be(1001)))).unwrap(), (true, false));

// change is selected from competing pending changes
changes.note_change((1, 1.into()));
changes.note_change((1, 101.into()));
assert_eq!(changes.finalize((10, 10.into()), |_| Ok(Some(1.into()))).unwrap(), (true, true));
changes.note_change((1, H256::from_low_u64_be(1)));
changes.note_change((1, H256::from_low_u64_be(101)));
assert_eq!(changes.finalize((10, H256::from_low_u64_be(10)), |_| Ok(Some(H256::from_low_u64_be(1)))).unwrap(), (true, true));
}

#[test]
Expand Down
Loading

0 comments on commit 9040ca9

Please sign in to comment.