|
17 | 17 | //! Tests for the aux-schema of approval voting. |
18 | 18 |
|
19 | 19 | use super::*; |
20 | | -use std::cell::RefCell; |
| 20 | +use crate::tests::TestStore; |
21 | 21 | use polkadot_primitives::v1::Id as ParaId; |
22 | 22 |
|
23 | | -#[derive(Default)] |
24 | | -struct TestStore { |
25 | | - inner: RefCell<HashMap<Vec<u8>, Vec<u8>>>, |
26 | | -} |
27 | | - |
28 | | -impl AuxStore for TestStore { |
29 | | - fn insert_aux<'a, 'b: 'a, 'c: 'a, I, D>(&self, insertions: I, deletions: D) -> sp_blockchain::Result<()> |
30 | | - where I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]> |
31 | | - { |
32 | | - let mut store = self.inner.borrow_mut(); |
33 | | - |
34 | | - // insertions before deletions. |
35 | | - for (k, v) in insertions { |
36 | | - store.insert(k.to_vec(), v.to_vec()); |
37 | | - } |
38 | | - |
39 | | - for k in deletions { |
40 | | - store.remove(&k[..]); |
41 | | - } |
42 | | - |
43 | | - Ok(()) |
44 | | - } |
45 | | - |
46 | | - fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> { |
47 | | - Ok(self.inner.borrow().get(key).map(|v| v.clone())) |
48 | | - } |
49 | | -} |
50 | | - |
51 | 23 | impl TestStore { |
52 | | - fn write_stored_blocks(&self, range: StoredBlockRange) { |
| 24 | + pub(crate) fn write_stored_blocks(&self, range: StoredBlockRange) { |
53 | 25 | self.inner.borrow_mut().insert( |
54 | 26 | STORED_BLOCKS_KEY.to_vec(), |
55 | 27 | range.encode(), |
56 | 28 | ); |
57 | 29 | } |
58 | 30 |
|
59 | | - fn write_blocks_at_height(&self, height: BlockNumber, blocks: &[Hash]) { |
| 31 | + pub(crate) fn write_blocks_at_height(&self, height: BlockNumber, blocks: &[Hash]) { |
60 | 32 | self.inner.borrow_mut().insert( |
61 | 33 | blocks_at_height_key(height).to_vec(), |
62 | 34 | blocks.encode(), |
63 | 35 | ); |
64 | 36 | } |
65 | 37 |
|
66 | | - fn write_block_entry(&self, block_hash: &Hash, entry: &BlockEntry) { |
| 38 | + pub(crate) fn write_block_entry(&self, block_hash: &Hash, entry: &BlockEntry) { |
67 | 39 | self.inner.borrow_mut().insert( |
68 | 40 | block_entry_key(block_hash).to_vec(), |
69 | 41 | entry.encode(), |
70 | 42 | ); |
71 | 43 | } |
72 | 44 |
|
73 | | - fn write_candidate_entry(&self, candidate_hash: &CandidateHash, entry: &CandidateEntry) { |
| 45 | + pub(crate) fn write_candidate_entry(&self, candidate_hash: &CandidateHash, entry: &CandidateEntry) { |
74 | 46 | self.inner.borrow_mut().insert( |
75 | 47 | candidate_entry_key(candidate_hash).to_vec(), |
76 | 48 | entry.encode(), |
|
0 commit comments