Skip to content

Commit c2c4caf

Browse files
committed
fix: use relay HTTP client for tests (#316)
* fix: use relay HTTP client for tests * fix: run CI when tests are changed
1 parent e4ff849 commit c2c4caf

File tree

5 files changed

+458
-536
lines changed

5 files changed

+458
-536
lines changed

.github/workflows/event_pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
- uses: actions/checkout@v3
4242
- uses: WalletConnect/actions/github/paths-filter/@2.2.1
4343
id: filter
44+
with:
45+
path-app: . # run CI when tests are changed
4446
outputs:
4547
infra: ${{ steps.filter.outputs.infra }}
4648
app: ${{ steps.filter.outputs.app }}

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test-all:
3131

3232
test-integration:
3333
@echo '==> Testing integration'
34-
RUST_BACKTRACE=1 ANSI_LOGS=true cargo test --test integration -- {{test}}
34+
RUST_BACKTRACE=1 ANSI_LOGS=true cargo test --test integration -- {{test}} --test-threads=1
3535

3636
# Clean build artifacts
3737
clean:

tests/deployment.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
22
crate::utils::{
3-
create_client, encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth,
4-
JWT_LEEWAY, RELAY_MESSAGE_DELIVERY_TIMEOUT,
3+
encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth, JWT_LEEWAY,
4+
RELAY_MESSAGE_DELIVERY_TIMEOUT,
55
},
66
base64::Engine,
77
chacha20poly1305::{
@@ -53,13 +53,13 @@ use {
5353
cacao::{self, signature::Eip191},
5454
ed25519_dalek::Keypair,
5555
},
56-
domain::DecodedClientId,
56+
domain::{DecodedClientId, ProjectId},
5757
rpc::msg_id::get_message_id,
5858
},
5959
serde_json::json,
6060
sha2::Digest,
6161
sha3::Keccak256,
62-
std::{collections::HashSet, env},
62+
std::{collections::HashSet, env, sync::Arc},
6363
tokio::sync::broadcast::Receiver,
6464
url::Url,
6565
uuid::Uuid,
@@ -151,6 +151,44 @@ struct Vars {
151151
keys_server_url: Url,
152152
}
153153

154+
pub async fn create_client(
155+
relay_url: Url,
156+
relay_project_id: ProjectId,
157+
notify_url: Url,
158+
) -> (
159+
Arc<relay_client::websocket::Client>,
160+
Receiver<notify_server::services::websocket_server::relay_ws_client::RelayClientEvent>,
161+
) {
162+
let (tx, mut rx) = tokio::sync::broadcast::channel(8);
163+
let (mpsc_tx, mut mpsc_rx) = tokio::sync::mpsc::unbounded_channel();
164+
tokio::task::spawn(async move {
165+
while let Some(event) = mpsc_rx.recv().await {
166+
let _ = tx.send(event);
167+
}
168+
});
169+
let connection_handler =
170+
notify_server::services::websocket_server::relay_ws_client::RelayConnectionHandler::new(
171+
"notify-client",
172+
mpsc_tx,
173+
);
174+
let relay_ws_client = Arc::new(relay_client::websocket::Client::new(connection_handler));
175+
176+
let keypair = Keypair::generate(&mut StdRng::from_entropy());
177+
let opts = notify_server::relay_client_helpers::create_ws_connect_options(
178+
&keypair,
179+
relay_url,
180+
notify_url,
181+
relay_project_id,
182+
)
183+
.unwrap();
184+
relay_ws_client.connect(&opts).await.unwrap();
185+
186+
// Eat up the "connected" message
187+
_ = rx.recv().await.unwrap();
188+
189+
(relay_ws_client, rx)
190+
}
191+
154192
#[allow(clippy::too_many_arguments)]
155193
async fn watch_subscriptions(
156194
vars: &Vars,

0 commit comments

Comments
 (0)