Skip to content

Commit

Permalink
fix: use relay HTTP client for tests (#316)
Browse files Browse the repository at this point in the history
* fix: use relay HTTP client for tests

* fix: run CI when tests are changed
  • Loading branch information
chris13524 authored Jan 23, 2024
1 parent a390b8f commit 5342168
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 536 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/event_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
- uses: actions/checkout@v3
- uses: WalletConnect/actions/github/paths-filter/@2.2.1
id: filter
with:
path-app: . # run CI when tests are changed
outputs:
infra: ${{ steps.filter.outputs.infra }}
app: ${{ steps.filter.outputs.app }}
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test-all:

test-integration:
@echo '==> Testing integration'
RUST_BACKTRACE=1 ANSI_LOGS=true cargo test --test integration -- {{test}}
RUST_BACKTRACE=1 ANSI_LOGS=true cargo test --test integration -- {{test}} --test-threads=1

# Clean build artifacts
clean:
Expand Down
46 changes: 42 additions & 4 deletions tests/deployment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::utils::{
create_client, encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth,
JWT_LEEWAY, RELAY_MESSAGE_DELIVERY_TIMEOUT,
encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth, JWT_LEEWAY,
RELAY_MESSAGE_DELIVERY_TIMEOUT,
},
base64::Engine,
chacha20poly1305::{
Expand Down Expand Up @@ -53,13 +53,13 @@ use {
cacao::{self, signature::Eip191},
ed25519_dalek::Keypair,
},
domain::DecodedClientId,
domain::{DecodedClientId, ProjectId},
rpc::msg_id::get_message_id,
},
serde_json::json,
sha2::Digest,
sha3::Keccak256,
std::{collections::HashSet, env},
std::{collections::HashSet, env, sync::Arc},
tokio::sync::broadcast::Receiver,
url::Url,
uuid::Uuid,
Expand Down Expand Up @@ -151,6 +151,44 @@ struct Vars {
keys_server_url: Url,
}

pub async fn create_client(
relay_url: Url,
relay_project_id: ProjectId,
notify_url: Url,
) -> (
Arc<relay_client::websocket::Client>,
Receiver<notify_server::services::websocket_server::relay_ws_client::RelayClientEvent>,
) {
let (tx, mut rx) = tokio::sync::broadcast::channel(8);
let (mpsc_tx, mut mpsc_rx) = tokio::sync::mpsc::unbounded_channel();
tokio::task::spawn(async move {
while let Some(event) = mpsc_rx.recv().await {
let _ = tx.send(event);
}
});
let connection_handler =
notify_server::services::websocket_server::relay_ws_client::RelayConnectionHandler::new(
"notify-client",
mpsc_tx,
);
let relay_ws_client = Arc::new(relay_client::websocket::Client::new(connection_handler));

let keypair = Keypair::generate(&mut StdRng::from_entropy());
let opts = notify_server::relay_client_helpers::create_ws_connect_options(
&keypair,
relay_url,
notify_url,
relay_project_id,
)
.unwrap();
relay_ws_client.connect(&opts).await.unwrap();

// Eat up the "connected" message
_ = rx.recv().await.unwrap();

(relay_ws_client, rx)
}

#[allow(clippy::too_many_arguments)]
async fn watch_subscriptions(
vars: &Vars,
Expand Down
Loading

0 comments on commit 5342168

Please sign in to comment.