rpc: don't include current block in new_block_filter (#7982)
This commit is contained in:
		
							parent
							
								
									5cf6684461
								
							
						
					
					
						commit
						e4f863b4b0
					
				@ -111,7 +111,8 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
 | 
			
		||||
 | 
			
		||||
	fn new_block_filter(&self) -> Result<RpcU256> {
 | 
			
		||||
		let mut polls = self.polls().lock();
 | 
			
		||||
		let id = polls.create_poll(PollFilter::Block(self.best_block_number()));
 | 
			
		||||
		// +1, since we don't want to include the current block
 | 
			
		||||
		let id = polls.create_poll(PollFilter::Block(self.best_block_number() + 1));
 | 
			
		||||
		Ok(id.into())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -129,7 +130,7 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
 | 
			
		||||
			None => Either::A(future::ok(FilterChanges::Empty)),
 | 
			
		||||
			Some(filter) => match *filter {
 | 
			
		||||
				PollFilter::Block(ref mut block_number) => {
 | 
			
		||||
					// + 1, cause we want to return hashes including current block hash.
 | 
			
		||||
					// +1, cause we want to return hashes including current block hash.
 | 
			
		||||
					let current_number = self.best_block_number() + 1;
 | 
			
		||||
					let hashes = (*block_number..current_number).into_iter()
 | 
			
		||||
						.map(BlockId::Number)
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,7 @@ use std::time::{Instant, Duration};
 | 
			
		||||
use ethereum_types::{H256, U256, Address};
 | 
			
		||||
use parking_lot::Mutex;
 | 
			
		||||
use ethcore::account_provider::AccountProvider;
 | 
			
		||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};
 | 
			
		||||
use ethcore::client::{BlockChainClient, BlockId, EachBlockWith, Executed, TestBlockChainClient, TransactionId};
 | 
			
		||||
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
 | 
			
		||||
use ethcore::miner::MinerService;
 | 
			
		||||
use ethcore::receipt::{LocalizedReceipt, TransactionOutcome};
 | 
			
		||||
@ -284,6 +284,29 @@ fn rpc_logs_filter() {
 | 
			
		||||
	assert_eq!(tester.io.handle_request_sync(request_changes2), Some(response2.to_owned()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn rpc_blocks_filter() {
 | 
			
		||||
	let tester = EthTester::default();
 | 
			
		||||
	let request_filter = r#"{"jsonrpc": "2.0", "method": "eth_newBlockFilter", "id": 1}"#;
 | 
			
		||||
	let response = r#"{"jsonrpc":"2.0","result":"0x0","id":1}"#;
 | 
			
		||||
 | 
			
		||||
	assert_eq!(tester.io.handle_request_sync(request_filter), Some(response.to_owned()));
 | 
			
		||||
 | 
			
		||||
	let request_changes = r#"{"jsonrpc": "2.0", "method": "eth_getFilterChanges", "params": ["0x0"], "id": 1}"#;
 | 
			
		||||
	let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#;
 | 
			
		||||
 | 
			
		||||
	assert_eq!(tester.io.handle_request_sync(request_changes), Some(response.to_owned()));
 | 
			
		||||
 | 
			
		||||
	tester.client.add_blocks(2, EachBlockWith::Nothing);
 | 
			
		||||
 | 
			
		||||
	let response = format!(
 | 
			
		||||
		r#"{{"jsonrpc":"2.0","result":["0x{:x}","0x{:x}"],"id":1}}"#,
 | 
			
		||||
		tester.client.block_hash(BlockId::Number(1)).unwrap(),
 | 
			
		||||
		tester.client.block_hash(BlockId::Number(2)).unwrap());
 | 
			
		||||
 | 
			
		||||
	assert_eq!(tester.io.handle_request_sync(request_changes), Some(response.to_owned()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn rpc_eth_submit_hashrate() {
 | 
			
		||||
	let tester = EthTester::default();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user