Skip to content

Commit 23448d8

Browse files
committed
tests: generalize integration tests for rust and motoko
1 parent ca69ad7 commit 23448d8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tests/src/integration/client.test.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Actor, HttpAgent } from "@dfinity/agent";
12
import IcWebSocket, { createWsConfig, generateRandomIdentity } from "ic-websocket-js";
2-
import { test_canister_rs } from "../declarations/test_canister_rs";
3-
// import { test_canister_mo } from "../declarations/test_canister_mo";
3+
import { idlFactory } from "../declarations/test_canister_rs";
44
import type { AppMessage, _SERVICE } from "../declarations/test_canister_rs/test_canister_rs.did";
5+
// The Motoko test canister has the same interface as the Rust test canister, so we don't need to import it
6+
// import { idlFactory } from "../declarations/test_canister_mo";
57
// import type { AppMessage, _SERVICE } from "../declarations/test_canister_mo/test_canister_mo.did";
68

79
/// IcWebsocket parameters
@@ -15,6 +17,29 @@ console.log("gatewayAddress", gatewayAddress);
1517
console.log("icUrl", icUrl);
1618
console.log("canisterId", canisterId);
1719

20+
/// Canister actor
21+
const createActor = async (canisterId: string) => {
22+
const agent = await HttpAgent.create();
23+
24+
// Fetch root key for certificate validation during development
25+
if (process.env.DFX_NETWORK !== "ic") {
26+
try {
27+
await agent.fetchRootKey();
28+
} catch (err) {
29+
console.warn(
30+
"Unable to fetch root key. Check to ensure that your local replica is running"
31+
);
32+
console.error(err);
33+
}
34+
}
35+
36+
// Creates an actor with using the candid interface and the HttpAgent
37+
return Actor.createActor<_SERVICE>(idlFactory, {
38+
agent,
39+
canisterId,
40+
});
41+
};
42+
1843
/// test constants & variables
1944
const pingPongCount = 20;
2045
let ws: IcWebSocket<_SERVICE, AppMessage>;
@@ -56,9 +81,10 @@ const reconstructWsMessage = (index: number) => {
5681
/// tests
5782
describe("WS client", () => {
5883
it("should open a connection", async () => {
84+
const canisterActor = await createActor(canisterId);
5985
const wsConfig = createWsConfig({
6086
canisterId,
61-
canisterActor: test_canister_rs,
87+
canisterActor,
6288
// canisterActor: test_canister_mo,
6389
networkUrl: icUrl,
6490
identity: generateRandomIdentity(),

0 commit comments

Comments
 (0)