From 68e24d4cc1efec9d89789e22e9b13f3d3cc1937f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 24 Sep 2021 14:16:19 +1000 Subject: [PATCH] Fix camelCase --- .../execution_layer/src/engine_api/http.rs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index eb638b6a5f..99ded08f1a 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -9,6 +9,9 @@ use serde_json::json; use std::time::Duration; use types::{execution_payload::serde_logs_bloom, EthSpec, FixedVector, Transaction, VariableList}; +const STATIC_ID: u32 = 1; +const JSONRPC_VERSION: &str = "2.0"; + const ETH_SYNCING: &str = "eth_syncing"; const ETH_SYNCING_TIMEOUT: Duration = Duration::from_millis(250); @@ -47,10 +50,10 @@ impl HttpJsonRpc { timeout: Duration, ) -> Result { let body = JsonRequestBody { - jsonrpc: "2.0", + jsonrpc: JSONRPC_VERSION, method: method, params, - id: 1, + id: STATIC_ID, }; let body: JsonResponseBody = self @@ -183,7 +186,7 @@ impl EngineApi for HttpJsonRpc { } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename = "camelCase")] +#[serde(rename_all = "camelCase")] struct JsonRequestBody<'a> { jsonrpc: &'a str, method: &'a str, @@ -192,7 +195,7 @@ struct JsonRequestBody<'a> { } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename = "camelCase")] +#[serde(rename_all = "camelCase")] struct JsonResponseBody { jsonrpc: String, error: Option, @@ -201,7 +204,7 @@ struct JsonResponseBody { } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename = "camelCase")] +#[serde(rename_all = "camelCase")] struct JsonPreparePayloadRequest { parent_hash: Hash256, #[serde(with = "eth2_serde_utils::u64_hex_be")] @@ -211,7 +214,7 @@ struct JsonPreparePayloadRequest { } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(transparent, rename = "camelCase")] +#[serde(transparent, rename_all = "camelCase")] struct JsonPreparePayloadResponse { #[serde(with = "eth2_serde_utils::u64_hex_be")] payload_id: u64, @@ -283,14 +286,14 @@ impl From> for ExecutionPayload { } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename = "camelCase")] +#[serde(rename_all = "camelCase")] struct JsonConsensusValidatedRequest { block_hash: Hash256, status: ConsensusStatus, } #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename = "camelCase")] +#[serde(rename_all = "camelCase")] struct JsonForkChoiceUpdatedRequest { head_block_hash: Hash256, finalized_block_hash: Hash256, @@ -345,6 +348,9 @@ mod test { } } + const HASH_00: &str = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const HASH_01: &str = "0x0101010101010101010101010101010101010101010101010101010101010101"; + #[tokio::test] async fn forkchoice_updated_request() { Tester::new() @@ -354,7 +360,15 @@ mod test { .forkchoice_updated(Hash256::repeat_byte(0), Hash256::repeat_byte(1)) .await; }, - json!("meow"), + json!({ + "id": STATIC_ID, + "jsonrpc": JSONRPC_VERSION, + "method": ENGINE_FORKCHOICE_UPDATED, + "params": [{ + "headBlockHash": HASH_00, + "finalizedBlockHash": HASH_01, + }] + }), ) .await; }