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

Commit 657653a

Browse files
committed
move TestStore to main tests file
1 parent 508cb9c commit 657653a

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

node/core/approval-voting/src/aux_schema/tests.rs

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,60 +17,32 @@
1717
//! Tests for the aux-schema of approval voting.
1818
1919
use super::*;
20-
use std::cell::RefCell;
20+
use crate::tests::TestStore;
2121
use polkadot_primitives::v1::Id as ParaId;
2222

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-
5123
impl TestStore {
52-
fn write_stored_blocks(&self, range: StoredBlockRange) {
24+
pub(crate) fn write_stored_blocks(&self, range: StoredBlockRange) {
5325
self.inner.borrow_mut().insert(
5426
STORED_BLOCKS_KEY.to_vec(),
5527
range.encode(),
5628
);
5729
}
5830

59-
fn write_blocks_at_height(&self, height: BlockNumber, blocks: &[Hash]) {
31+
pub(crate) fn write_blocks_at_height(&self, height: BlockNumber, blocks: &[Hash]) {
6032
self.inner.borrow_mut().insert(
6133
blocks_at_height_key(height).to_vec(),
6234
blocks.encode(),
6335
);
6436
}
6537

66-
fn write_block_entry(&self, block_hash: &Hash, entry: &BlockEntry) {
38+
pub(crate) fn write_block_entry(&self, block_hash: &Hash, entry: &BlockEntry) {
6739
self.inner.borrow_mut().insert(
6840
block_entry_key(block_hash).to_vec(),
6941
entry.encode(),
7042
);
7143
}
7244

73-
fn write_candidate_entry(&self, candidate_hash: &CandidateHash, entry: &CandidateEntry) {
45+
pub(crate) fn write_candidate_entry(&self, candidate_hash: &CandidateHash, entry: &CandidateEntry) {
7446
self.inner.borrow_mut().insert(
7547
candidate_entry_key(candidate_hash).to_vec(),
7648
entry.encode(),

node/core/approval-voting/src/tests.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use super::*;
1818

1919
use parking_lot::Mutex;
20+
use std::cell::RefCell;
2021
use std::pin::Pin;
2122
use std::sync::Arc;
2223

@@ -97,7 +98,33 @@ impl MockClockInner {
9798

9899
// TODO [now]: mock `AssignmentCriteria` implementation.
99100

100-
// TODO [now]: mock `AuxStore`.
101+
#[derive(Default)]
102+
pub(crate) struct TestStore {
103+
pub(crate) inner: RefCell<HashMap<Vec<u8>, Vec<u8>>>,
104+
}
105+
106+
impl AuxStore for TestStore {
107+
fn insert_aux<'a, 'b: 'a, 'c: 'a, I, D>(&self, insertions: I, deletions: D) -> sp_blockchain::Result<()>
108+
where I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]>
109+
{
110+
let mut store = self.inner.borrow_mut();
111+
112+
// insertions before deletions.
113+
for (k, v) in insertions {
114+
store.insert(k.to_vec(), v.to_vec());
115+
}
116+
117+
for k in deletions {
118+
store.remove(&k[..]);
119+
}
120+
121+
Ok(())
122+
}
123+
124+
fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
125+
Ok(self.inner.borrow().get(key).map(|v| v.clone()))
126+
}
127+
}
101128

102129
#[test]
103130
fn rejects_bad_assignment() {

0 commit comments

Comments
 (0)