Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Jan 11, 2024
2 parents 3ffc62e + 600edc6 commit c86885f
Show file tree
Hide file tree
Showing 11 changed files with 717 additions and 95 deletions.
261 changes: 187 additions & 74 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()
}
11 changes: 7 additions & 4 deletions unit_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ 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 = "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 }
starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "a35ce22", default-features = false }
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-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", 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/" }
3 changes: 3 additions & 0 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ pub const SELECTOR_NAME: &str = "";
///
pub const SIGNER_PRIVATE: &str = "";
pub const ARGENT_CONTRACT_ADDRESS: &str = "";

pub const ERR_DEOXYS: &str = "Error waiting for response from Deoxys client";
pub const ERR_PATHFINDER: &str = "Error waiting for response from Pathfinder client";
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
13 changes: 5 additions & 8 deletions unit_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#![feature(assert_matches)]

use std::{fs::File, io::Read};

use constants::*;
use serde::Deserialize;
use starknet_core::{
types::{BroadcastedInvokeTransaction, BroadcastedTransaction, FieldElement},
utils::get_selector_from_name,
};

use anyhow::Context;
use serde::Deserialize;
use serde_json::from_str;
use std::{fs::File, io::Read};

pub mod constants;
pub mod fixtures;
pub mod macros;
Expand All @@ -28,13 +26,12 @@ impl TestConfig {

file.read_to_string(&mut content)?;

let config: TestConfig = from_str(&content)
.with_context(|| format!("Could not deserialize test at {path} into Config"))?;
let config: TestConfig = serde_json::from_str(&content)
.expect("Could not deserialize test at {path} into Config");

Ok(config)
}
}

pub trait TransactionFactory {
fn build(nonce: Option<FieldElement>) -> BroadcastedTransaction;
}
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 c86885f

Please sign in to comment.