Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RPC error on starknet_getBlockTransactionCount #497

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl JsonRpcHandler {
let num_trans_count = self.api.starknet.read().await.get_block_txs_count(block_id.as_ref());
match num_trans_count {
Ok(count) => Ok(StarknetResponse::BlockTransactionCount(count).into()),
Err(_) => Err(ApiError::NoBlocks),
Err(_) => Err(ApiError::BlockNotFound),
}
}

Expand Down
35 changes: 35 additions & 0 deletions crates/starknet-devnet/tests/test_get_block_txs_count.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pub mod common;

mod get_block_txs_count_tests {

use starknet_rs_core::types::{BlockId, BlockTag, StarknetError};
use starknet_rs_providers::{Provider, ProviderError};

use crate::common::background_devnet::BackgroundDevnet;

#[tokio::test]
async fn test_invalid_block() {
let devnet = BackgroundDevnet::spawn().await.expect("Could not start Devnet");

let res = devnet
.json_rpc_client
.get_block_transaction_count(BlockId::Number(9000000000))
.await
.unwrap_err();
match res {
ProviderError::StarknetError(StarknetError::BlockNotFound) => (),
_ => panic!("Invalid error: {res:?}"),
}
}

#[tokio::test]
async fn test_valid_block() {
let devnet = BackgroundDevnet::spawn().await.expect("Could not start Devnet");

devnet
.json_rpc_client
.get_block_transaction_count(BlockId::Tag(BlockTag::Latest))
.await
.unwrap();
}
}