From 23efaeba9f586090fa3b387e4a2f080086584262 Mon Sep 17 00:00:00 2001 From: Fabien Penso Date: Sat, 27 Apr 2024 16:07:51 +0200 Subject: [PATCH 1/4] Add test for DYDX fixtures --- rpc/Cargo.toml | 1 + rpc/tests/dydx_fixtures.rs | 46 ++++++++++++ .../block_results_at_height_12791634.json | 71 +++++++++++++++++++ tendermint/src/abci/event.rs | 2 +- 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 rpc/tests/dydx_fixtures.rs create mode 100644 rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index cb40c8452..d545c5ed7 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -88,6 +88,7 @@ tracing = { version = "0.1", optional = true, default-features = false } tracing-subscriber = { version = "0.3", optional = true, default-features = false, features = ["fmt"] } [dev-dependencies] +tendermint = { version = "0.36.0", default-features = false, path = "../tendermint", features = ["secp256k1"] } http = { version = "1", default-features = false, features = ["std"] } lazy_static = { version = "1.4.0", default-features = false } tokio-test = { version = "0.4", default-features = false } diff --git a/rpc/tests/dydx_fixtures.rs b/rpc/tests/dydx_fixtures.rs new file mode 100644 index 000000000..7ef495756 --- /dev/null +++ b/rpc/tests/dydx_fixtures.rs @@ -0,0 +1,46 @@ +use std::{fs, path::PathBuf}; + +use tendermint_rpc::{endpoint, Response}; + +use walkdir::WalkDir; + +fn find_fixtures(in_out_folder_name: &str) -> Vec { + WalkDir::new( + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("dydx_fixtures") + .join(in_out_folder_name), + ) + .into_iter() + .filter_map(|e| e.ok()) + .filter(|e| { + e.file_type().is_file() + && e.path().extension().is_some() + && e.path().extension().unwrap() == "json" + }) + .map(|e| e.into_path()) + .collect::>() +} + +#[test] +fn incoming_fixtures() { + for json_file in find_fixtures("incoming") { + let file_name = json_file + .file_name() + .unwrap() + .to_str() + .unwrap() + .strip_suffix(".json") + .unwrap(); + let content = fs::read_to_string(&json_file).unwrap(); + match file_name { + "block_results_at_height_12791634" => { + let r = endpoint::block_results::v0_34::DialectResponse::from_string(content); + assert!(r.is_ok(), "block_results_at_height_12791634: {r:?}"); + }, + _ => { + panic!("unhandled incoming fixture: {file_name}"); + }, + } + } +} diff --git a/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json b/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json new file mode 100644 index 000000000..c4343f873 --- /dev/null +++ b/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json @@ -0,0 +1,71 @@ +{ + "jsonrpc": "2.0", + "id": -1, + "result": { + "height": "12791634", + "txs_results": [ + { + "code": 0, + "data": "ChAIgICAAhD///////////8BEg4IoI0GEgQIgMYKGICAQBoJCgdlZDI1NTE5IgA=", + "log": "", + "info": "", + "gas_wanted": "0", + "gas_used": "0", + "events": [], + "codespace": "" + } + ], + "finalize_block_events": [ + { + "attributes": [ + { + "key": "", + "value": "\n0/dydxprotocol.clob.MsgProposedOperationsResponse", + "index": false + } + ] + }, + { + "attributes": [ + { + "key": "", + "value": "\n2/dydxprotocol.bridge.MsgAcknowledgeBridgesResponse", + "index": false + } + ] + }, + { + "attributes": [ + { + "key": "", + "value": "\n3/dydxprotocol.perpetuals.MsgAddPremiumVotesResponse", + "index": false + } + ] + }, + { + "attributes": [ + { + "key": "", + "value": "\n2/dydxprotocol.prices.MsgUpdateMarketPricesResponse", + "index": false + } + ] + } + ], + "validator_updates": [ + { + "pub_key": { + "Sum": { + "type": "tendermint.crypto.PublicKey_Secp256K1", + "value": { + "secp256k1": "CgZzZW5kZXISK2R5ZHgxbHR5YzZ5NHNrY2x6YWZ2cHpucHQycWp3bWZ3Z3NuZHA0NThybXAYAQ==" + } + } + } + } + ], + "consensus_param_updates": null, + "app_hash": null + } +} diff --git a/tendermint/src/abci/event.rs b/tendermint/src/abci/event.rs index aafb66c27..77c034889 100644 --- a/tendermint/src/abci/event.rs +++ b/tendermint/src/abci/event.rs @@ -18,7 +18,7 @@ pub struct Event { /// /// Tendermint calls this the `type`, but we use `kind` to avoid confusion /// with Rust types and follow Rust conventions. - #[serde(rename = "type")] + #[serde(rename = "type", default)] pub kind: String, /// A list of [`EventAttribute`]s describing the event. From ee841c5e41f307afc7b9be2ba6c132827b429fa6 Mon Sep 17 00:00:00 2001 From: Fabien Penso Date: Sat, 27 Apr 2024 17:25:49 +0200 Subject: [PATCH 2/4] Fix test --- rpc/tests/dydx_fixtures.rs | 2 ++ .../incoming/block_results_at_height_12791634.json | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/rpc/tests/dydx_fixtures.rs b/rpc/tests/dydx_fixtures.rs index 7ef495756..a4994b66d 100644 --- a/rpc/tests/dydx_fixtures.rs +++ b/rpc/tests/dydx_fixtures.rs @@ -34,6 +34,8 @@ fn incoming_fixtures() { .unwrap(); let content = fs::read_to_string(&json_file).unwrap(); match file_name { + // NOTE: for the purpose of the test I emptied `validator_updates` which has another + // unrelated issue deserializing the Secp256K1 public key "block_results_at_height_12791634" => { let r = endpoint::block_results::v0_34::DialectResponse::from_string(content); assert!(r.is_ok(), "block_results_at_height_12791634: {r:?}"); diff --git a/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json b/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json index c4343f873..28be2f333 100644 --- a/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json +++ b/rpc/tests/dydx_fixtures/incoming/block_results_at_height_12791634.json @@ -54,16 +54,6 @@ } ], "validator_updates": [ - { - "pub_key": { - "Sum": { - "type": "tendermint.crypto.PublicKey_Secp256K1", - "value": { - "secp256k1": "CgZzZW5kZXISK2R5ZHgxbHR5YzZ5NHNrY2x6YWZ2cHpucHQycWp3bWZ3Z3NuZHA0NThybXAYAQ==" - } - } - } - } ], "consensus_param_updates": null, "app_hash": null From f84bfdeee49ea6055a092f3916aab6636aa8083e Mon Sep 17 00:00:00 2001 From: Fabien Penso Date: Sat, 27 Apr 2024 17:39:42 +0200 Subject: [PATCH 3/4] Fix comment --- rpc/tests/dydx_fixtures.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rpc/tests/dydx_fixtures.rs b/rpc/tests/dydx_fixtures.rs index a4994b66d..9789a3201 100644 --- a/rpc/tests/dydx_fixtures.rs +++ b/rpc/tests/dydx_fixtures.rs @@ -34,10 +34,11 @@ fn incoming_fixtures() { .unwrap(); let content = fs::read_to_string(&json_file).unwrap(); match file_name { - // NOTE: for the purpose of the test I emptied `validator_updates` which has another - // unrelated issue deserializing the Secp256K1 public key + // NOTE: for the purpose of the test I manually emptied `validator_updates` from the + // block_results, which has another unrelated issue deserializing the Secp256K1 public + // key "block_results_at_height_12791634" => { - let r = endpoint::block_results::v0_34::DialectResponse::from_string(content); + let r = endpoint::block_results::Response::from_string(content); assert!(r.is_ok(), "block_results_at_height_12791634: {r:?}"); }, _ => { From 775d001f6cf9591bb0f9808bb9a10283272bee0d Mon Sep 17 00:00:00 2001 From: Fabien Penso Date: Sat, 27 Apr 2024 17:53:42 +0200 Subject: [PATCH 4/4] Add Changelog --- .../unreleased/bug-fixes/1415-fix-optional-event-type.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/1415-fix-optional-event-type.md diff --git a/.changelog/unreleased/bug-fixes/1415-fix-optional-event-type.md b/.changelog/unreleased/bug-fixes/1415-fix-optional-event-type.md new file mode 100644 index 000000000..c2b919258 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1415-fix-optional-event-type.md @@ -0,0 +1,3 @@ +- `[tendermint-abci]` Add serde default for Event.type since it has omitempty in the Go + implementation. + ([\#1416](https://github.com/informalsystems/tendermint-rs/pull/1416))