From b6ca82b4eaa1d248b493deebb145573e00d53a31 Mon Sep 17 00:00:00 2001 From: NathanosDev Date: Mon, 23 Oct 2023 11:05:49 +0200 Subject: [PATCH 1/2] test: add integration tests for fallback routes with an alias re #TT-322 --- README.md | 2 +- .../frontend/assets/hello/index.html | 19 +++++++++++++++++ .../canisters/frontend/assets/world.html | 19 +++++++++++++++++ .../src/main.rs | 21 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/hello/index.html create mode 100644 packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/world.html diff --git a/README.md b/README.md index 71817378..0fbbd829 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ This package encapsulates the protocol for such verification. It is used by [the | `cargo doc -p ic-response-verification --no-deps --open` | Build Cargo crate docs | | `pnpm run -F @dfinity/response-verification build` | Build NPM package | | `pnpm run -F @dfinity/response-verification test` | Test NPM package | -| `./scripts/e2e/sh` | Run e2e tests | +| `./scripts/e2e.sh` | Run e2e tests | ### Certificate Verification diff --git a/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/hello/index.html b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/hello/index.html new file mode 100644 index 00000000..08a75679 --- /dev/null +++ b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/hello/index.html @@ -0,0 +1,19 @@ + + + + + + + canister + + + + + + +
+

Hello World!

+
+ + + diff --git a/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/world.html b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/world.html new file mode 100644 index 00000000..0ee35298 --- /dev/null +++ b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/world.html @@ -0,0 +1,19 @@ + + + + + + + canister + + + + + + +
+

Hello World?????

+
+ + + diff --git a/packages/ic-response-verification-tests/src/main.rs b/packages/ic-response-verification-tests/src/main.rs index 39f681af..8bdabc9b 100644 --- a/packages/ic-response-verification-tests/src/main.rs +++ b/packages/ic-response-verification-tests/src/main.rs @@ -77,6 +77,24 @@ async fn v2_test(canister_id: &str, agent: &Agent) -> Result<()> { let test_cases = [ ["GET", "/index.html", "dist/frontend/index.html"], // load index.html when requesting /index.html ["GET", "/", "dist/frontend/index.html"], // load index.html when requesting trailing slash + [ + "GET", + "/hello", + "canisters/frontend/assets/hello/index.html", + ], // load hello/index.html when requesting /hello + [ + "GET", + "/hello/", + "canisters/frontend/assets/hello/index.html", + ], // load hello/index.html when requesting /hello/ with trailing slash + [ + "GET", + "/hello/index.html", + "canisters/frontend/assets/hello/index.html", + ], // load hello/index.html when requesting full file path + // *** /world.html *** + ["GET", "/world", "canisters/frontend/assets/world.html"], // load hello/index.html when requesting /hello + ["GET", "/world.html", "canisters/frontend/assets/world.html"], // load hello/index.html when requesting full file path [ "GET", "/sample-asset.txt", @@ -91,6 +109,9 @@ async fn v2_test(canister_id: &str, agent: &Agent) -> Result<()> { ["GET", "/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path ["GET", "/not/found", "dist/frontend/index.html"], // fallback to index.html on not found path ["GET", "/a/b/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path + ["GET", "/world/", "dist/frontend/index.html"], // load hello/index.html when requesting /hello/ with trailing slash + ["GET", "/world/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path + ["GET", "/hello/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path ]; for [http_method, http_path, file_path] in test_cases.into_iter() { From c7160c971a5ae4e5f4118ca37dcda30448250280 Mon Sep 17 00:00:00 2001 From: NathanosDev Date: Tue, 31 Oct 2023 10:30:31 +0100 Subject: [PATCH 2/2] test: convert integration tests to use bun --- .../frontend/assets/another sample asset.txt | 1 + ...231e\314\201cran-2023-10-26-a\314\200.txt" | 1 + .../dfx-project/dfx.json | 2 +- .../dfx-project/webpack.config.js | 5 + .../package.json | 16 -- .../src/main.rs | 35 +-- .../tsconfig.json | 6 - .../wasm-tests/bunfig.toml | 2 + .../canister_http_interface.did | 47 ---- .../http-interface/canister_http_interface.ts | 46 ---- .../canister_http_interface_types.d.ts | 37 --- .../wasm-tests/main.ts | 143 ---------- .../wasm-tests/package.json | 18 ++ .../wasm-tests/setup.ts | 20 ++ .../wasm-tests/support/agent.ts | 16 ++ .../wasm-tests/support/cases.ts | 48 ++++ .../wasm-tests/support/dfx.ts | 32 +++ .../wasm-tests/support/exec.ts | 24 ++ .../wasm-tests/support/identity.ts | 14 + .../wasm-tests/support/index.ts | 6 + .../wasm-tests/support/steps.ts | 77 ++++++ .../wasm-tests/tests/v1.spec.ts | 61 +++++ .../wasm-tests/tests/v2.spec.ts | 64 +++++ .../wasm-tests/tsconfig.json | 12 + .../wasm-tests/typings.d.ts | 6 + pnpm-lock.yaml | 244 ++++++++++-------- pnpm-workspace.yaml | 2 +- scripts/e2e.sh | 5 - 28 files changed, 558 insertions(+), 432 deletions(-) create mode 100644 packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/another sample asset.txt create mode 100644 "packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/capture-d\342\200\231e\314\201cran-2023-10-26-a\314\200.txt" delete mode 100644 packages/ic-response-verification-tests/package.json delete mode 100644 packages/ic-response-verification-tests/tsconfig.json create mode 100644 packages/ic-response-verification-tests/wasm-tests/bunfig.toml delete mode 100644 packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.did delete mode 100644 packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.ts delete mode 100644 packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface_types.d.ts delete mode 100644 packages/ic-response-verification-tests/wasm-tests/main.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/package.json create mode 100644 packages/ic-response-verification-tests/wasm-tests/setup.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/agent.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/cases.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/dfx.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/exec.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/identity.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/index.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/support/steps.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/tests/v1.spec.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/tests/v2.spec.ts create mode 100644 packages/ic-response-verification-tests/wasm-tests/tsconfig.json create mode 100644 packages/ic-response-verification-tests/wasm-tests/typings.d.ts diff --git a/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/another sample asset.txt b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/another sample asset.txt new file mode 100644 index 00000000..33e2cdb4 --- /dev/null +++ b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/another sample asset.txt @@ -0,0 +1 @@ +This is another sample asset! diff --git "a/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/capture-d\342\200\231e\314\201cran-2023-10-26-a\314\200.txt" "b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/capture-d\342\200\231e\314\201cran-2023-10-26-a\314\200.txt" new file mode 100644 index 00000000..4b1a75f0 --- /dev/null +++ "b/packages/ic-response-verification-tests/dfx-project/canisters/frontend/assets/capture-d\342\200\231e\314\201cran-2023-10-26-a\314\200.txt" @@ -0,0 +1 @@ +Bonjour le monde ! diff --git a/packages/ic-response-verification-tests/dfx-project/dfx.json b/packages/ic-response-verification-tests/dfx-project/dfx.json index dae4b51f..4c0ef7db 100644 --- a/packages/ic-response-verification-tests/dfx-project/dfx.json +++ b/packages/ic-response-verification-tests/dfx-project/dfx.json @@ -4,7 +4,7 @@ "frontend": { "entrypoint": "canisters/frontend/src/index.html" }, - "source": ["canisters/frontend/assets", "dist/frontend/"], + "source": ["dist/frontend/"], "type": "assets" } } diff --git a/packages/ic-response-verification-tests/dfx-project/webpack.config.js b/packages/ic-response-verification-tests/dfx-project/webpack.config.js index f2ddbb85..8e185f45 100644 --- a/packages/ic-response-verification-tests/dfx-project/webpack.config.js +++ b/packages/ic-response-verification-tests/dfx-project/webpack.config.js @@ -32,6 +32,11 @@ module.exports = { to: '.ic-assets.json5', noErrorOnMissing: true, }, + { + from: 'canisters/frontend/assets', + to: '.', + noErrorOnMissing: true, + }, ], }), ], diff --git a/packages/ic-response-verification-tests/package.json b/packages/ic-response-verification-tests/package.json deleted file mode 100644 index 5633ee77..00000000 --- a/packages/ic-response-verification-tests/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "ic-response-verification-tests", - "version": "1.2.0", - "dependencies": { - "@dfinity/agent": "~0.19.3", - "@dfinity/principal": "~0.19.3", - "@dfinity/candid": "~0.19.3", - "@dfinity/response-verification": "workspace:*", - "isomorphic-fetch": "^3.0.0" - }, - "devDependencies": { - "@types/isomorphic-fetch": "^0.0.37", - "@types/node": "^18.0.0", - "ts-node": "^10.9.1" - } -} diff --git a/packages/ic-response-verification-tests/src/main.rs b/packages/ic-response-verification-tests/src/main.rs index 8bdabc9b..12ab6aad 100644 --- a/packages/ic-response-verification-tests/src/main.rs +++ b/packages/ic-response-verification-tests/src/main.rs @@ -77,33 +77,17 @@ async fn v2_test(canister_id: &str, agent: &Agent) -> Result<()> { let test_cases = [ ["GET", "/index.html", "dist/frontend/index.html"], // load index.html when requesting /index.html ["GET", "/", "dist/frontend/index.html"], // load index.html when requesting trailing slash - [ - "GET", - "/hello", - "canisters/frontend/assets/hello/index.html", - ], // load hello/index.html when requesting /hello - [ - "GET", - "/hello/", - "canisters/frontend/assets/hello/index.html", - ], // load hello/index.html when requesting /hello/ with trailing slash - [ - "GET", - "/hello/index.html", - "canisters/frontend/assets/hello/index.html", - ], // load hello/index.html when requesting full file path + ["GET", "/hello", "dist/frontend/hello/index.html"], // load hello/index.html when requesting /hello + ["GET", "/hello/", "dist/frontend/hello/index.html"], // load hello/index.html when requesting /hello/ with trailing slash + ["GET", "/hello/index.html", "dist/frontend/hello/index.html"], // load hello/index.html when requesting full file path // *** /world.html *** - ["GET", "/world", "canisters/frontend/assets/world.html"], // load hello/index.html when requesting /hello - ["GET", "/world.html", "canisters/frontend/assets/world.html"], // load hello/index.html when requesting full file path - [ - "GET", - "/sample-asset.txt", - "canisters/frontend/assets/sample-asset.txt", - ], // load sample text asset when requesting /sample-asset.txt + ["GET", "/world", "dist/frontend/world.html"], // load hello/index.html when requesting /hello + ["GET", "/world.html", "dist/frontend/world.html"], // load hello/index.html when requesting full file path + ["GET", "/sample-asset.txt", "dist/frontend/sample-asset.txt"], // load sample text asset when requesting /sample-asset.txt [ "GET", "/%73ample-asset.txt", - "canisters/frontend/assets/sample-asset.txt", + "dist/frontend/sample-asset.txt", ], // load sample text asset when requesting /sample-asset.txt with encoding ["GET", "/index.js", "dist/frontend/index.js"], // load sample js asset when requesting /index.js ["GET", "/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path @@ -111,7 +95,10 @@ async fn v2_test(canister_id: &str, agent: &Agent) -> Result<()> { ["GET", "/a/b/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path ["GET", "/world/", "dist/frontend/index.html"], // load hello/index.html when requesting /hello/ with trailing slash ["GET", "/world/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path - ["GET", "/hello/not-found", "dist/frontend/index.html"], // fallback to index.html on not found path that has an existing asset on a sub path + + // currently broken: see SDK-1298 + // ["GET", "/hello/not-found", "dist/frontend/index.html"], + // fallback to index.html on not found path that has an existing asset on a sub path ]; for [http_method, http_path, file_path] in test_cases.into_iter() { diff --git a/packages/ic-response-verification-tests/tsconfig.json b/packages/ic-response-verification-tests/tsconfig.json deleted file mode 100644 index 82bb0adb..00000000 --- a/packages/ic-response-verification-tests/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "include": ["./wasm-tests/**/*"], - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/packages/ic-response-verification-tests/wasm-tests/bunfig.toml b/packages/ic-response-verification-tests/wasm-tests/bunfig.toml new file mode 100644 index 00000000..98fa5103 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/bunfig.toml @@ -0,0 +1,2 @@ +[test] +preload = ["./setup.ts"] diff --git a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.did b/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.did deleted file mode 100644 index 5ae170c6..00000000 --- a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.did +++ /dev/null @@ -1,47 +0,0 @@ -// adapted from https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-gateway-interface - -type HeaderField = record { text; text; }; - -type HttpRequest = record { - method: text; - url: text; - headers: vec HeaderField; - body: blob; - certificate_version: opt nat16; -}; - -type HttpUpdateRequest = record { - method: text; - url: text; - headers: vec HeaderField; - body: blob; -}; - -type HttpResponse = record { - status_code: nat16; - headers: vec HeaderField; - body: blob; - upgrade : opt bool; - streaming_strategy: opt StreamingStrategy; -}; - -type Token = variant { - "type": reserved; -}; - -type StreamingCallbackHttpResponse = record { - body: blob; - token: opt Token; -}; - -type StreamingStrategy = variant { - Callback: record { - callback: func (Token) -> (opt StreamingCallbackHttpResponse) query; - token: Token; - }; -}; - -service : { - http_request: (request: HttpRequest) -> (HttpResponse) query; - http_request_update: (request: HttpUpdateRequest) -> (HttpResponse); -} \ No newline at end of file diff --git a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.ts b/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.ts deleted file mode 100644 index f916cb8e..00000000 --- a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IDL } from '@dfinity/candid'; - -const Token = IDL.Unknown; - -export const streamingCallbackHttpResponseType = IDL.Record({ - token: IDL.Opt(Token), - body: IDL.Vec(IDL.Nat8), -}); - -export const idlFactory: IDL.InterfaceFactory = ({ IDL }) => { - const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); - const HttpRequest = IDL.Record({ - url: IDL.Text, - method: IDL.Text, - body: IDL.Vec(IDL.Nat8), - headers: IDL.Vec(HeaderField), - certificate_version: IDL.Opt(IDL.Nat16), - }); - const StreamingStrategy = IDL.Variant({ - Callback: IDL.Record({ - token: Token, - callback: IDL.Func( - [Token], - [IDL.Opt(streamingCallbackHttpResponseType)], - ['query'], - ), - }), - }); - const HttpResponse = IDL.Record({ - body: IDL.Vec(IDL.Nat8), - headers: IDL.Vec(HeaderField), - upgrade: IDL.Opt(IDL.Bool), - streaming_strategy: IDL.Opt(StreamingStrategy), - status_code: IDL.Nat16, - }); - const HttpUpdateRequest = IDL.Record({ - url: IDL.Text, - method: IDL.Text, - body: IDL.Vec(IDL.Nat8), - headers: IDL.Vec(HeaderField), - }); - return IDL.Service({ - http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']), - http_request_update: IDL.Func([HttpUpdateRequest], [HttpResponse], []), - }); -}; diff --git a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface_types.d.ts b/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface_types.d.ts deleted file mode 100644 index f30ef9b8..00000000 --- a/packages/ic-response-verification-tests/wasm-tests/http-interface/canister_http_interface_types.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { Principal } from '@dfinity/principal'; -import type { ActorMethod } from '@dfinity/agent'; -import { IDL } from '@dfinity/candid'; - -export type HeaderField = [string, string]; -export interface HttpRequest { - url: string; - method: string; - body: Uint8Array; - headers: Array; - certificate_version: [] | [number]; -} -export interface HttpResponse { - body: Uint8Array; - headers: Array; - upgrade: [] | [boolean]; - streaming_strategy: [] | [StreamingStrategy]; - status_code: number; -} -export interface HttpUpdateRequest { - url: string; - method: string; - body: Uint8Array; - headers: Array; -} -export interface StreamingCallbackHttpResponse { - token: [] | [Token]; - body: Uint8Array; -} -export type StreamingStrategy = { - Callback: { token: Token; callback: [Principal, string] }; -}; -export type Token = { type: () => IDL.Type }; -export interface _SERVICE { - http_request: ActorMethod<[HttpRequest], HttpResponse>; - http_request_update: ActorMethod<[HttpUpdateRequest], HttpResponse>; -} diff --git a/packages/ic-response-verification-tests/wasm-tests/main.ts b/packages/ic-response-verification-tests/wasm-tests/main.ts deleted file mode 100644 index f3cd709b..00000000 --- a/packages/ic-response-verification-tests/wasm-tests/main.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { - VerificationInfo, - Request, - Response, - getMinVerificationVersion, - verifyRequestResponsePair, -} from '@dfinity/response-verification'; - -import fetch from 'isomorphic-fetch'; -import { idlFactory } from './http-interface/canister_http_interface'; -import { - HttpRequest, - _SERVICE, -} from './http-interface/canister_http_interface_types'; -import { HttpAgent, ActorSubclass, Actor, Agent } from '@dfinity/agent'; -import { Principal } from '@dfinity/principal'; -import assert from 'node:assert'; -import { exit } from 'process'; - -async function createAgentAndActor( - gatewayUrl: string, - canisterId: Principal, -): Promise<[HttpAgent, ActorSubclass<_SERVICE>]> { - const agent = new HttpAgent({ host: gatewayUrl, fetch }); - await agent.fetchRootKey(); - - const actor = Actor.createActor<_SERVICE>(idlFactory, { - agent, - canisterId: canisterId, - }); - return [agent, actor]; -} - -async function main(): Promise { - try { - const replicaAddress = process.env['DFX_REPLICA_ADDRESS']; - if (!replicaAddress) { - throw 'The `DFX_REPLICA_ADDRESS` env variable was not provided'; - } - - if (process.argv.length === 2) { - throw 'The canister ID arg was not provided'; - } - const canisterId = process.argv[3]; - const principal = Principal.fromText(canisterId); - - const [agent, actor] = await createAgentAndActor(replicaAddress, principal); - - await v1Test(principal, agent, actor); - await v2Test(principal, agent, actor); - } catch (error) { - console.error('Error running e2e tests...', error); - exit(1); - } -} - -async function v1Test( - canisterId: Principal, - agent: Agent, - actor: ActorSubclass<_SERVICE>, -): Promise { - const resultOne = await performTest( - canisterId, - 'GET', - '/', - null, - agent, - actor, - ); - assert.equal(resultOne.verificationVersion, 1); - - const resultTwo = await performTest( - canisterId, - 'GET', - '/', - null, - agent, - actor, - ); - assert.equal(resultTwo.verificationVersion, 1); -} - -async function v2Test( - canisterId: Principal, - agent: Agent, - actor: ActorSubclass<_SERVICE>, -): Promise { - const resultOne = await performTest(canisterId, 'GET', '/', 2, agent, actor); - assert.equal(resultOne.verificationVersion, 2); - - const resultTwo = await performTest(canisterId, 'GET', '/', 2, agent, actor); - assert.equal(resultTwo.verificationVersion, 2); -} - -async function performTest( - canisterId: Principal, - method: string, - url: string, - certificateVersion: number | null, - agent: Agent, - actor: ActorSubclass<_SERVICE>, -): Promise { - let httpRequest: HttpRequest = { - method, - body: new Uint8Array(), - certificate_version: certificateVersion ? [certificateVersion] : [], - headers: [], - url, - }; - - let httpResponse = await actor.http_request(httpRequest); - - let request: Request = { - headers: httpRequest.headers, - method: httpRequest.method, - url: httpRequest.url, - body: httpRequest.body, - }; - let response: Response = { - body: httpResponse.body, - headers: httpResponse.headers, - statusCode: httpResponse.status_code, - }; - - const currentTimeNs = BigInt.asUintN(64, BigInt(Date.now() * 1_000_000)); // from ms to nanoseconds - const maxCertTimeOffsetNs = BigInt.asUintN(64, BigInt(300_000_000_000)); - - if (!agent.rootKey) { - throw 'Agent does not have root key'; - } - - return verifyRequestResponsePair( - request, - response, - canisterId.toUint8Array(), - currentTimeNs, - maxCertTimeOffsetNs, - new Uint8Array(agent.rootKey), - certificateVersion ?? getMinVerificationVersion(), - ); -} - -main(); diff --git a/packages/ic-response-verification-tests/wasm-tests/package.json b/packages/ic-response-verification-tests/wasm-tests/package.json new file mode 100644 index 00000000..2816beaf --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/package.json @@ -0,0 +1,18 @@ +{ + "name": "ic-response-verification-tests", + "version": "1.2.0", + "scripts": { + "test": "tsc && bun test" + }, + "devDependencies": { + "@dfinity/agent": "~0.19.3", + "@dfinity/candid": "~0.19.3", + "@dfinity/identity": "~0.19.3", + "@dfinity/principal": "~0.19.3", + "@dfinity/ic-management": "^1.0.0", + "@dfinity/http-canister-client": "https://gitpkg.now.sh/dfinity/http-gateway/packages/http-canister-client-js?7f42a1a3f94aee11218e3bb8b08ccdff9be6cecc", + "@dfinity/response-verification": "workspace:*", + "bun-types": "^1.0.7", + "ts-node": "^10.9.1" + } +} diff --git a/packages/ic-response-verification-tests/wasm-tests/setup.ts b/packages/ic-response-verification-tests/wasm-tests/setup.ts new file mode 100644 index 00000000..9a0821d6 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/setup.ts @@ -0,0 +1,20 @@ +import { beforeAll, afterAll } from 'bun:test'; +import { resolve } from 'path'; +import { dfxDeploy, getReplicaUrl, restartDfx, stopDfx } from './support'; + +beforeAll(async () => { + restartDfx(); + + const replicaUrl = getReplicaUrl(); + const canisterId = dfxDeploy( + 'frontend', + resolve(import.meta.dir, '..', 'dfx-project'), + ); + + process.env['REPLICA_URL'] = replicaUrl; + process.env['CANISTER_ID'] = canisterId; +}); + +afterAll(async () => { + stopDfx(); +}); diff --git a/packages/ic-response-verification-tests/wasm-tests/support/agent.ts b/packages/ic-response-verification-tests/wasm-tests/support/agent.ts new file mode 100644 index 00000000..f589013f --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/agent.ts @@ -0,0 +1,16 @@ +import { HttpAgent, Identity } from '@dfinity/agent'; +import { ANONYMOUS_IDENTITY } from './identity'; + +export async function createAgent( + host: string, + identity: Identity = ANONYMOUS_IDENTITY, +): Promise { + const agent = new HttpAgent({ + identity, + host, + }); + + await agent.fetchRootKey(); + + return agent; +} diff --git a/packages/ic-response-verification-tests/wasm-tests/support/cases.ts b/packages/ic-response-verification-tests/wasm-tests/support/cases.ts new file mode 100644 index 00000000..b0ab9706 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/cases.ts @@ -0,0 +1,48 @@ +export interface TestCase { + url: string; + responsePath: string; +} + +export const TEST_CASES: TestCase[] = [ + // /index.html + { url: '/', responsePath: 'index.html' }, + { url: '/index.html', responsePath: 'index.html' }, + { url: '/index', responsePath: 'index.html' }, + + // /world.html + { url: '/world', responsePath: 'world.html' }, + { url: '/world.html', responsePath: 'world.html' }, + + // /hello/index.html + { url: '/hello', responsePath: 'hello/index.html' }, + { url: '/hello/', responsePath: 'hello/index.html' }, + { url: '/hello/index.html', responsePath: 'hello/index.html' }, + { url: '/hello/index', responsePath: 'hello/index.html' }, + + // /sample-asset.txt + { url: '/sample-asset.txt', responsePath: 'sample-asset.txt' }, + { url: '/%73ample-asset.txt', responsePath: 'sample-asset.txt' }, + + // /another%20sample%20asset.txt + { + url: '/another%20sample%20asset.txt', + responsePath: 'another sample asset.txt', + }, + + // /capture-d’écran-2023-10-26-à.txt + { + url: '/capture-d%E2%80%99e%CC%81cran-2023-10-26-a%CC%80.txt', + responsePath: 'capture-d’écran-2023-10-26-à.txt', + }, + + // /index.html fallback + { url: '/not-found', responsePath: 'index.html' }, + { url: '/not-found/', responsePath: 'index.html' }, + { url: '/not/found', responsePath: 'index.html' }, + { url: '/not/found/', responsePath: 'index.html' }, + { url: '/a/b/not-found', responsePath: 'index.html' }, + { url: '/world/', responsePath: 'index.html' }, + { url: '/world/not-found', responsePath: 'index.html' }, + // currently broken: see SDK-1298 + // { url: '/hello/not-found', responsePath: 'index.html' }, +]; diff --git a/packages/ic-response-verification-tests/wasm-tests/support/dfx.ts b/packages/ic-response-verification-tests/wasm-tests/support/dfx.ts new file mode 100644 index 00000000..920a992a --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/dfx.ts @@ -0,0 +1,32 @@ +import { exec, execWithLogs } from './exec'; + +function getReplicaPort(): string { + return exec('dfx info replica-port'); +} + +export function getReplicaUrl(): string { + const port = getReplicaPort(); + + return `http://localhost:${port}`; +} + +function startDfx(): void { + execWithLogs('dfx start --background'); +} + +export function stopDfx(): void { + execWithLogs('dfx stop'); +} + +export function restartDfx(): void { + stopDfx(); + startDfx(); +} + +export function dfxDeploy( + canisterName: string, + projectDirectory: string, +): string { + execWithLogs(`dfx deploy ${canisterName}`, projectDirectory); + return exec(`dfx canister id ${canisterName}`, projectDirectory); +} diff --git a/packages/ic-response-verification-tests/wasm-tests/support/exec.ts b/packages/ic-response-verification-tests/wasm-tests/support/exec.ts new file mode 100644 index 00000000..da91279a --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/exec.ts @@ -0,0 +1,24 @@ +import { execSync } from 'node:child_process'; +import { resolve } from 'node:path'; + +export function execWithLogs(cmd: string, cwd?: string): void { + execSync(cmd, { stdio: 'inherit', cwd }); +} + +export function exec(cmd: string, cwd?: string): string { + const result = execSync(cmd, { cwd }); + + return result.toString().replace(/(\r\n|\n|\r)/gm, ''); +} + +async function readFileBytes(filepath: string): Promise { + filepath = resolve(import.meta.dir, filepath); + const file = Bun.file(filepath); + + const buffer = await file.arrayBuffer(); + return new Uint8Array(buffer); +} + +export async function readAsset(path: string): Promise { + return await readFileBytes(`../../dfx-project/dist/frontend/${path}`); +} diff --git a/packages/ic-response-verification-tests/wasm-tests/support/identity.ts b/packages/ic-response-verification-tests/wasm-tests/support/identity.ts new file mode 100644 index 00000000..04a459b0 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/identity.ts @@ -0,0 +1,14 @@ +import { AnonymousIdentity, Identity } from '@dfinity/agent'; +import { Ed25519KeyIdentity } from '@dfinity/identity'; + +export function createIdentity(seedPhrase: string): Identity { + const hash = new Bun.CryptoHasher('sha256'); + hash.update(seedPhrase); + const digest = hash.digest('hex').slice(0, 32); + const encodedDigest = new TextEncoder().encode(digest); + + return Ed25519KeyIdentity.generate(encodedDigest); +} + +export const ANONYMOUS_IDENTITY = new AnonymousIdentity(); +export const DEFAULT_IDENTITY = createIdentity('@Password!1234'); diff --git a/packages/ic-response-verification-tests/wasm-tests/support/index.ts b/packages/ic-response-verification-tests/wasm-tests/support/index.ts new file mode 100644 index 00000000..aebd04cf --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/index.ts @@ -0,0 +1,6 @@ +export * from './agent'; +export * from './cases'; +export * from './dfx'; +export * from './exec'; +export * from './identity'; +export * from './steps'; diff --git a/packages/ic-response-verification-tests/wasm-tests/support/steps.ts b/packages/ic-response-verification-tests/wasm-tests/support/steps.ts new file mode 100644 index 00000000..3efc1da9 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/support/steps.ts @@ -0,0 +1,77 @@ +import { + HttpCanisterClient, + HttpRequest, + HttpResponse, +} from '@dfinity/http-canister-client'; +import { Principal } from '@dfinity/principal'; +import { + VerificationInfo, + getMinVerificationVersion, + verifyRequestResponsePair, + Request, + Response, +} from '@dfinity/response-verification'; + +export interface RequestOptions { + method: string; + url: string; + certificateVersion?: number; +} + +export async function request( + httpCanisterClient: HttpCanisterClient, + { method, url, certificateVersion }: RequestOptions, +): Promise<[HttpRequest, HttpResponse]> { + const httpRequest: HttpRequest = { + method, + body: new Uint8Array(), + certificate_version: certificateVersion ? [certificateVersion] : [], + headers: [], + url, + }; + + const httpResponse = await httpCanisterClient.httpRequest(httpRequest); + + return [httpRequest, httpResponse]; +} + +export interface VerifyOptions { + httpRequest: HttpRequest; + httpResponse: HttpResponse; + certificateVersion?: number; + rootKey: Uint8Array; + canisterId: Principal; +} + +export function verify({ + httpRequest, + httpResponse, + certificateVersion, + rootKey, + canisterId, +}: VerifyOptions): VerificationInfo { + let request: Request = { + headers: httpRequest.headers, + method: httpRequest.method, + url: httpRequest.url, + body: Uint8Array.from(httpRequest.body), + }; + let response: Response = { + body: Uint8Array.from(httpResponse.body), + headers: httpResponse.headers, + statusCode: httpResponse.status_code, + }; + + const currentTimeNs = BigInt.asUintN(64, BigInt(Date.now() * 1_000_000)); // from ms to nanoseconds + const maxCertTimeOffsetNs = BigInt.asUintN(64, BigInt(300_000_000_000)); + + return verifyRequestResponsePair( + request, + response, + canisterId.toUint8Array(), + currentTimeNs, + maxCertTimeOffsetNs, + rootKey, + certificateVersion ?? getMinVerificationVersion(), + ); +} diff --git a/packages/ic-response-verification-tests/wasm-tests/tests/v1.spec.ts b/packages/ic-response-verification-tests/wasm-tests/tests/v1.spec.ts new file mode 100644 index 00000000..74c69d11 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/tests/v1.spec.ts @@ -0,0 +1,61 @@ +import { beforeEach, describe, expect, it } from 'bun:test'; +import { HttpCanisterClient } from '@dfinity/http-canister-client'; +import { Principal } from '@dfinity/principal'; +import { HttpAgent } from '@dfinity/agent'; +import { + TEST_CASES, + createAgent, + readAsset, + request, + verify, +} from '../support'; + +describe('Response Verification v1', () => { + let agent: HttpAgent; + let httpCanisterClient: HttpCanisterClient; + let rootKey: Uint8Array; + let canisterId: Principal; + + beforeEach(async () => { + const replicaUrl = process.env.REPLICA_URL; + canisterId = Principal.fromText(process.env.CANISTER_ID); + + agent = await createAgent(replicaUrl); + rootKey = new Uint8Array(agent.rootKey); + + httpCanisterClient = new HttpCanisterClient(canisterId, agent); + }); + + TEST_CASES.forEach(({ url, responsePath }) => { + it(`should verify a valid response on URL ${url}`, async () => { + const certificateVersion = 1; + + const [httpRequest, httpResponse] = await request(httpCanisterClient, { + url, + method: 'GET', + certificateVersion, + }); + + const result = verify({ + httpRequest, + httpResponse, + certificateVersion, + rootKey, + canisterId, + }); + + const expectedResponse = await readAsset(responsePath); + + expect(result.verificationVersion).toEqual(1); + expect(result.response).toBeDefined(); + + expect(result.response.statusCode).not.toBeDefined(); + + expect(result.response.headers).toBeArray(); + expect(result.response.headers).toBeArrayOfSize(0); + + expect(result.response.body).toBeInstanceOf(Uint8Array); + expect(result.response.body).toEqual(expectedResponse); + }); + }); +}); diff --git a/packages/ic-response-verification-tests/wasm-tests/tests/v2.spec.ts b/packages/ic-response-verification-tests/wasm-tests/tests/v2.spec.ts new file mode 100644 index 00000000..9af68944 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/tests/v2.spec.ts @@ -0,0 +1,64 @@ +import { beforeEach, describe, expect, it } from 'bun:test'; +import { HttpCanisterClient } from '@dfinity/http-canister-client'; +import { Principal } from '@dfinity/principal'; +import { HttpAgent } from '@dfinity/agent'; +import { + createAgent, + readAsset, + request, + verify, + TEST_CASES, +} from '../support'; + +describe('Response Verification v2', () => { + let agent: HttpAgent; + let httpCanisterClient: HttpCanisterClient; + let rootKey: Uint8Array; + let canisterId: Principal; + + beforeEach(async () => { + const replicaUrl = process.env.REPLICA_URL; + canisterId = Principal.fromText(process.env.CANISTER_ID); + + agent = await createAgent(replicaUrl); + rootKey = new Uint8Array(agent.rootKey); + + httpCanisterClient = new HttpCanisterClient(canisterId, agent); + }); + + TEST_CASES.forEach(({ url, responsePath }) => { + it(`should verify a valid response on URL ${url}`, async () => { + const certificateVersion = 2; + + const [httpRequest, httpResponse] = await request(httpCanisterClient, { + url, + method: 'GET', + certificateVersion, + }); + + console.log('httpRequest', httpRequest); + console.log('httpResponse', httpResponse); + + const result = verify({ + httpRequest, + httpResponse, + certificateVersion, + rootKey, + canisterId, + }); + + const expectedResponse = await readAsset(responsePath); + + expect(result.verificationVersion).toEqual(2); + expect(result.response).toBeDefined(); + + expect(result.response.statusCode).toEqual(200); + + expect(result.response.headers).toBeArray(); + expect(result.response.headers).toBeArrayOfSize(9); + + expect(result.response.body).toBeInstanceOf(Uint8Array); + expect(result.response.body).toEqual(expectedResponse); + }); + }); +}); diff --git a/packages/ic-response-verification-tests/wasm-tests/tsconfig.json b/packages/ic-response-verification-tests/wasm-tests/tsconfig.json new file mode 100644 index 00000000..64119527 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/tsconfig.json @@ -0,0 +1,12 @@ +{ + "include": ["./**/*.ts"], + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["ESNext"], + "skipLibCheck": true, + "noEmit": true, + "types": ["bun-types"] + } +} diff --git a/packages/ic-response-verification-tests/wasm-tests/typings.d.ts b/packages/ic-response-verification-tests/wasm-tests/typings.d.ts new file mode 100644 index 00000000..6721ceb5 --- /dev/null +++ b/packages/ic-response-verification-tests/wasm-tests/typings.d.ts @@ -0,0 +1,6 @@ +declare namespace NodeJS { + export interface ProcessEnv { + REPLICA_URL: string; + CANISTER_ID: string; + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 091fccc7..003cf5dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -196,34 +196,6 @@ importers: packages/ic-certification-testing-wasm: {} - packages/ic-response-verification-tests: - dependencies: - '@dfinity/agent': - specifier: ~0.19.3 - version: 0.19.3(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) - '@dfinity/candid': - specifier: ~0.19.3 - version: 0.19.3(@dfinity/principal@0.19.3) - '@dfinity/principal': - specifier: ~0.19.3 - version: 0.19.3 - '@dfinity/response-verification': - specifier: workspace:* - version: link:../ic-response-verification-wasm - isomorphic-fetch: - specifier: ^3.0.0 - version: 3.0.0 - devDependencies: - '@types/isomorphic-fetch': - specifier: ^0.0.37 - version: 0.0.37 - '@types/node': - specifier: ^18.0.0 - version: 18.0.0 - ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@18.0.0)(typescript@5.1.3) - packages/ic-response-verification-tests/dfx-project: devDependencies: copy-webpack-plugin: @@ -239,6 +211,36 @@ importers: specifier: ^4.10.0 version: 4.10.0(webpack@5.76.0) + packages/ic-response-verification-tests/wasm-tests: + devDependencies: + '@dfinity/agent': + specifier: ~0.19.3 + version: 0.19.3(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) + '@dfinity/candid': + specifier: ~0.19.3 + version: 0.19.3(@dfinity/principal@0.19.3) + '@dfinity/http-canister-client': + specifier: https://gitpkg.now.sh/dfinity/http-gateway/packages/http-canister-client-js?7f42a1a3f94aee11218e3bb8b08ccdff9be6cecc + version: link:node_modules/@dfinity/http-canister-client + '@dfinity/ic-management': + specifier: ^1.0.0 + version: 1.0.0(@dfinity/agent@0.19.3)(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3)(@dfinity/utils@1.0.0) + '@dfinity/identity': + specifier: ~0.19.3 + version: 0.19.3(@dfinity/agent@0.19.3)(@dfinity/principal@0.19.3)(@peculiar/webcrypto@1.4.3) + '@dfinity/principal': + specifier: ~0.19.3 + version: 0.19.3 + '@dfinity/response-verification': + specifier: workspace:* + version: link:../../ic-response-verification-wasm + bun-types: + specifier: ^1.0.7 + version: 1.0.7 + ts-node: + specifier: ^10.9.1 + version: 10.9.1(@types/node@20.4.2)(typescript@5.1.3) + packages/ic-response-verification-wasm: {} packages: @@ -322,6 +324,35 @@ packages: dependencies: '@dfinity/principal': 0.19.3 + /@dfinity/ic-management@1.0.0(@dfinity/agent@0.19.3)(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3)(@dfinity/utils@1.0.0): + resolution: {integrity: sha512-mWYlXQP8bP5yxuczLyWa+K0Pt3fNDgtM2a281NGOPEWhfVY/HkskxahkeVLMjUxjLPNSvbn1aK3uJreMMh+3vg==} + peerDependencies: + '@dfinity/agent': ^0.19.2 + '@dfinity/candid': ^0.19.2 + '@dfinity/principal': ^0.19.2 + '@dfinity/utils': ^1.0.0 + dependencies: + '@dfinity/agent': 0.19.3(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) + '@dfinity/candid': 0.19.3(@dfinity/principal@0.19.3) + '@dfinity/principal': 0.19.3 + '@dfinity/utils': 1.0.0(@dfinity/agent@0.19.3)(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) + dev: true + + /@dfinity/identity@0.19.3(@dfinity/agent@0.19.3)(@dfinity/principal@0.19.3)(@peculiar/webcrypto@1.4.3): + resolution: {integrity: sha512-6XHrkNQ8tVN6+MERyXPy+avGHTd2zoX3l47bu6gSwreDdOZQnAnXpHVzLcXhnUptkBVetcC70YQEKCmqtuLriA==} + peerDependencies: + '@dfinity/agent': ^0.19.3 + '@dfinity/principal': ^0.19.3 + '@peculiar/webcrypto': ^1.4.0 + dependencies: + '@dfinity/agent': 0.19.3(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) + '@dfinity/principal': 0.19.3 + '@noble/hashes': 1.3.2 + '@peculiar/webcrypto': 1.4.3 + borc: 2.1.2 + tweetnacl: 1.0.3 + dev: true + /@dfinity/principal@0.15.7(@types/node@20.3.1)(typescript@4.8.4): resolution: {integrity: sha512-6/AkYzpGEH6Jw/0+B/EeeQn+5u2GDDvRLt1kQPhIG4txQYFnOy04H3VvyrymmfAj6/CXUgrOrux6OxgYSLYVJg==} dependencies: @@ -363,6 +394,18 @@ packages: dependencies: '@noble/hashes': 1.3.2 + /@dfinity/utils@1.0.0(@dfinity/agent@0.19.3)(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3): + resolution: {integrity: sha512-xpsAgsx5jJZcdIYVbSHJ9XiNTtNIEzu8PH6Z2ALfYzF5an6B1HHTOGmhGUfLFBiEbQAyGb0zULcqBUV6lFVlCg==} + peerDependencies: + '@dfinity/agent': ^0.19.2 + '@dfinity/candid': ^0.19.2 + '@dfinity/principal': ^0.19.2 + dependencies: + '@dfinity/agent': 0.19.3(@dfinity/candid@0.19.3)(@dfinity/principal@0.19.3) + '@dfinity/candid': 0.19.3(@dfinity/principal@0.19.3) + '@dfinity/principal': 0.19.3 + dev: true + /@discoveryjs/json-ext@0.5.7: resolution: {integrity: sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==} engines: {node: '>=10.0.0'} @@ -645,6 +688,32 @@ packages: fastq: 1.15.0 dev: true + /@peculiar/asn1-schema@2.3.8: + resolution: {integrity: sha512-ULB1XqHKx1WBU/tTFIA+uARuRoBVZ4pNdOA878RDrRbBfBGcSzi5HBkdScC6ZbHn8z7L8gmKCgPC1LHRrP46tA==} + dependencies: + asn1js: 3.0.5 + pvtsutils: 1.3.5 + tslib: 2.6.2 + dev: true + + /@peculiar/json-schema@1.1.12: + resolution: {integrity: sha512-coUfuoMeIB7B8/NMekxaDzLhaYmp0HZNPEjYRm9goRou8UZIC3z21s0sL9AWoCw4EG876QyO3kYrc61WNF9B/w==} + engines: {node: '>=8.0.0'} + dependencies: + tslib: 2.6.2 + dev: true + + /@peculiar/webcrypto@1.4.3: + resolution: {integrity: sha512-VtaY4spKTdN5LjJ04im/d/joXuvLbQdgy5Z4DXF4MFZhQ+MTrejbNMkfZBp1Bs3O5+bFqnJgyGdPuZQflvIa5A==} + engines: {node: '>=10.12.0'} + dependencies: + '@peculiar/asn1-schema': 2.3.8 + '@peculiar/json-schema': 1.1.12 + pvtsutils: 1.3.5 + tslib: 2.6.2 + webcrypto-core: 1.7.7 + dev: true + /@tsconfig/node10@1.0.9: resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} @@ -743,10 +812,6 @@ packages: '@types/node': 20.4.2 dev: true - /@types/isomorphic-fetch@0.0.37: - resolution: {integrity: sha512-+27HulrbyFpcalE4Agl+KHfGi4Qkcdmxv/ISi+DmUs5NECAFxRHeuZaLJj6DBfDRle6yxCOqLHJrfyVy9y5x9w==} - dev: true - /@types/json-schema@7.0.12: resolution: {integrity: sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==} dev: true @@ -759,10 +824,6 @@ packages: resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} dev: true - /@types/node@18.0.0: - resolution: {integrity: sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==} - dev: true - /@types/node@20.3.1: resolution: {integrity: sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==} @@ -1138,6 +1199,15 @@ packages: resolution: {integrity: sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==} dev: true + /asn1js@3.0.5: + resolution: {integrity: sha512-FVnvrKJwpt9LP2lAMl8qZswRNm3T4q9CON+bxldk2iwk3FFpuwhx2FfinyitizWHsVYyaY+y5JzDR0rCMV5yTQ==} + engines: {node: '>=12.0.0'} + dependencies: + pvtsutils: 1.3.5 + pvutils: 1.1.3 + tslib: 2.6.2 + dev: true + /assert@2.0.0: resolution: {integrity: sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==} dependencies: @@ -1283,6 +1353,10 @@ packages: ieee754: 1.2.1 dev: true + /bun-types@1.0.7: + resolution: {integrity: sha512-zlIp+SCutbbugs6xDy+3WC3KO3zKySpF/bRfiTk/VJUdKt+WHAzlCtLplS7XglRYDFzhRhlzXMW/R5BHkw+u2Q==} + dev: true + /bytes@3.0.0: resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} engines: {node: '>= 0.8'} @@ -2442,15 +2516,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /isomorphic-fetch@3.0.0: - resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} - dependencies: - node-fetch: 2.6.11 - whatwg-fetch: 3.6.2 - transitivePeerDependencies: - - encoding - dev: false - /jest-worker@27.5.1: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} @@ -2704,18 +2769,6 @@ packages: tslib: 2.5.3 dev: true - /node-fetch@2.6.11: - resolution: {integrity: sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - dependencies: - whatwg-url: 5.0.0 - dev: false - /node-forge@1.3.1: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} engines: {node: '>= 6.13.0'} @@ -2980,6 +3033,17 @@ packages: engines: {node: '>=6'} dev: true + /pvtsutils@1.3.5: + resolution: {integrity: sha512-ARvb14YB9Nm2Xi6nBq1ZX6dAM0FsJnuk+31aUp4TrcZEdKUlSqOqsxJHUPJDNE3qiIp+iUPEIeR6Je/tgV7zsA==} + dependencies: + tslib: 2.6.2 + dev: true + + /pvutils@1.1.3: + resolution: {integrity: sha512-pMpnA0qRdFp32b1sJl1wOJNxZLQ2cbQx+k6tjNtZ8CpvVhNqEPRgivZ2WOUev2YMajecdH7ctUPDvEe87nariQ==} + engines: {node: '>=6.0.0'} + dev: true + /qs@6.11.0: resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} engines: {node: '>=0.6'} @@ -3501,10 +3565,6 @@ packages: engines: {node: '>=0.6'} dev: true - /tr46@0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - dev: false - /ts-loader@9.4.1(typescript@4.8.4)(webpack@5.76.0): resolution: {integrity: sha512-384TYAqGs70rn9F0VBnh6BPTfhga7yFNdC5gXbQpDrBj9/KsT4iRkGqKXhziofHOlE2j6YEaiTYVGKKvPhGWvw==} engines: {node: '>=12.0.0'} @@ -3535,37 +3595,6 @@ packages: webpack: 5.76.0(webpack-cli@4.10.0) dev: true - /ts-node@10.9.1(@types/node@18.0.0)(typescript@5.1.3): - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.3 - '@types/node': 18.0.0 - acorn: 8.9.0 - acorn-walk: 8.2.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.1.3 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - dev: true - /ts-node@10.9.1(@types/node@20.3.1)(typescript@4.8.4): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true @@ -3661,6 +3690,14 @@ packages: resolution: {integrity: sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==} dev: true + /tslib@2.6.2: + resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: true + + /tweetnacl@1.0.3: + resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} + dev: true + /type-detect@4.0.8: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} @@ -3993,9 +4030,15 @@ packages: minimalistic-assert: 1.0.1 dev: true - /webidl-conversions@3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - dev: false + /webcrypto-core@1.7.7: + resolution: {integrity: sha512-7FjigXNsBfopEj+5DV2nhNpfic2vumtjjgPmeDKk45z+MJwXKKfhPB7118Pfzrmh4jqOMST6Ch37iPAHoImg5g==} + dependencies: + '@peculiar/asn1-schema': 2.3.8 + '@peculiar/json-schema': 1.1.12 + asn1js: 3.0.5 + pvtsutils: 1.3.5 + tslib: 2.6.2 + dev: true /webpack-cli@4.10.0(webpack-dev-server@4.11.1)(webpack@5.76.0): resolution: {integrity: sha512-NLhDfH/h4O6UOy+0LSso42xvYypClINuMNBVVzX4vX98TmTaTUxwRbXdhucbFMd2qLaCTcLq/PdYrvi8onw90w==} @@ -4211,17 +4254,6 @@ packages: iconv-lite: 0.6.3 dev: true - /whatwg-fetch@3.6.2: - resolution: {integrity: sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==} - dev: false - - /whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - dev: false - /which-typed-array@1.1.9: resolution: {integrity: sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==} engines: {node: '>= 0.4'} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index c7b32a77..9b3f2aa2 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,7 +2,7 @@ packages: - 'packages/certificate-verification-js' - 'packages/ic-certification-testing-wasm' - 'packages/ic-response-verification-wasm' - - 'packages/ic-response-verification-tests' + - 'packages/ic-response-verification-tests/wasm-tests' - 'packages/ic-response-verification-tests/dfx-project' - 'examples/certified-counter' - 'examples/nodejs' diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 7106e835..9e9dae77 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -110,11 +110,6 @@ run_e2e_tests() { fi DFX_REPLICA_ADDRESS=$DFX_REPLICA_ADDRESS RUST_BACKTRACE=1 cargo run -p ic-response-verification-tests -- "$DFX_CANISTER_ID" || clean_exit - - pnpm run --filter @dfinity/response-verification build || clean_exit - pushd ./packages/ic-response-verification-tests || clean_exit - DFX_REPLICA_ADDRESS=$DFX_REPLICA_ADDRESS npx ts-node ./wasm-tests/main.ts -- "$DFX_CANISTER_ID" || clean_exit - popd || clean_exit } pnpm i --frozen-lockfile