From c2f3d2ec1c6d8030c71c57704f374ba772915196 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Wed, 22 Jan 2025 15:29:14 +0100 Subject: [PATCH] Refreshing casper-node dependency, refactoring tests for 'chain_get_era_info_by_switch_block' --- Cargo.lock | 100 ++++++------ Cargo.toml | 4 +- .../src/event_stream_server/sse_server.rs | 10 +- resources/test/rpc_schema.json | 51 +++++- rpc_sidecar/src/rpcs/chain.rs | 147 +++++++++++++----- rpc_sidecar/src/rpcs/chain/era_summary.rs | 7 +- rpc_sidecar/src/rpcs/docs.rs | 6 +- .../src/rpcs/state_get_auction_info_v2.rs | 7 +- rpc_sidecar/src/rpcs/test_utils.rs | 31 +++- rust-toolchain.toml | 2 +- 10 files changed, 253 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f9202e0..7c517db9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,9 +406,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "4.0.1" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" +checksum = "74fa05ad7d803d413eb8380983b092cbbaf9a85f151b871360e7b00cd7060b37" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -493,7 +493,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=release-2.0.0-rc6#2178ad3aad9488076b38d8de467e6d1123f4b66b" +source = "git+https://github.com/casper-network/casper-node.git?branch=dev#b1540891bdbb25d586a209afa4e2f687d397cc66" dependencies = [ "bincode", "bytes", @@ -557,7 +557,7 @@ dependencies = [ "hex_fmt", "http 0.2.12", "hyper 0.14.32", - "indexmap 2.7.0", + "indexmap 2.7.1", "itertools", "jsonschema 0.17.1", "metrics", @@ -699,7 +699,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=release-2.0.0-rc6#2178ad3aad9488076b38d8de467e6d1123f4b66b" +source = "git+https://github.com/casper-network/casper-node.git?branch=dev#b1540891bdbb25d586a209afa4e2f687d397cc66" dependencies = [ "base16", "base64 0.13.1", @@ -742,9 +742,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.9" +version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" dependencies = [ "jobserver", "libc", @@ -769,9 +769,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" +checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" dependencies = [ "clap_builder", "clap_derive", @@ -779,9 +779,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.26" +version = "4.5.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" dependencies = [ "anstream", "anstyle", @@ -913,9 +913,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" [[package]] name = "crypto-bigint" @@ -1677,18 +1677,18 @@ dependencies = [ [[package]] name = "gix-bitmap" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48b897b4bbc881aea994b4a5bbb340a04979d7be9089791304e04a9fbc66b53" +checksum = "b1db9765c69502650da68f0804e3dc2b5f8ccc6a2d104ca6c85bc40700d37540" dependencies = [ "thiserror 2.0.11", ] [[package]] name = "gix-chunk" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ffbeb3a5c0b8b84c3fe4133a6f8c82fa962f4caefe8d0762eced025d3eb4f7" +checksum = "0b1f1d8764958699dc764e3f727cef280ff4d1bd92c107bbf8acd85b30c1bd6f" dependencies = [ "thiserror 2.0.11", ] @@ -1730,9 +1730,9 @@ dependencies = [ [[package]] name = "gix-config-value" -version = "0.14.10" +version = "0.14.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49aaeef5d98390a3bcf9dbc6440b520b793d1bf3ed99317dc407b02be995b28e" +checksum = "11365144ef93082f3403471dbaa94cfe4b5e72743bdb9560719a251d439f4cee" dependencies = [ "bitflags 2.8.0", "bstr", @@ -1953,9 +1953,9 @@ dependencies = [ [[package]] name = "gix-path" -version = "0.10.13" +version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc292ef1a51e340aeb0e720800338c805975724c1dfbd243185452efd8645b7" +checksum = "c40f12bb65a8299be0cfb90fe718e3be236b7a94b434877012980863a883a99f" dependencies = [ "bstr", "gix-trace", @@ -1966,9 +1966,9 @@ dependencies = [ [[package]] name = "gix-quote" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a1e282216ec2ab2816cd57e6ed88f8009e634aec47562883c05ac8a7009a63" +checksum = "e49357fccdb0c85c0d3a3292a9f6db32d9b3535959b5471bb9624908f4a066c6" dependencies = [ "bstr", "gix-utils", @@ -2044,9 +2044,9 @@ dependencies = [ [[package]] name = "gix-sec" -version = "0.10.10" +version = "0.10.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8b876ef997a955397809a2ec398d6a45b7a55b4918f2446344330f778d14fd6" +checksum = "d84dae13271f4313f8d60a166bf27e54c968c7c33e2ffd31c48cafe5da649875" dependencies = [ "bitflags 2.8.0", "gix-path", @@ -2071,9 +2071,9 @@ dependencies = [ [[package]] name = "gix-trace" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04bdde120c29f1fc23a24d3e115aeeea3d60d8e65bab92cc5f9d90d9302eb952" +checksum = "7c396a2036920c69695f760a65e7f2677267ccf483f25046977d87e4cb2665f7" [[package]] name = "gix-traverse" @@ -2108,9 +2108,9 @@ dependencies = [ [[package]] name = "gix-utils" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba427e3e9599508ed98a6ddf8ed05493db114564e338e41f6a996d2e4790335f" +checksum = "ff08f24e03ac8916c478c8419d7d3c33393da9bb41fa4c24455d5406aeefd35f" dependencies = [ "fastrand", "unicode-normalization", @@ -2149,7 +2149,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.7.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util 0.7.13", @@ -2168,7 +2168,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.2.0", - "indexmap 2.7.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util 0.7.13", @@ -2642,9 +2642,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -2673,9 +2673,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "is_terminal_polyfill" @@ -4006,9 +4006,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.43" +version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ "bitflags 2.8.0", "errno", @@ -4237,9 +4237,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" [[package]] name = "serde" @@ -4293,11 +4293,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ - "indexmap 2.7.0", + "indexmap 2.7.1", "itoa", "memchr", "ryu", @@ -4390,9 +4390,9 @@ dependencies = [ [[package]] name = "similar" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" [[package]] name = "slab" @@ -4482,7 +4482,7 @@ dependencies = [ "futures-util", "hashlink", "hex", - "indexmap 2.7.0", + "indexmap 2.7.1", "log", "memchr", "native-tls", @@ -5427,7 +5427,7 @@ version = "4.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5afb1a60e207dca502682537fefcfd9921e71d0b83e9576060f09abc6efab23" dependencies = [ - "indexmap 2.7.0", + "indexmap 2.7.1", "serde", "serde_json", "utoipa-gen", @@ -5462,9 +5462,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744018581f9a3454a9e15beb8a33b017183f1e7c0cd170232a2d1453b23a51c4" +checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" [[package]] name = "uuid-simd" @@ -5479,9 +5479,9 @@ dependencies = [ [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vcpkg" diff --git a/Cargo.toml b/Cargo.toml index cd3f8e24..a42dbc70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ members = [ anyhow = "1" async-stream = "0.3.4" async-trait = "0.1.77" -casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc6", features = ["json-schema"]} -casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc6" } +casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "dev", features = ["json-schema"]} +casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "dev" } casper-event-sidecar = { path = "./event_sidecar", version = "1.0.0" } casper-event-types = { path = "./types", version = "1.0.0" } casper-rpc-sidecar = { path = "./rpc_sidecar", version = "1.0.0" } diff --git a/event_sidecar/src/event_stream_server/sse_server.rs b/event_sidecar/src/event_stream_server/sse_server.rs index 61ce8570..75030803 100644 --- a/event_sidecar/src/event_stream_server/sse_server.rs +++ b/event_sidecar/src/event_stream_server/sse_server.rs @@ -483,10 +483,7 @@ fn parse_url_props( Some(filter) => filter, None => return Err(create_404(enable_legacy_filters)), }; - let start_from = match parse_query(query) { - Ok(maybe_id) => maybe_id, - Err(error_response) => return Err(error_response), - }; + let start_from = parse_query(query)?; Ok((event_filter, stream_filter, start_from, is_legacy_filter)) } @@ -949,6 +946,9 @@ mod tests { )) .collect(); + let ends_with_id = Regex::new(r"\nid:\d*$").unwrap(); + let starts_with_data = Regex::new(r"^data:").unwrap(); + // Run three cases; where only a single event is duplicated, where five are duplicated, and // where the whole initial stream (except the `ApiVersion`) is duplicated. for duplicate_count in &[1, 5, NUM_INITIAL_EVENTS] { @@ -1016,8 +1016,6 @@ mod tests { let expected_data = deduplicated_event.data.clone().unwrap(); let mut received_event_str = received_event.to_string().trim().to_string(); - let ends_with_id = Regex::new(r"\nid:\d*$").unwrap(); - let starts_with_data = Regex::new(r"^data:").unwrap(); if let Some(id) = deduplicated_event.id { assert!(received_event_str.ends_with(format!("\nid:{}", id).as_str())); } else { diff --git a/resources/test/rpc_schema.json b/resources/test/rpc_schema.json index 14a0e2d4..6408a5dd 100644 --- a/resources/test/rpc_schema.json +++ b/resources/test/rpc_schema.json @@ -2332,7 +2332,7 @@ "EraInfo": { "seigniorage_allocations": [ { - "Delegator": { + "DelegatorKind": { "delegator_kind": { "PublicKey": "01e1b46a25baa8a5c28beb3c9cfb79b572effa04076f00befa57eb70b016153f18" }, @@ -2611,7 +2611,7 @@ "EraInfo": { "seigniorage_allocations": [ { - "Delegator": { + "DelegatorKind": { "delegator_kind": { "PublicKey": "01e1b46a25baa8a5c28beb3c9cfb79b572effa04076f00befa57eb70b016153f18" }, @@ -4275,6 +4275,51 @@ ], "properties": { "Delegator": { + "type": "object", + "required": [ + "amount", + "delegator_public_key", + "validator_public_key" + ], + "properties": { + "delegator_public_key": { + "description": "Delegator's public key", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "validator_public_key": { + "description": "Validator's public key", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "amount": { + "description": "Allocated amount", + "allOf": [ + { + "$ref": "#/components/schemas/U512" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Info about a seigniorage allocation for a delegator", + "type": "object", + "required": [ + "DelegatorKind" + ], + "properties": { + "DelegatorKind": { "type": "object", "required": [ "amount", @@ -4283,7 +4328,7 @@ ], "properties": { "delegator_kind": { - "description": "Delegator's public key", + "description": "Delegator kind", "allOf": [ { "$ref": "#/components/schemas/DelegatorKind" diff --git a/rpc_sidecar/src/rpcs/chain.rs b/rpc_sidecar/src/rpcs/chain.rs index 7aec0a03..faadb954 100644 --- a/rpc_sidecar/src/rpcs/chain.rs +++ b/rpc_sidecar/src/rpcs/chain.rs @@ -402,14 +402,17 @@ async fn get_era_summary_by_block( mod tests { use std::convert::TryFrom; - use crate::{ClientError, SUPPORTED_PROTOCOL_VERSION}; + use crate::{rpcs::test_utils::BinaryPortMock, ClientError, SUPPORTED_PROTOCOL_VERSION}; use casper_binary_port::{ BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, - GlobalStateEntityQualifier, GlobalStateQueryResult, InformationRequestTag, RecordId, + GlobalStateEntityQualifier, GlobalStateQueryResult, InformationRequest, + InformationRequestTag, RecordId, }; use casper_types::{ - system::auction::EraInfo, testing::TestRng, Block, BlockSignaturesV1, BlockSignaturesV2, - ChainNameDigest, SignedBlock, TestBlockBuilder, TestBlockV1Builder, + system::auction::{DelegatorKind, EraInfo, SeigniorageAllocation}, + testing::TestRng, + AsymmetricType, Block, BlockSignaturesV1, BlockSignaturesV2, ChainNameDigest, PublicKey, + SignedBlock, TestBlockBuilder, TestBlockV1Builder, U512, }; use pretty_assertions::assert_eq; use rand::Rng; @@ -602,27 +605,41 @@ mod tests { #[tokio::test] async fn should_read_block_era_info_by_switch_block() { let rng = &mut TestRng::new(); - let block = TestBlockBuilder::new().switch_block(true).build(rng); + let mut binary_port_mock = BinaryPortMock::new(); + + let block_header = TestBlockV1Builder::new() + .switch_block(true) + .build_versioned(rng) + .clone_header(); + binary_port_mock + .add_block_header_req_res( + block_header.clone(), + InformationRequest::LatestSwitchBlockHeader, + ) + .await; + let era_info = example_era_info(); + binary_port_mock + .add_era_info_req_res( + era_info.clone(), + Some(GlobalStateIdentifier::StateRootHash( + *block_header.state_root_hash(), + )), + ) + .await; - let resp = GetEraInfoBySwitchBlock::do_handle_request( - Arc::new(ValidEraSummaryMock { - block: Block::V2(block.clone()), - expect_no_block_identifier: true, - }), - None, - ) - .await - .expect("should handle request"); + let resp = GetEraInfoBySwitchBlock::do_handle_request(Arc::new(binary_port_mock), None) + .await + .expect("should handle request"); assert_eq!( resp, GetEraInfoResult { api_version: CURRENT_API_VERSION, era_summary: Some(EraSummary { - block_hash: *block.hash(), - era_id: block.era_id(), - stored_value: StoredValue::EraInfo(EraInfo::new()), - state_root_hash: *block.state_root_hash(), + block_hash: block_header.block_hash(), + era_id: block_header.era_id(), + stored_value: StoredValue::EraInfo(era_info), + state_root_hash: *block_header.state_root_hash(), merkle_proof: String::from("00000000"), }) } @@ -632,15 +649,32 @@ mod tests { #[tokio::test] async fn should_read_block_era_info_by_switch_block_with_block_id() { let rng = &mut TestRng::new(); - let block = TestBlockBuilder::new().switch_block(true).build(rng); + let mut binary_port_mock = BinaryPortMock::new(); + + let block_header = TestBlockV1Builder::new() + .switch_block(true) + .build_versioned(rng) + .clone_header(); + binary_port_mock + .add_block_header_req_res( + block_header.clone(), + InformationRequest::BlockHeader(Some(BlockIdentifier::Height(150))), + ) + .await; + let era_info = example_era_info(); + binary_port_mock + .add_era_info_req_res( + era_info.clone(), + Some(GlobalStateIdentifier::StateRootHash( + *block_header.state_root_hash(), + )), + ) + .await; let resp = GetEraInfoBySwitchBlock::do_handle_request( - Arc::new(ValidEraSummaryMock { - block: Block::V2(block.clone()), - expect_no_block_identifier: false, - }), + Arc::new(binary_port_mock), Some(GetEraInfoParams { - block_identifier: BlockIdentifier::Hash(*block.hash()), + block_identifier: BlockIdentifier::Height(150), }), ) .await @@ -651,10 +685,10 @@ mod tests { GetEraInfoResult { api_version: CURRENT_API_VERSION, era_summary: Some(EraSummary { - block_hash: *block.hash(), - era_id: block.era_id(), - stored_value: StoredValue::EraInfo(EraInfo::new()), - state_root_hash: *block.state_root_hash(), + block_hash: block_header.block_hash(), + era_id: block_header.era_id(), + stored_value: StoredValue::EraInfo(era_info), + state_root_hash: *block_header.state_root_hash(), merkle_proof: String::from("00000000"), }) } @@ -664,18 +698,21 @@ mod tests { #[tokio::test] async fn should_read_none_block_era_info_by_switch_block_for_non_switch() { let rng = &mut TestRng::new(); - let block = TestBlockBuilder::new().switch_block(false).build(rng); - - let resp = GetEraInfoBySwitchBlock::do_handle_request( - Arc::new(ValidEraSummaryMock { - block: Block::V2(block.clone()), - expect_no_block_identifier: true, - }), - None, - ) - .await - .expect("should handle request"); - + let mut binary_port_mock = BinaryPortMock::new(); + + let block_header = TestBlockV1Builder::new() + .switch_block(false) + .build_versioned(rng) + .clone_header(); + binary_port_mock + .add_block_header_req_res( + block_header.clone(), + InformationRequest::LatestSwitchBlockHeader, + ) + .await; + let resp = GetEraInfoBySwitchBlock::do_handle_request(Arc::new(binary_port_mock), None) + .await + .expect("should handle request"); assert_eq!( resp, GetEraInfoResult { @@ -788,4 +825,34 @@ mod tests { } } } + + fn example_era_info() -> EraInfo { + let delegator_amount = U512::from(1000); + let validator_amount = U512::from(2000); + let delegator_public_key = PublicKey::from_hex( + "01e1b46a25baa8a5c28beb3c9cfb79b572effa04076f00befa57eb70b016153f18", + ) + .unwrap(); + let validator_public_key = PublicKey::from_hex( + "012a1732addc639ea43a89e25d3ad912e40232156dcaa4b9edfc709f43d2fb0876", + ) + .unwrap(); + let delegator_kind = DelegatorKind::PublicKey(delegator_public_key); + let delegator = SeigniorageAllocation::delegator_kind( + delegator_kind, + validator_public_key, + delegator_amount, + ); + let validator = SeigniorageAllocation::validator( + PublicKey::from_hex( + "012a1732addc639ea43a89e25d3ad912e40232156dcaa4b9edfc709f43d2fb0876", + ) + .unwrap(), + validator_amount, + ); + let seigniorage_allocations = vec![delegator, validator]; + let mut era_info = EraInfo::new(); + *era_info.seigniorage_allocations_mut() = seigniorage_allocations; + era_info + } } diff --git a/rpc_sidecar/src/rpcs/chain/era_summary.rs b/rpc_sidecar/src/rpcs/chain/era_summary.rs index d70aab94..3d5e4f80 100644 --- a/rpc_sidecar/src/rpcs/chain/era_summary.rs +++ b/rpc_sidecar/src/rpcs/chain/era_summary.rs @@ -19,8 +19,11 @@ pub(super) static ERA_SUMMARY: Lazy = Lazy::new(|| { PublicKey::from_hex("012a1732addc639ea43a89e25d3ad912e40232156dcaa4b9edfc709f43d2fb0876") .unwrap(); let delegator_kind = DelegatorKind::PublicKey(delegator_public_key); - let delegator = - SeigniorageAllocation::delegator(delegator_kind, validator_public_key, delegator_amount); + let delegator = SeigniorageAllocation::delegator_kind( + delegator_kind, + validator_public_key, + delegator_amount, + ); let validator = SeigniorageAllocation::validator( PublicKey::from_hex("012a1732addc639ea43a89e25d3ad912e40232156dcaa4b9edfc709f43d2fb0876") .unwrap(), diff --git a/rpc_sidecar/src/rpcs/docs.rs b/rpc_sidecar/src/rpcs/docs.rs index ac23da0a..b52b1eb1 100644 --- a/rpc_sidecar/src/rpcs/docs.rs +++ b/rpc_sidecar/src/rpcs/docs.rs @@ -487,9 +487,10 @@ impl RpcWithoutParams for RpcDiscover { } mod doc_example_impls { + #[allow(deprecated)] + use casper_types::AuctionState; use casper_types::{ - account::Account, AuctionState, Deploy, EraEndV1, EraEndV2, EraReport, PublicKey, - Timestamp, Transaction, + account::Account, Deploy, EraEndV1, EraEndV2, EraReport, PublicKey, Timestamp, Transaction, }; use super::DocExample; @@ -536,6 +537,7 @@ mod doc_example_impls { } } + #[allow(deprecated)] impl DocExample for AuctionState { fn doc_example() -> &'static Self { AuctionState::example() diff --git a/rpc_sidecar/src/rpcs/state_get_auction_info_v2.rs b/rpc_sidecar/src/rpcs/state_get_auction_info_v2.rs index c28f999e..b9248176 100644 --- a/rpc_sidecar/src/rpcs/state_get_auction_info_v2.rs +++ b/rpc_sidecar/src/rpcs/state_get_auction_info_v2.rs @@ -246,6 +246,7 @@ mod tests { }, SUPPORTED_PROTOCOL_VERSION, }; + use casper_binary_port::InformationRequest; use casper_types::{ system::{ auction::{ @@ -287,7 +288,7 @@ mod tests { block_header.height(), )); binary_port_mock - .add_block_header_req_res(block_header.clone()) + .add_block_header_req_res(block_header.clone(), InformationRequest::BlockHeader(None)) .await; binary_port_mock .add_bids_fetch_res(bids.clone(), state_identifier) @@ -365,7 +366,7 @@ mod tests { let bid_kind_1 = BidKind::Validator(Box::new(validator_bid)); let bid_kinds = vec![bid_kind_1]; binary_port_mock - .add_block_header_req_res(block_header.clone()) + .add_block_header_req_res(block_header.clone(), InformationRequest::BlockHeader(None)) .await; binary_port_mock .add_bid_kinds_fetch_res(bid_kinds.clone(), state_identifier) @@ -438,7 +439,7 @@ mod tests { let bid_kind_1 = BidKind::Validator(Box::new(validator_bid)); let bid_kinds = vec![bid_kind_1]; binary_port_mock - .add_block_header_req_res(block_header.clone()) + .add_block_header_req_res(block_header.clone(), InformationRequest::BlockHeader(None)) .await; binary_port_mock .add_bid_kinds_fetch_res(bid_kinds.clone(), state_identifier) diff --git a/rpc_sidecar/src/rpcs/test_utils.rs b/rpc_sidecar/src/rpcs/test_utils.rs index b334d91a..24da20bb 100644 --- a/rpc_sidecar/src/rpcs/test_utils.rs +++ b/rpc_sidecar/src/rpcs/test_utils.rs @@ -8,7 +8,7 @@ use casper_binary_port::{ use casper_types::{ addressable_entity::EntityKindTag, bytesrepr::ToBytes, - system::auction::{Bid, BidKind, SEIGNIORAGE_RECIPIENTS_SNAPSHOT_KEY}, + system::auction::{Bid, BidKind, EraInfo, SEIGNIORAGE_RECIPIENTS_SNAPSHOT_KEY}, AddressableEntityHash, BlockHeader, CLValue, GlobalStateIdentifier, Key, KeyTag, ProtocolVersion, SemVer, StoredValue, }; @@ -31,8 +31,33 @@ impl BinaryPortMock { } } - pub async fn add_block_header_req_res(&mut self, block_header: BlockHeader) { - let get_request = InformationRequest::BlockHeader(None) + pub async fn add_era_info_req_res( + &mut self, + era_info: EraInfo, + state_identifier: Option, + ) { + let req = GlobalStateRequest::new( + state_identifier, + GlobalStateEntityQualifier::Item { + base_key: Key::EraSummary, + path: vec![], + }, + ); + let req = BinaryRequest::Get(GetRequest::State(Box::new(req))); + let stored_value = StoredValue::EraInfo(era_info); + let res = BinaryResponse::from_value( + GlobalStateQueryResult::new(stored_value, vec![]), + *PROTOCOL_VERSION, + ); + self.when_then(req, res).await; + } + + pub async fn add_block_header_req_res( + &mut self, + block_header: BlockHeader, + information_request: InformationRequest, + ) { + let get_request = information_request .try_into() .expect("should create request"); let req = BinaryRequest::Get(get_request); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4d7ea937..6d4bd803 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.83.0" +channel = "1.84.0" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] profile = "minimal" \ No newline at end of file