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

Pre-release Ditto Version 📍 #50

Merged
merged 8 commits into from
Mar 18, 2024
1 change: 1 addition & 0 deletions macro_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use url::Url;
pub struct TestConfig {
pub pathfinder: String,
pub deoxys: String,
pub juno: String,
}

impl TestConfig {
Expand Down
1 change: 1 addition & 0 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub const DEOXYS: &str = "deoxys";
pub const PATHFINDER: &str = "pathfinder";
pub const JUNO: &str = "juno";
pub const STARKGATE_ETH_CONTRACT_ADDR: &str =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
pub const INVALID_CONTRACT_ADDR: &str = "0x4269DEADBEEF";
Expand Down
11 changes: 10 additions & 1 deletion unit_tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@ pub fn deoxys(config: TestConfig) -> JsonRpcClient<HttpTransport> {
#[fixture]
pub fn pathfinder(config: TestConfig) -> JsonRpcClient<HttpTransport> {
JsonRpcClient::new(HttpTransport::new(
Url::parse(&config.pathfinder).expect("Error parsing Deoxys node url"),
Url::parse(&config.pathfinder).expect("Error parsing Pathfinder node url"),
))
}

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

#[fixture]
pub fn clients(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
juno: JsonRpcClient<HttpTransport>,
) -> HashMap<String, JsonRpcClient<HttpTransport>> {
map! {
String::from(DEOXYS) => deoxys,
String::from(PATHFINDER) => pathfinder,
String::from(JUNO) => juno,
}
}
28 changes: 28 additions & 0 deletions unit_tests/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use starknet_core::types::StarknetError;
use starknet_providers::ProviderError;
/* Common imports used throughout all unit tests */

#[allow(unused_imports)]
Expand All @@ -8,3 +10,29 @@ pub use rstest::*;
pub use unit_tests::constants::*;
#[allow(unused_imports)]
pub use unit_tests::fixtures::*;

/// This function aimed to check if the error is correctly handled by checking
/// the error code/type suggested by starknet rpc specs, see : https://github.com/starkware-libs/starknet-specs/blob/eedf5f899aa51a85a841333175023aa5d615aa33/api/starknet_api_openrpc.json#L3867-L3950
/// Be aware that the error message is not deeply checked, only the error type.
/// So be sure that the same contract or transaction are submitted to the function.

pub fn checking_error_format(response: &ProviderError, expected_error: StarknetError) -> bool {
match response {
ProviderError::StarknetError(actual_error) => {
if *actual_error == expected_error {
return true;
}

match (actual_error, &expected_error) {
(StarknetError::ContractError(_), StarknetError::ContractError(_)) => true,

(StarknetError::UnexpectedError(_), StarknetError::UnexpectedError(_)) => true,
_ => false,
}
}
_ => false,
}
}

// TODO : Maybe create a function for each executions call that retrieves
// responses from the 3 differents full nodes and compare releveant fields
Loading
Loading