Skip to content

Commit

Permalink
Merge pull request #27 from Trantorian1/test/getEvents
Browse files Browse the repository at this point in the history
✅ Added tests for `starknet_getEvents`
  • Loading branch information
antiyro authored Jan 11, 2024
2 parents b074f4b + a698748 commit 600edc6
Show file tree
Hide file tree
Showing 8 changed files with 562 additions and 74 deletions.
237 changes: 175 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
members = [
members = [ "macros",
"macros",
"unit_tests",
]
default-members = ["unit_tests"]
resolver = "2"

11 changes: 11 additions & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "macros"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
quote = "1.0.35"
syn = "2.0.48"
21 changes: 21 additions & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, ItemFn};

#[proc_macro_attribute]
pub fn logging(_: TokenStream, input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as ItemFn);

input.block.stmts.insert(
0,
syn::parse(
quote! {
env_logger::builder().is_test(true).try_init().err();
}
.into(),
)
.unwrap(),
);

input.into_token_stream().into()
}
9 changes: 6 additions & 3 deletions unit_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ serde = "1.0.194"
serde_json = "1.0.110"
tokio = { version = "1", features = ["full"] }
url = "2.5.0"
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-core = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-providers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "a35ce22", default-features = false }
starknet-core = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "a35ce22", default-features = false }
starknet-providers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "a35ce22", default-features = false }
env_logger = "0.10.1"

[dev-dependencies]
jsonrpsee = { version = "0.21.0", features = ["client"] }
tokio = { version = "1", features = ["full", "test-util"] }
flate2 = "1.0.28"
log = "0.4.20"
macros = { path = "../macros/" }
27 changes: 20 additions & 7 deletions unit_tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@ use crate::map;
use crate::TestConfig;

#[fixture]
pub fn clients() -> HashMap<String, JsonRpcClient<HttpTransport>> {
let config =
TestConfig::new("./secret.json").expect("'./secret.json' must contain correct node urls");
let deoxys = JsonRpcClient::new(HttpTransport::new(
pub fn config() -> TestConfig {
TestConfig::new("./secret.json").expect("'./secret.json' must contain correct node urls")
}

#[fixture]
pub fn deoxys(config: TestConfig) -> JsonRpcClient<HttpTransport> {
JsonRpcClient::new(HttpTransport::new(
Url::parse(&config.deoxys).expect("Error parsing Deoxys node url"),
));
let pathfinder = JsonRpcClient::new(HttpTransport::new(
))
}

#[fixture]
pub fn pathfinder(config: TestConfig) -> JsonRpcClient<HttpTransport> {
JsonRpcClient::new(HttpTransport::new(
Url::parse(&config.pathfinder).expect("Error parsing Deoxys node url"),
));
))
}

#[fixture]
pub fn clients(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) -> HashMap<String, JsonRpcClient<HttpTransport>> {
map! {
String::from(DEOXYS) => deoxys,
String::from(PATHFINDER) => pathfinder,
Expand Down
5 changes: 5 additions & 0 deletions unit_tests/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* Common imports used throughout all unit tests */

#[allow(unused_imports)]
pub use macros::*;
#[allow(unused_imports)]
pub use rstest::*;
#[allow(unused_imports)]
pub use unit_tests::constants::*;
#[allow(unused_imports)]
pub use unit_tests::fixtures::*;
Loading

0 comments on commit 600edc6

Please sign in to comment.