diff --git a/Cargo.toml b/Cargo.toml index 966da90..acbf380 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/cli", "crates/core"] +members = ["crates/cli", "crates/core", "tests"] resolver = "2" [workspace.package] @@ -12,9 +12,8 @@ license = "MIT" [workspace.dependencies] -#stwo-prover = { git = "https://github.com/starkware-libs/stwo.git" } +stwo-prover = { git = "https://github.com/starkware-libs/stwo.git" } # Temporary fork for serde compatibility of StarkProof -stwo-prover = { git = "https://github.com/MSghais/stwo.git", rev = "8401c93" } tokio = { version = "1", default-features = false } tracing = { version = "0.1", default-features = false } tracing-subscriber = "0.3" diff --git a/tests/Cargo.toml b/tests/Cargo.toml new file mode 100644 index 0000000..c30a836 --- /dev/null +++ b/tests/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "tests" +version = "0.1.0" +edition = "2018" + +[dependencies] +askeladd = { path = "../crates/core" } +nostr-sdk = "0.33.0" +tokio = { version = "1", default-features = false } + +[[test]] +name = "e2e_test" +path = "tests/src/e2e_test.rs" \ No newline at end of file diff --git a/tests/e2e_test.rs b/tests/e2e_test.rs deleted file mode 100644 index 16fba8c..0000000 --- a/tests/e2e_test.rs +++ /dev/null @@ -1,46 +0,0 @@ -use askeladd::config::Settings; -use askeladd::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; -use nostr_sdk::prelude::*; -use std::time::Duration; - -#[tokio::test] -async fn test_e2e_flow() { - let settings = Settings::new().expect("Failed to load settings"); - - let secret_key = SecretKey::from_bech32(&settings.user_bech32_sk).unwrap(); - let keys = Keys::new(secret_key); - - let client = Client::new(&keys); - client.add_relay("ws://nostr-relay:8080").await.unwrap(); - client.connect().await; - // Create and publish a proving request - let request = FibonnacciProvingRequest { - request_id: "test-request-id".to_string(), - log_size: 5, - claim: 443693538, - }; - let request_json = serde_json::to_string(&request).unwrap(); - let event_id = client.publish_text_note(request_json, &[]).await.unwrap(); - - // Wait for the response - let filter = Filter::new() - .kind(Kind::TextNote) - .custom_tag("e", vec![event_id.to_string()]); - let mut notifications = client.notifications(); - - let mut response_received = false; - for _ in 0..30 { // Wait up to 30 seconds - if let Ok(notification) = tokio::time::timeout(Duration::from_secs(1), notifications.next()).await { - if let Some(RelayPoolNotification::Event { event, .. }) = notification { - if let Ok(response) = serde_json::from_str::(&event.content) { - assert_eq!(response.request_id, request.request_id); - assert!(response.proof.is_some()); - response_received = true; - break; - } - } - } - } - - assert!(response_received, "Did not receive a response within the timeout period"); -} \ No newline at end of file diff --git a/tests/src/e2e_test.rs b/tests/src/e2e_test.rs new file mode 100644 index 0000000..b33ecf3 --- /dev/null +++ b/tests/src/e2e_test.rs @@ -0,0 +1,50 @@ + +#[cfg(test)] +mod e2e_test { + use askeladd::config::Settings; + use askeladd::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; + use nostr_sdk::prelude::*; + use std::time::Duration; + #[tokio::test] + async fn e2e_test() { + let settings = Settings::new().expect("Failed to load settings"); + + let secret_key = SecretKey::from_bech32(&settings.user_bech32_sk).unwrap(); + let keys = Keys::new(secret_key); + + let client = Client::new(&keys); + client.add_relay("ws://nostr-relay:8080").await.unwrap(); + client.connect().await; + // Create and publish a proving request + let request = FibonnacciProvingRequest { + request_id: "test-request-id".to_string(), + log_size: 5, + claim: 443693538, + }; + let request_json = serde_json::to_string(&request).unwrap(); + let tags:Vec=vec![]; + let event_id = client.publish_text_note(request_json, tags).await.unwrap(); + + // Wait for the response + let filter = Filter::new() + .kind(Kind::TextNote) + .custom_tag(SingleLetterTag::from_char('e').unwrap(), vec![event_id.to_string()]); + let mut notifications = client.notifications(); + + let mut response_received = false; + for _ in 0..30 { // Wait up to 30 seconds + if let Ok(notification) = tokio::time::timeout(Duration::from_secs(1), notifications.next()).await { + if let Some(RelayPoolNotification::Event { event, .. }) = notification { + if let Ok(response) = serde_json::from_str::(&event.content) { + assert_eq!(response.request_id, request.request_id); + assert!(response.proof.is_some()); + response_received = true; + break; + } + } + } + } + + assert!(response_received, "Did not receive a response within the timeout period"); + } +} diff --git a/tests/src/lib.rs b/tests/src/lib.rs new file mode 100644 index 0000000..41dec4a --- /dev/null +++ b/tests/src/lib.rs @@ -0,0 +1 @@ +pub mod e2e_test; \ No newline at end of file