Skip to content

Commit

Permalink
chore: Cleanup the new test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-l committed Apr 8, 2024
1 parent 32fa232 commit 886cbfc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 52 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions crates/core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ pub struct BeerusClient {

impl BeerusClient {
pub async fn new(config: &Config) -> Result<Self> {
// TODO Remove
tracing::info!("STARTING {:?}", config);


#[cfg(not(target_arch = "wasm32"))]
let mut helios_client: Client<FileDB> = config.to_helios_client().await;
#[cfg(target_arch = "wasm32")]
Expand All @@ -137,8 +141,8 @@ impl BeerusClient {
.await
.context("failed to fetch syncing status")?
{
debug!("{} syncing: head={}", config.network, sync.highest_block);
thread::sleep(time::Duration::from_secs(1));
info!("{} syncing: head={}", config.network, sync.highest_block);
thread::sleep(time::Duration::from_millis(300));
}

get_starknet_state_root(
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const DEFAULT_POLL_SECS: u64 = 5;
pub const DEFAULT_FEE_TOKEN_ADDR: &str =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
const DEFAULT_IP_V4_ADDR: &str = "127.0.0.1";
const DEFAULT_PORT: u16 = 3030;
pub const DEFAULT_PORT: u16 = 3030;

// mainnet constants
pub const MAINNET_CC_ADDRESS: &str = "c662c410C0ECf747543f5bA90660f6ABeBD9C8c4";
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tracing.workspace = true
env_logger = "0.11"
serde_json = "1.0"
reqwest = "0.11.13"
tokio = { version = "1", features = ["sync", "macros", "rt", "time"] }
tokio = { version = "1", features = ["sync", "macros", "rt", "time"] }
tokio-retry = "0.3"
7 changes: 7 additions & 0 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ impl BeerusRpc {
}

pub async fn run(self) -> Result<(SocketAddr, ServerHandle), RunError> {
// TODO REMOVE
tracing::error!("Version check..");
println!("OK");

self.check_spec_version(SPEC_VERION).await?;

// TODO REMOVE
tracing::error!("Version check passed");

let server =
ServerBuilder::default().build(self.beerus.config.rpc_addr).await?;

Expand Down
80 changes: 32 additions & 48 deletions crates/rpc/tests/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// These tests need Beerus to run in the background, hence why they're hidden behing the following feature.
#![cfg(feature = "integration-tests")]
/*
TODO As expected, these states aren't as reliable as I hoped because to state changes.
I see two possible ways to tackle this:
* retries
* maybe work on "mature" blocks, 100 below the latest to limit state changes?
*/

use tokio_retry::Retry;
use std::{format, sync::Once};
use beerus_core::{
config::Config,
client::BeerusClient,
};
use beerus_rpc::BeerusRpc;
use reqwest::Url;
use starknet::{
core::types::{
BlockHashAndNumber, BlockId, BlockTag, BlockWithTxHashes, BlockWithTxs,
BroadcastedInvokeTransactionV3, BroadcastedTransaction,
DeclareTransaction, DeployAccountTransaction, Event, EventFilter,
FieldElement, FunctionCall, InvokeTransaction,
FieldElement, InvokeTransaction,
MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs,
MaybePendingTransactionReceipt, SimulationFlagForEstimateFee,
Transaction, TransactionExecutionStatus, TransactionReceipt,
MaybePendingTransactionReceipt,
Transaction, TransactionReceipt,
},
providers::{
jsonrpc::HttpTransport, JsonRpcClient, Provider, ProviderError,
Expand Down Expand Up @@ -160,27 +161,12 @@ impl L2ClientExt for JsonRpcClient<HttpTransport> {
}
}

// TODO
#[ignore = "draft"]
#[tokio::test]
async fn test_block_hash_and_number() {
let TestContext { client, block, block_id: _, extracted_value: () } =
latest_block_context().await;

let BlockHashAndNumber { block_hash, block_number } = client
.block_hash_and_number()
.await
.expect("Failed to retrieve the latest hash & block number");
assert_eq!(block_number, block.block_number);
assert_eq!(block_hash, block.block_hash);
}

#[tokio::test]
async fn test_block_number() {
let TestContext { client, block, block_id: _, extracted_value: () } =
latest_block_context().await;

// TODO In the case the block just changed, retry
let block_number = client
.block_number()
.await
Expand All @@ -193,7 +179,6 @@ async fn test_chain_id() {
let TestContext { client, block: _, block_id: _, extracted_value: () } =
latest_block_context().await;

// TODO Assertion?
client.chain_id().await.expect("Failed to retrieve the chain ID");
}

Expand Down Expand Up @@ -266,15 +251,16 @@ async fn test_get_class() {
Transaction::Declare(DeclareTransaction::V3(declare)) => {
Some(declare.class_hash)
}
// TODO Make the match exhaustive to make dep upgrades more reliable.
_ => None,
}
})
})
.await;

// TODO Assertions?
client.get_class(block_id, extracted_value).await.expect("getClass failed");
client
.get_class(block_id, extracted_value)
.await
.expect("getClass failed");
}

#[tokio::test]
Expand All @@ -286,7 +272,6 @@ async fn test_get_class_at() {
Transaction::DeployAccount(
DeployAccountTransaction::V3(deploy),
) => Some(deploy.transaction_hash),
// TODO Make the match exhaustive to make dep upgrades more reliable.
_ => None,
}
})
Expand Down Expand Up @@ -321,7 +306,6 @@ async fn test_get_class_hash_at() {
Transaction::DeployAccount(
DeployAccountTransaction::V3(deploy),
) => Some(deploy.transaction_hash),
// TODO Make the match exhaustive to make dep upgrades more reliable.
_ => None,
}
})
Expand Down Expand Up @@ -360,7 +344,6 @@ async fn test_get_nonce() {
Transaction::Invoke(InvokeTransaction::V3(invoke)) => {
Some((invoke.nonce, invoke.sender_address))
}
// TODO Make the match exhaustive to make dep upgrades more reliable.
_ => None,
}
})
Expand Down Expand Up @@ -483,19 +466,20 @@ async fn test_get_transaction_status() {
}

/* TODO
Add more test scenarios to cover the following methods:
starknet_call
starknet_estimateFee
starknet_estimateFeeSingle
starknet_getBalance
starknet_getEvents
starknet_getProof
starknet_getStateRoot
starknet_getStateUpdate
starknet_getStorateAt
starknet_getTransactionReceipt
starknet_getTransactionStatus
starknet_syncing
pathfinder_getProof
*/
Add more test scenarios to cover the following methods:
starknet_block_hash_and_number
starknet_call
starknet_estimateFee
starknet_estimateFeeSingle
starknet_getBalance
starknet_getEvents
starknet_getProof
starknet_getStateRoot
starknet_getStateUpdate
starknet_getStorateAt
starknet_getTransactionReceipt
starknet_getTransactionStatus
starknet_syncing
pathfinder_getProof
*/

0 comments on commit 886cbfc

Please sign in to comment.