Skip to content

Commit

Permalink
Remove unwrap in state_get_auction_info
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-casper committed May 9, 2024
1 parent e91a4e0 commit 29af67d
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions rpc_sidecar/src/rpcs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ impl RpcWithOptionalParams for GetAuctionInfo {
maybe_params: Option<Self::OptionalRequestParams>,
) -> Result<Self::ResponseResult, RpcError> {
let block_identifier = maybe_params.map(|params| params.block_identifier);
let block_header = node_client
.read_block_header(block_identifier)
.await
.map_err(|err| Error::NodeRequest("block header", err))?
.unwrap();
let block_header = common::get_block_header(&*node_client, block_identifier).await?;

let state_identifier = block_identifier.map(GlobalStateIdentifier::from);
let legacy_bid_stored_values = node_client
Expand Down Expand Up @@ -1128,8 +1124,8 @@ mod tests {
global_state::{TrieMerkleProof, TrieMerkleProofStep},
system::auction::{Bid, BidKind, ValidatorBid},
testing::TestRng,
AccessRights, AddressableEntity, Block, ByteCodeHash, EntityKind, PackageHash,
ProtocolVersion, TestBlockBuilder, TransactionRuntime,
AccessRights, AddressableEntity, AvailableBlockRange, Block, ByteCodeHash, EntityKind,
PackageHash, ProtocolVersion, TestBlockBuilder, TransactionRuntime,
};
use pretty_assertions::assert_eq;
use rand::Rng;
Expand Down Expand Up @@ -1351,6 +1347,50 @@ mod tests {
);
}

#[tokio::test]
async fn should_fail_auction_info_when_block_not_found() {
struct ClientMock;

#[async_trait]
impl NodeClient for ClientMock {
async fn send_request(
&self,
req: BinaryRequest,
) -> Result<BinaryResponseAndRequest, ClientError> {
match req {
BinaryRequest::Get(GetRequest::Information { info_type_tag, .. })
if InformationRequestTag::try_from(info_type_tag)
== Ok(InformationRequestTag::BlockHeader) =>
{
Ok(BinaryResponseAndRequest::new(
BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION),
&[],
))
}
BinaryRequest::Get(GetRequest::Information { info_type_tag, .. })
if InformationRequestTag::try_from(info_type_tag)
== Ok(InformationRequestTag::AvailableBlockRange) =>
{
Ok(BinaryResponseAndRequest::new(
BinaryResponse::from_value(
AvailableBlockRange::RANGE_0_0,
SUPPORTED_PROTOCOL_VERSION,
),
&[],
))
}
req => unimplemented!("unexpected request: {:?}", req),
}
}
}

let err = GetAuctionInfo::do_handle_request(Arc::new(ClientMock), None)
.await
.expect_err("should reject request");

assert_eq!(err.code(), ErrorCode::NoSuchBlock as i64);
}

#[tokio::test]
async fn should_read_entity() {
use casper_types::addressable_entity::{ActionThresholds, AssociatedKeys};
Expand Down

0 comments on commit 29af67d

Please sign in to comment.