Fixed test
This commit is contained in:
parent
8dbd6f36b5
commit
416040f313
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
//! Test client.
|
//! Test client.
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
|
||||||
use util::*;
|
use util::*;
|
||||||
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
||||||
use blockchain::TreeRoute;
|
use blockchain::TreeRoute;
|
||||||
@ -54,6 +55,8 @@ pub struct TestBlockChainClient {
|
|||||||
pub execution_result: RwLock<Option<Executed>>,
|
pub execution_result: RwLock<Option<Executed>>,
|
||||||
/// Transaction receipts.
|
/// Transaction receipts.
|
||||||
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
|
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
|
||||||
|
/// Block queue size.
|
||||||
|
pub queue_size: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -90,6 +93,7 @@ impl TestBlockChainClient {
|
|||||||
code: RwLock::new(HashMap::new()),
|
code: RwLock::new(HashMap::new()),
|
||||||
execution_result: RwLock::new(None),
|
execution_result: RwLock::new(None),
|
||||||
receipts: RwLock::new(HashMap::new()),
|
receipts: RwLock::new(HashMap::new()),
|
||||||
|
queue_size: AtomicUsize::new(0),
|
||||||
};
|
};
|
||||||
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
||||||
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
||||||
@ -121,6 +125,11 @@ impl TestBlockChainClient {
|
|||||||
self.storage.write().unwrap().insert((address, position), value);
|
self.storage.write().unwrap().insert((address, position), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set block queue size for testing
|
||||||
|
pub fn set_queue_size(&self, size: usize) {
|
||||||
|
self.queue_size.store(size, AtomicOrder::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
/// Add blocks to test client.
|
/// Add blocks to test client.
|
||||||
pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
|
pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
|
||||||
let len = self.numbers.read().unwrap().len();
|
let len = self.numbers.read().unwrap().len();
|
||||||
@ -383,7 +392,7 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
|
|
||||||
fn queue_info(&self) -> BlockQueueInfo {
|
fn queue_info(&self) -> BlockQueueInfo {
|
||||||
BlockQueueInfo {
|
BlockQueueInfo {
|
||||||
verified_queue_size: 0,
|
verified_queue_size: self.queue_size.load(AtomicOrder::Relaxed),
|
||||||
unverified_queue_size: 0,
|
unverified_queue_size: 0,
|
||||||
verifying_queue_size: 0,
|
verifying_queue_size: 0,
|
||||||
max_queue_size: 0,
|
max_queue_size: 0,
|
||||||
|
@ -402,6 +402,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
// check if we're still syncing and return empty strings in that case
|
// check if we're still syncing and return empty strings in that case
|
||||||
{
|
{
|
||||||
|
//TODO: check if initial sync is complete here
|
||||||
//let sync = take_weak!(self.sync);
|
//let sync = take_weak!(self.sync);
|
||||||
if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON {
|
if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON {
|
||||||
trace!(target: "miner", "Syncing. Cannot give any work.");
|
trace!(target: "miner", "Syncing. Cannot give any work.");
|
||||||
|
@ -476,7 +476,8 @@ fn rpc_eth_compile_serpent() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn returns_no_work_if_cant_mine() {
|
fn returns_no_work_if_cant_mine() {
|
||||||
let eth_tester = EthTester::default();
|
let mut eth_tester = EthTester::default();
|
||||||
|
eth_tester.client.set_queue_size(10);
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#;
|
||||||
|
Loading…
Reference in New Issue
Block a user