rpc: Update jsonrpsee v0.15.1 (#11939)

* Bump jsonrpsee to v0.15.1

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc-servers: Adjust RpcMiddleware to WS and HTTP traits

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/author: Use `SubscriptionSink`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain: Use `SubscriptionSink`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/state:  Use `SubscriptionSink`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/finality-grandpa: Use `SubscriptionSink`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/beefy: Use `SubscriptionSink`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client: Extract RPC string result from queries

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply rust-fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix warnings

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/tests: Remove trailing comma

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Use `SubscriptionResult` for implementations

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Remove comment

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Delegate middleware calls to `RpcMiddleware`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Remove comment

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert Cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update Cargo.lock with minimal changes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Update imports for `SubscriptionResult`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply cargo fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/tests: Submit raw json requests to validate DenyUnsafe

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-08-02 20:00:18 +03:00
committed by GitHub
parent 103f770e75
commit 63f847c24f
32 changed files with 201 additions and 136 deletions
+13 -6
View File
@@ -17,8 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use assert_matches::assert_matches;
use jsonrpsee::{core::Error as JsonRpseeError, types::error::CallError};
use sc_block_builder::BlockBuilderProvider;
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
@@ -61,9 +59,18 @@ async fn deny_unsafe_works() {
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).await.unwrap();
assert_matches!(
api.call::<_, Option<BlockStats>>("dev_getBlockStats", [client.info().best_hash])
.await,
Err(JsonRpseeError::Call(CallError::Custom(err))) if err.message().contains("RPC call is unsafe to be called externally")
let best_hash = client.info().best_hash;
let best_hash_param =
serde_json::to_string(&best_hash).expect("To string must always succeed for block hashes");
let request = format!(
"{{\"jsonrpc\":\"2.0\",\"method\":\"dev_getBlockStats\",\"params\":[{}],\"id\":1}}",
best_hash_param
);
let (resp, _) = api.raw_json_request(&request).await.expect("Raw calls should succeed");
assert_eq!(
resp.result,
r#"{"jsonrpc":"2.0","error":{"code":-32601,"message":"RPC call is unsafe to be called externally"},"id":1}"#
);
}