forked from AbdelStark/askeladd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d26572
commit 4e25ddd
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: End-to-End Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
e2e-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Copy .env.docker to .env | ||
run: cp .env.docker .env | ||
|
||
- name: Install Docker Compose | ||
run: | | ||
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
sudo chmod +x /usr/local/bin/docker-compose | ||
- name: Build and start services | ||
run: docker-compose up -d --build | ||
|
||
- name: Wait for services to be ready | ||
run: | | ||
timeout 60s bash -c 'until curl -s http://localhost:8080 > /dev/null; do sleep 1; done' | ||
sleep 10 # Additional wait time for other services to initialize | ||
- name: Run end-to-end test | ||
run: | | ||
docker-compose exec -T user-cli /bin/sh -c "cargo test --test e2e_test -- --nocapture" | ||
- name: Collect logs | ||
if: always() | ||
run: docker-compose logs > docker-compose-logs.txt | ||
|
||
- name: Upload logs | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: docker-compose-logs | ||
path: docker-compose-logs.txt | ||
|
||
- name: Stop services | ||
if: always() | ||
run: docker-compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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::<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"); | ||
} |