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

Fix/e2e test #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/cli", "crates/core"]
members = ["crates/cli", "crates/core", "tests"]
resolver = "2"

[workspace.package]
Expand All @@ -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"
13 changes: 13 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 0 additions & 46 deletions tests/e2e_test.rs

This file was deleted.

50 changes: 50 additions & 0 deletions tests/src/e2e_test.rs
Original file line number Diff line number Diff line change
@@ -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<Tag>=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::<FibonnacciProvingResponse>(&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");
}
}
1 change: 1 addition & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod e2e_test;
Loading