From acf7c48d7e0fcd67a6a409e47827febcd330ac69 Mon Sep 17 00:00:00 2001 From: Fabio Lama Date: Wed, 23 Oct 2019 14:20:47 +0200 Subject: [PATCH] Type annotation for next_key() matching of json filter options (#11192) * type annotation for next_key matching of json filter options * rpc tests for pending transactions * mention git submodules in the readme --- README.md | 2 +- ethcore/src/miner/filter_options.rs | 8 +++---- rpc/src/v1/tests/mocked/parity.rs | 35 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b79d295f..be31c4924 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ To start Parity Ethereum as a regular user using `systemd` init: ## 4. Testing -You can run tests with the following commands: +Download the required test files: `git submodule update --init --recursive`. You can run tests with the following commands: * **All** packages ``` diff --git a/ethcore/src/miner/filter_options.rs b/ethcore/src/miner/filter_options.rs index db0e67378..ae1a206b0 100644 --- a/ethcore/src/miner/filter_options.rs +++ b/ethcore/src/miner/filter_options.rs @@ -160,8 +160,8 @@ impl<'de> Deserialize<'de> for FilterOptions { M: MapAccess<'de>, { let mut filter = FilterOptions::default(); - while let Some(key) = map.next_key()? { - match key { + while let Some(key) = map.next_key::()? { + match key.as_str() { "from" => { filter.from = map.validate_from()?; }, @@ -221,8 +221,8 @@ impl<'de> Deserialize<'de> for FilterOptions { let mut counter = 0; let mut f_op = Wrapper::O(FilterOperator::Any); - while let Some(key) = map.next_key()? { - match key { + while let Some(key) = map.next_key::()? { + match key.as_str() { "eq" => f_op = W::O(FilterOperator::Eq(map.next_value()?)), "gt" => f_op = W::O(FilterOperator::GreaterThan(map.next_value()?)), "lt" => f_op = W::O(FilterOperator::LessThan(map.next_value()?)), diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 06da1861e..05c9c97d7 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -316,7 +316,7 @@ fn rpc_parity_unsigned_transactions_count_when_signer_disabled() { } #[test] -fn rpc_parity_pending_transactions() { +fn rpc_parity_pending_transactions_without_limit_without_filter() { let deps = Dependencies::new(); let io = deps.default_client(); @@ -326,6 +326,39 @@ fn rpc_parity_pending_transactions() { assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } +#[test] +fn rpc_parity_pending_transactions_with_limit_without_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[5], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + +#[test] +fn rpc_parity_pending_transactions_without_limit_with_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[null,{"to":{"eq":"0xe8b2d01ffa0a15736b2370b6e5064f9702c891b6"},"gas":{"gt":"0x493e0"}}], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + +#[test] +fn rpc_parity_pending_transactions_with_limit_with_filter() { + let deps = Dependencies::new(); + let io = deps.default_client(); + + let request = r#"{"jsonrpc": "2.0", "method": "parity_pendingTransactions", "params":[5,{"to":{"eq":"0xe8b2d01ffa0a15736b2370b6e5064f9702c891b6"},"gas":{"gt":"0x493e0"}}], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} + #[test] fn rpc_parity_encrypt() { let deps = Dependencies::new();