From 8582bbf1d2a06210a3ebc5131adf9eaf17f453f1 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 19 Dec 2023 13:02:10 -0700 Subject: [PATCH 1/5] Add InspectMessageMethodArb --- .github/workflows/test.yml | 1 + property_tests/arbitraries/canister_arb.ts | 8 +- .../inspect_message_method_arb.ts | 77 ++ .../canister_methods/inspect_message/dfx.json | 16 + .../inspect_message/package-lock.json | 996 ++++++++++++++++++ .../inspect_message/package.json | 12 + .../inspect_message/test/generate_tests.ts | 50 + .../inspect_message/test/test.ts | 87 ++ .../inspect_message/tsconfig.json | 10 + 9 files changed, 1256 insertions(+), 1 deletion(-) create mode 100644 property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts create mode 100644 property_tests/tests/canister_methods/inspect_message/dfx.json create mode 100644 property_tests/tests/canister_methods/inspect_message/package-lock.json create mode 100644 property_tests/tests/canister_methods/inspect_message/package.json create mode 100644 property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts create mode 100644 property_tests/tests/canister_methods/inspect_message/test/test.ts create mode 100644 property_tests/tests/canister_methods/inspect_message/tsconfig.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 508e7051e1..1bca101e81 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -162,6 +162,7 @@ jobs: "property_tests/tests/canister_methods/http_request", "property_tests/tests/canister_methods/http_request_update", "property_tests/tests/canister_methods/init", + "property_tests/tests/canister_methods/inspect_message", "property_tests/tests/canister_methods/post_upgrade", "property_tests/tests/canister_methods/pre_upgrade", "property_tests/tests/canister_methods/query", diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index bdf664a700..3ca5914130 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -4,6 +4,7 @@ import { Test } from '../../test'; import { CliStringVisitor } from '../visitors/cli-string-visitor'; import { CorrespondingJSType } from './candid/corresponding_js_type'; import { InitMethod } from './canister_methods/init_method_arb'; +import { InspectMessageMethod } from './canister_methods/inspect_message_method_arb'; import { PostUpgradeMethod } from './canister_methods/post_upgrade_arb'; import { PreUpgradeMethod } from './canister_methods/pre_upgrade_method_arb'; import { QueryMethod } from './canister_methods/query_method_arb'; @@ -24,7 +25,8 @@ export type CanisterMethod< | UpdateMethod | InitMethod | PostUpgradeMethod - | PreUpgradeMethod; + | PreUpgradeMethod + | InspectMessageMethod; export type CanisterConfig< ParamAgentArgumentValue extends CorrespondingJSType = undefined, @@ -32,6 +34,7 @@ export type CanisterConfig< > = { globalDeclarations?: string[]; initMethod?: InitMethod; + inspectMessageMethod?: InspectMessageMethod; postUpgradeMethod?: PostUpgradeMethod< ParamAgentArgumentValue, ParamAgentResponseValue @@ -56,6 +59,9 @@ export function CanisterArb< ParamAgentResponseValue >[] = [ ...(config.initMethod ? [config.initMethod] : []), + ...(config.inspectMessageMethod + ? [config.inspectMessageMethod] + : []), ...(config.postUpgradeMethod ? [config.postUpgradeMethod] : []), ...(config.preUpgradeMethod ? [config.preUpgradeMethod] : []), ...(config.queryMethods ?? []), diff --git a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts new file mode 100644 index 0000000000..6e3bc6f928 --- /dev/null +++ b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts @@ -0,0 +1,77 @@ +import fc from 'fast-check'; + +import { UniqueIdentifierArb } from '../unique_identifier_arb'; +import { + BodyGenerator, + TestsGenerator, + CallbackLocation, + generateCallback, + CallbackLocationArb +} from '.'; +import { Test } from '../../../test'; +import { VoidArb } from '../candid/primitive/void'; + +export type InspectMessageMethod = { + imports: Set; + globalDeclarations: string[]; + sourceCode: string; + tests: Test[][]; +}; + +export function InspectMessageMethodArb(constraints: { + generateBody: BodyGenerator; + generateTests: TestsGenerator; + callbackLocation?: CallbackLocation; +}) { + return fc + .tuple( + UniqueIdentifierArb('canisterMethod'), + VoidArb(), + CallbackLocationArb, + UniqueIdentifierArb('typeDeclaration') + // TODO: This unique id would be better named globalScope or something + // But needs to match the same scope as typeDeclarations so I'm using + // that for now. + ) + .map( + ([ + functionName, + returnType, + defaultCallbackLocation, + callbackName + ]): InspectMessageMethod => { + const callbackLocation = + constraints.callbackLocation ?? defaultCallbackLocation; + + const imports = new Set(['inspectMessage', 'ic']); + + const callback = generateCallback( + [], + returnType, + constraints.generateBody, + callbackLocation, + callbackName + ); + + const globalDeclarations = + callbackLocation === 'STANDALONE' ? [callback] : []; + + const sourceCode = `${functionName}: inspectMessage(${ + callbackLocation === 'STANDALONE' ? callbackName : callback + })`; + + const tests = constraints.generateTests( + functionName, + [], + returnType + ); + + return { + imports, + globalDeclarations, + sourceCode, + tests + }; + } + ); +} diff --git a/property_tests/tests/canister_methods/inspect_message/dfx.json b/property_tests/tests/canister_methods/inspect_message/dfx.json new file mode 100644 index 0000000000..6ab9fbd7e4 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/dfx.json @@ -0,0 +1,16 @@ +{ + "canisters": { + "canister": { + "type": "custom", + "main": "src/index.ts", + "candid": "src/index.did", + "build": "npx azle canister", + "wasm": ".azle/canister/canister.wasm", + "gzip": true, + "declarations": { + "output": "test/dfx_generated/canister", + "node_compatibility": true + } + } + } +} diff --git a/property_tests/tests/canister_methods/inspect_message/package-lock.json b/property_tests/tests/canister_methods/inspect_message/package-lock.json new file mode 100644 index 0000000000..fac1bf5b99 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/package-lock.json @@ -0,0 +1,996 @@ +{ + "name": "inspect_message", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "azle": "^0.18.5" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } + }, + "node_modules/@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@dfinity/principal": { + "version": "0.19.3", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.19.3.tgz", + "integrity": "sha512-+nixVvdGt7ECxRvLXDXsvU9q9sSPssBtDQ4bXa149SK6gcYcmZ6lfWIi3DJNqj3tGROxILVBsguel9tECappsA==", + "dependencies": { + "@noble/hashes": "^1.3.1" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.5.tgz", + "integrity": "sha512-bhvbzWFF3CwMs5tbjf3ObfGqbl/17ict2/uwOSfr3wmxDE6VdS2GqY/FuzIPe0q0bdhj65zQsvqfArI9MY6+AA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.5.tgz", + "integrity": "sha512-5d1OkoJxnYQfmC+Zd8NBFjkhyCNYwM4n9ODrycTFY6Jk1IGiZ+tjVJDDSwDt77nK+tfpGP4T50iMtVi4dEGzhQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.5.tgz", + "integrity": "sha512-9t+28jHGL7uBdkBjL90QFxe7DVA+KGqWlHCF8ChTKyaKO//VLuoBricQCgwhOjA1/qOczsw843Fy4cbs4H3DVA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.5.tgz", + "integrity": "sha512-mvXGcKqqIqyKoxq26qEDPHJuBYUA5KizJncKOAf9eJQez+L9O+KfvNFu6nl7SCZ/gFb2QPaRqqmG0doSWlgkqw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.5.tgz", + "integrity": "sha512-Ly8cn6fGLNet19s0X4unjcniX24I0RqjPv+kurpXabZYSXGM4Pwpmf85WHJN3lAgB8GSth7s5A0r856S+4DyiA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.5.tgz", + "integrity": "sha512-GGDNnPWTmWE+DMchq1W8Sd0mUkL+APvJg3b11klSGUDvRXh70JqLAO56tubmq1s2cgpVCSKYywEiKBfju8JztQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.5.tgz", + "integrity": "sha512-1CCwDHnSSoA0HNwdfoNY0jLfJpd7ygaLAp5EHFos3VWJCRX9DMwWODf96s9TSse39Br7oOTLryRVmBoFwXbuuQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.5.tgz", + "integrity": "sha512-lrWXLY/vJBzCPC51QN0HM71uWgIEpGSjSZZADQhq7DKhPcI6NH1IdzjfHkDQws2oNpJKpR13kv7/pFHBbDQDwQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.5.tgz", + "integrity": "sha512-o3vYippBmSrjjQUCEEiTZ2l+4yC0pVJD/Dl57WfPwwlvFkrxoSO7rmBZFii6kQB3Wrn/6GwJUPLU5t52eq2meA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.5.tgz", + "integrity": "sha512-MkjHXS03AXAkNp1KKkhSKPOCYztRtK+KXDNkBa6P78F8Bw0ynknCSClO/ztGszILZtyO/lVKpa7MolbBZ6oJtQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.5.tgz", + "integrity": "sha512-42GwZMm5oYOD/JHqHska3Jg0r+XFb/fdZRX+WjADm3nLWLcIsN27YKtqxzQmGNJgu0AyXg4HtcSK9HuOk3v1Dw==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.5.tgz", + "integrity": "sha512-kcjndCSMitUuPJobWCnwQ9lLjiLZUR3QLQmlgaBfMX23UEa7ZOrtufnRds+6WZtIS9HdTXqND4yH8NLoVVIkcg==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.5.tgz", + "integrity": "sha512-yJAxJfHVm0ZbsiljbtFFP1BQKLc8kUF6+17tjQ78QjqjAQDnhULWiTA6u0FCDmYT1oOKS9PzZ2z0aBI+Mcyj7Q==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.5.tgz", + "integrity": "sha512-5u8cIR/t3gaD6ad3wNt1MNRstAZO+aNyBxu2We8X31bA8XUNyamTVQwLDA1SLoPCUehNCymhBhK3Qim1433Zag==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.5.tgz", + "integrity": "sha512-Z6JrMyEw/EmZBD/OFEFpb+gao9xJ59ATsoTNlj39jVBbXqoZm4Xntu6wVmGPB/OATi1uk/DB+yeDPv2E8PqZGw==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.5.tgz", + "integrity": "sha512-psagl+2RlK1z8zWZOmVdImisMtrUxvwereIdyJTmtmHahJTKb64pAcqoPlx6CewPdvGvUKe2Jw+0Z/0qhSbG1A==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.5.tgz", + "integrity": "sha512-kL2l+xScnAy/E/3119OggX8SrWyBEcqAh8aOY1gr4gPvw76la2GlD4Ymf832UCVbmuWeTf2adkZDK+h0Z/fB4g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.5.tgz", + "integrity": "sha512-sPOfhtzFufQfTBgRnE1DIJjzsXukKSvZxloZbkJDG383q0awVAq600pc1nfqBcl0ice/WN9p4qLc39WhBShRTA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.5.tgz", + "integrity": "sha512-dGZkBXaafuKLpDSjKcB0ax0FL36YXCvJNnztjKV+6CO82tTYVDSH2lifitJ29jxRMoUhgkg9a+VA/B03WK5lcg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.5.tgz", + "integrity": "sha512-dWVjD9y03ilhdRQ6Xig1NWNgfLtf2o/STKTS+eZuF90fI2BhbwD6WlaiCGKptlqXlURVB5AUOxUj09LuwKGDTg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.5.tgz", + "integrity": "sha512-4liggWIA4oDgUxqpZwrDhmEfAH4d0iljanDOK7AnVU89T6CzHon/ony8C5LeOdfgx60x5cnQJFZwEydVlYx4iw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.5.tgz", + "integrity": "sha512-czTrygUsB/jlM8qEW5MD8bgYU2Xg14lo6kBDXW6HdxKjh8M5PzETGiSHaz9MtbXBYDloHNUAUW2tMiKW4KM9Mw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@swc/core": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.93.tgz", + "integrity": "sha512-690GRr1wUGmGYZHk7fUduX/JUwViMF2o74mnZYIWEcJaCcd9MQfkhsxPBtjeg6tF+h266/Cf3RPYhsFBzzxXcA==", + "hasInstallScript": true, + "dependencies": { + "@swc/counter": "^0.1.1", + "@swc/types": "^0.1.5" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/swc" + }, + "optionalDependencies": { + "@swc/core-darwin-arm64": "1.3.93", + "@swc/core-darwin-x64": "1.3.93", + "@swc/core-linux-arm-gnueabihf": "1.3.93", + "@swc/core-linux-arm64-gnu": "1.3.93", + "@swc/core-linux-arm64-musl": "1.3.93", + "@swc/core-linux-x64-gnu": "1.3.93", + "@swc/core-linux-x64-musl": "1.3.93", + "@swc/core-win32-arm64-msvc": "1.3.93", + "@swc/core-win32-ia32-msvc": "1.3.93", + "@swc/core-win32-x64-msvc": "1.3.93" + }, + "peerDependencies": { + "@swc/helpers": "^0.5.0" + }, + "peerDependenciesMeta": { + "@swc/helpers": { + "optional": true + } + } + }, + "node_modules/@swc/core-darwin-arm64": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.93.tgz", + "integrity": "sha512-gEKgk7FVIgltnIfDO6GntyuQBBlAYg5imHpRgLxB1zSI27ijVVkksc6QwISzFZAhKYaBWIsFSVeL9AYSziAF7A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.93.tgz", + "integrity": "sha512-ZQPxm/fXdDQtn3yrYSL/gFfA8OfZ5jTi33yFQq6vcg/Y8talpZ+MgdSlYM0FkLrZdMTYYTNFiuBQuuvkA+av+Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.93.tgz", + "integrity": "sha512-OYFMMI2yV+aNe3wMgYhODxHdqUB/jrK0SEMHHS44GZpk8MuBXEF+Mcz4qjkY5Q1EH7KVQqXb/gVWwdgTHpjM2A==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.93.tgz", + "integrity": "sha512-BT4dT78odKnJMNiq5HdjBsv29CiIdcCcImAPxeFqAeFw1LL6gh9nzI8E96oWc+0lVT5lfhoesCk4Qm7J6bty8w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.93.tgz", + "integrity": "sha512-yH5fWEl1bktouC0mhh0Chuxp7HEO4uCtS/ly1Vmf18gs6wZ8DOOkgAEVv2dNKIryy+Na++ljx4Ym7C8tSJTrLw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-gnu": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.93.tgz", + "integrity": "sha512-OFUdx64qvrGJhXKEyxosHxgoUVgba2ztYh7BnMiU5hP8lbI8G13W40J0SN3CmFQwPP30+3oEbW7LWzhKEaYjlg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-musl": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.93.tgz", + "integrity": "sha512-4B8lSRwEq1XYm6xhxHhvHmKAS7pUp1Q7E33NQ2TlmFhfKvCOh86qvThcjAOo57x8DRwmpvEVrqvpXtYagMN6Ig==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.93.tgz", + "integrity": "sha512-BHShlxtkven8ZjjvZ5QR6sC5fZCJ9bMujEkiha6W4cBUTY7ce7qGFyHmQd+iPC85d9kD/0cCiX/Xez8u0BhO7w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.93.tgz", + "integrity": "sha512-nEwNWnz4JzYAK6asVvb92yeylfxMYih7eMQOnT7ZVlZN5ba9WF29xJ6kcQKs9HRH6MvWhz9+wRgv3FcjlU6HYA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.93.tgz", + "integrity": "sha512-jibQ0zUr4kwJaQVwgmH+svS04bYTPnPw/ZkNInzxS+wFAtzINBYcU8s2PMWbDb2NGYiRSEeoSGyAvS9H+24JFA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/counter": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.2.tgz", + "integrity": "sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==" + }, + "node_modules/@swc/types": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.5.tgz", + "integrity": "sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==" + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + }, + "node_modules/@types/node": { + "version": "20.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.7.tgz", + "integrity": "sha512-21TKHHh3eUHIi2MloeptJWALuCu5H7HQTdTrWIFReA8ad+aggoX+lRes3ex7/FtpC+sVUpFMQ+QTfYr74mruiQ==", + "peer": true, + "dependencies": { + "undici-types": "~5.25.1" + } + }, + "node_modules/@types/uuid": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.6.tgz", + "integrity": "sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==" + }, + "node_modules/acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, + "node_modules/azle": { + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/azle/-/azle-0.18.5.tgz", + "integrity": "sha512-9lLhVKwexVCd8OOYMXgjk06L+Mu0q29Rpchmz07HYV6idwF5kg+8QCxzytpU9GpnUeoADTQNkEkyLABtkd2hCA==", + "dependencies": { + "@dfinity/candid": "github:demergent-labs/candid#minimum_viable", + "@dfinity/principal": "^0.19.0", + "@swc/core": "^1.3.86", + "@types/uuid": "^9.0.4", + "buffer": "^6.0.3", + "esbuild": "^0.19.3", + "fs-extra": "10.0.1", + "js-sha256": "0.9.0", + "text-encoding": "0.7.0", + "ts-node": "10.3.1", + "typescript": "^5.2.2", + "uuid": "^9.0.1" + }, + "bin": { + "azle": "bin.js" + } + }, + "node_modules/azle/node_modules/@cspotcode/source-map-support": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", + "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "dependencies": { + "@cspotcode/source-map-consumer": "0.8.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/azle/node_modules/@dfinity/candid": { + "version": "0.19.2", + "resolved": "git+ssh://git@github.com/demergent-labs/candid.git#5797fa906b1a7cc30c161dbb0eb919283ce2f80d", + "license": "Apache-2.0", + "peerDependencies": { + "@dfinity/principal": "^0.19.2" + } + }, + "node_modules/azle/node_modules/ts-node": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", + "integrity": "sha512-Yw3W2mYzhHfCHOICGNJqa0i+rbL0rAyg7ZIHxU+K4pgY8gd2Lh1j+XbHCusJMykbj6RZMJVOY0MlHVd+GOivcw==", + "dependencies": { + "@cspotcode/source-map-support": "0.7.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "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 + } + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/esbuild": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.5.tgz", + "integrity": "sha512-bUxalY7b1g8vNhQKdB24QDmHeY4V4tw/s6Ak5z+jJX9laP5MoQseTOMemAr0gxssjNcH0MCViG8ONI2kksvfFQ==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.19.5", + "@esbuild/android-arm64": "0.19.5", + "@esbuild/android-x64": "0.19.5", + "@esbuild/darwin-arm64": "0.19.5", + "@esbuild/darwin-x64": "0.19.5", + "@esbuild/freebsd-arm64": "0.19.5", + "@esbuild/freebsd-x64": "0.19.5", + "@esbuild/linux-arm": "0.19.5", + "@esbuild/linux-arm64": "0.19.5", + "@esbuild/linux-ia32": "0.19.5", + "@esbuild/linux-loong64": "0.19.5", + "@esbuild/linux-mips64el": "0.19.5", + "@esbuild/linux-ppc64": "0.19.5", + "@esbuild/linux-riscv64": "0.19.5", + "@esbuild/linux-s390x": "0.19.5", + "@esbuild/linux-x64": "0.19.5", + "@esbuild/netbsd-x64": "0.19.5", + "@esbuild/openbsd-x64": "0.19.5", + "@esbuild/sunos-x64": "0.19.5", + "@esbuild/win32-arm64": "0.19.5", + "@esbuild/win32-ia32": "0.19.5", + "@esbuild/win32-x64": "0.19.5" + } + }, + "node_modules/fs-extra": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", + "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, + "node_modules/text-encoding": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.7.0.tgz", + "integrity": "sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==", + "deprecated": "no longer maintained" + }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "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 + } + } + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "peer": true + }, + "node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + } + } +} diff --git a/property_tests/tests/canister_methods/inspect_message/package.json b/property_tests/tests/canister_methods/inspect_message/package.json new file mode 100644 index 0000000000..e5b0aa2544 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/package.json @@ -0,0 +1,12 @@ +{ + "scripts": { + "test": "ts-node --transpile-only --ignore=false test/test.ts" + }, + "dependencies": { + "azle": "^0.18.5" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } +} diff --git a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts new file mode 100644 index 0000000000..9e4a2b8ca4 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts @@ -0,0 +1,50 @@ +import { deepEqual, getActor, Named } from 'azle/property_tests'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; +import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { Test } from 'azle/test'; +import { InspectMessageBehavior } from './test'; + +export function generateTests( + mode: 'query' | 'update', + functionName: string, + params: Named>[], + returnType: CandidValueAndMeta, + behavior: InspectMessageBehavior +): Test[][] { + const paramValues = params.map( + (param) => param.value.value.agentArgumentValue + ); + + const expectedResult = returnType.value.agentResponseValue; + + return [ + [ + { + name: `${mode} method "${functionName}"`, + test: async () => { + const actor = getActor(__dirname); + try { + const result = await actor[functionName]( + ...paramValues + ); + + if (mode === 'update' && behavior !== 'ACCEPT') { + return { + Err: 'Expected canister method to throw but it did not' + }; + } + + return { Ok: deepEqual(result, expectedResult) }; + } catch (error) { + if (mode === 'update' && behavior !== 'ACCEPT') { + return { Ok: true }; + } + + throw error; + } + } + } + ] + ]; +} diff --git a/property_tests/tests/canister_methods/inspect_message/test/test.ts b/property_tests/tests/canister_methods/inspect_message/test/test.ts new file mode 100644 index 0000000000..d333cdc6e3 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/test/test.ts @@ -0,0 +1,87 @@ +import fc from 'fast-check'; + +import { runPropTests } from 'azle/property_tests'; +import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; +import { InspectMessageMethodArb } from 'azle/property_tests/arbitraries/canister_methods/inspect_message_method_arb'; + +import { CorrespondingJSType } from '../../../../arbitraries/candid/corresponding_js_type'; +import { generateTests } from './generate_tests'; + +export type InspectMessageBehavior = 'ACCEPT' | 'RETURN' | 'THROW'; + +const CanisterConfigArb = fc + .constantFrom('ACCEPT', 'RETURN', 'THROW') + .chain((behavior) => { + const InspectMessageArb = InspectMessageMethodArb({ + generateBody: () => generateInspectMessageMethodBody(behavior), + generateTests: () => [] + }); + + const HeterogeneousQueryMethodArb = QueryMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), + { + generateBody: (_, returnType) => + `return ${returnType.src.valueLiteral}`, + generateTests: (...args) => + generateTests('query', ...args, behavior) + } + ); + + const HeterogeneousUpdateMethodArb = UpdateMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), + { + generateBody: (_, returnType) => + `return ${returnType.src.valueLiteral}`, + generateTests: (...args) => + generateTests('update', ...args, behavior) + } + ); + + const small = { + minLength: 0, + maxLength: 20 + }; + + return fc.tuple( + InspectMessageArb, + fc.array(HeterogeneousQueryMethodArb, small), + fc.array(HeterogeneousUpdateMethodArb, small) + ); + }) + .map( + ([inspectMessageMethod, queryMethods, updateMethods]): CanisterConfig< + CorrespondingJSType, + CorrespondingJSType + > => { + return { + inspectMessageMethod, + queryMethods, + updateMethods + }; + } + ); + +runPropTests(CanisterArb(CanisterConfigArb)); + +function generateInspectMessageMethodBody( + behavior: InspectMessageBehavior +): string { + if (behavior === 'RETURN') { + return /*TS*/ ''; + } + + if (behavior === 'THROW') { + return /*TS*/ `throw \`Method "$\{ic.methodName()\}" not allowed\``; + } + + return /*TS*/ `ic.acceptMessage();`; +} diff --git a/property_tests/tests/canister_methods/inspect_message/tsconfig.json b/property_tests/tests/canister_methods/inspect_message/tsconfig.json new file mode 100644 index 0000000000..d20bea88d9 --- /dev/null +++ b/property_tests/tests/canister_methods/inspect_message/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "strict": true, + "target": "ES2020", + "moduleResolution": "node", + "allowJs": true, + "outDir": "HACK_BECAUSE_OF_ALLOW_JS", + "esModuleInterop": true + } +} From 575cc5c960efcc91b054fdb85127e789dda3b6f3 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Fri, 12 Apr 2024 14:58:04 -0600 Subject: [PATCH 2/5] lint --- .../canister_methods/inspect_message_method_arb.ts | 8 ++++---- .../inspect_message/test/generate_tests.ts | 3 ++- .../canister_methods/inspect_message/test/test.ts | 11 +++++------ src/lib/ic/accept_message.ts | 4 +++- src/lib/ic/reject_message.ts | 2 ++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts index 6e3bc6f928..22b3af53c7 100644 --- a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts @@ -1,15 +1,15 @@ import fc from 'fast-check'; +import { Test } from '../../../test'; +import { VoidArb } from '../candid/primitive/void'; import { UniqueIdentifierArb } from '../unique_identifier_arb'; import { BodyGenerator, - TestsGenerator, CallbackLocation, + CallbackLocationArb, generateCallback, - CallbackLocationArb + TestsGenerator } from '.'; -import { Test } from '../../../test'; -import { VoidArb } from '../candid/primitive/void'; export type InspectMessageMethod = { imports: Set; diff --git a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts index 9e4a2b8ca4..30b3fefbbc 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts @@ -1,8 +1,9 @@ import { deepEqual, getActor, Named } from 'azle/property_tests'; -import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; import { Test } from 'azle/test'; + import { InspectMessageBehavior } from './test'; export function generateTests( diff --git a/property_tests/tests/canister_methods/inspect_message/test/test.ts b/property_tests/tests/canister_methods/inspect_message/test/test.ts index d333cdc6e3..3a5be04251 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/test.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/test.ts @@ -1,15 +1,14 @@ -import fc from 'fast-check'; - import { runPropTests } from 'azle/property_tests'; -import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; +import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { CanisterArb, CanisterConfig } from 'azle/property_tests/arbitraries/canister_arb'; -import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { InspectMessageMethodArb } from 'azle/property_tests/arbitraries/canister_methods/inspect_message_method_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; +import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb'; +import fc from 'fast-check'; import { CorrespondingJSType } from '../../../../arbitraries/candid/corresponding_js_type'; import { generateTests } from './generate_tests'; @@ -80,7 +79,7 @@ function generateInspectMessageMethodBody( } if (behavior === 'THROW') { - return /*TS*/ `throw \`Method "$\{ic.methodName()\}" not allowed\``; + return /*TS*/ `throw \`Method "$\{ic.methodName()}" not allowed\``; } return /*TS*/ `ic.acceptMessage();`; diff --git a/src/lib/ic/accept_message.ts b/src/lib/ic/accept_message.ts index e503d49180..86cfa7c408 100644 --- a/src/lib/ic/accept_message.ts +++ b/src/lib/ic/accept_message.ts @@ -1,8 +1,10 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { inspectMessage } from '../../lib/canister_methods/methods/inspect_message'; // Used for links in comments import { Void } from '../candid/types/primitive/void'; /** * Accepts the ingress message. Calling from outside the - * {@link $inspectMessage} context will cause the canister to trap. + * {@link inspectMessage} context will cause the canister to trap. */ export function acceptMessage(): Void { return globalThis._azleIc ? globalThis._azleIc.acceptMessage() : undefined; diff --git a/src/lib/ic/reject_message.ts b/src/lib/ic/reject_message.ts index c6cf9a097f..bd54e33123 100644 --- a/src/lib/ic/reject_message.ts +++ b/src/lib/ic/reject_message.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { ic } from '../../lib/ic'; // Used for links in comments import { text } from '../candid/types/primitive/text'; /** From 9835e13854da4d595edd3d8b8698ba44783f5210 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 30 Jan 2024 13:00:58 -0700 Subject: [PATCH 3/5] Test multiple behaviors each round --- dfx/index.ts | 65 +++++++++- property_tests/get_actor.ts | 22 ++-- .../inspect_message/test/generate_tests.ts | 80 +++++++----- .../inspect_message/test/test.ts | 119 +++++++++--------- src/compiler/file_uploader/uploader_actor.ts | 4 +- src/compiler/file_watcher/file_watcher.ts | 4 +- 6 files changed, 193 insertions(+), 101 deletions(-) diff --git a/dfx/index.ts b/dfx/index.ts index dff4c7d2c2..67b11070b5 100644 --- a/dfx/index.ts +++ b/dfx/index.ts @@ -28,7 +28,7 @@ export function getAgentHost(): string { : `http://127.0.0.1:${getWebServerPort()}`; } -export async function createAnonymousAgent() { +export async function getAnonymousAgent() { const agent = new HttpAgent({ host: getAgentHost() }); @@ -38,7 +38,13 @@ export async function createAnonymousAgent() { } } -export async function createAuthenticatedAgent( +/** + * Returns an agent authenticated with the identity with the given name. + * + * @param identityName + * @returns + */ +export async function getAuthenticatedAgent( identityName: string ): Promise { const agent = new HttpAgent({ @@ -53,6 +59,61 @@ export async function createAuthenticatedAgent( return agent; } +/** + * Returns an agent authenticated with the identity with the given name. + * + * IMPORTANT: In order to be synchronous this call will not fetch the root key. + * If you are not on mainnet you will need to fetch the root key separately. + * + * @param identityName + * @returns + */ +export function getAuthenticatedAgentSync(identityName: string): HttpAgent { + const agent = new HttpAgent({ + host: getAgentHost(), + identity: getSecp256k1KeyIdentity(identityName) + }); + + return agent; +} + +/** + * Generates a new identity with the given name if there doesn't already exist + * an identity with that name, and returns an agent authenticated with that + * identity. + * + * IMPORTANT: In order to be synchronous this call will not fetch the root key. + * If you are not on mainnet you will need to fetch the root key separately. + * + * @param identityName + * @returns + */ +export function generateAuthenticatedAgentSync( + identityName: string +): HttpAgent { + if (!identityExists(identityName)) { + generateIdentity(identityName); + } + return getAuthenticatedAgentSync(identityName); +} + +/** + * Generates a new identity with the given name if there doesn't already exist + * an identity with that name, and returns an agent authenticated with that + * identity. + * + * @param identityName + * @returns + */ +export async function generateAuthenticatedAgent( + identityName: string +): Promise { + if (!identityExists(identityName)) { + generateIdentity(identityName); + } + return await getAuthenticatedAgent(identityName); +} + export function whoami(): string { return execSync(`dfx identity whoami`).toString().trim(); } diff --git a/property_tests/get_actor.ts b/property_tests/get_actor.ts index ee8ef0c577..32774f6cd2 100644 --- a/property_tests/get_actor.ts +++ b/property_tests/get_actor.ts @@ -1,6 +1,8 @@ +import { Agent } from '@dfinity/agent'; + import { getCanisterId } from '../dfx'; -export function getActor(parentDir: string) { +export function getActor(parentDir: string, agent?: Agent) { const resolvedPathIndex = require.resolve( `${parentDir}/dfx_generated/canister/index.js` ); @@ -13,10 +15,16 @@ export function getActor(parentDir: string) { // eslint-disable-next-line @typescript-eslint/no-var-requires const { createActor } = require(`${parentDir}/dfx_generated/canister`); - return createActor(getCanisterId('canister'), { - agentOptions: { - host: 'http://127.0.0.1:8000', - verifyQuerySignatures: false // TODO Major issue: https://forum.dfinity.org/t/agent-js-0-20-0-is-released-replica-signed-query-edition/24743/16?u=lastmjs - } - }); + + const options = + agent !== undefined + ? { agent } + : { + agentOptions: { + host: 'http://127.0.0.1:8000', + verifyQuerySignatures: false // TODO Major issue: https://forum.dfinity.org/t/agent-js-0-20-0-is-released-replica-signed-query-edition/24743/16?u=lastmjs + } + }; + + return createActor(getCanisterId('canister'), options); } diff --git a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts index 30b3fefbbc..9041a49b16 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts @@ -1,3 +1,4 @@ +import { Agent } from '@dfinity/agent'; import { deepEqual, getActor, Named } from 'azle/property_tests'; import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; @@ -7,11 +8,10 @@ import { Test } from 'azle/test'; import { InspectMessageBehavior } from './test'; export function generateTests( - mode: 'query' | 'update', functionName: string, params: Named>[], returnType: CandidValueAndMeta, - behavior: InspectMessageBehavior + agents: [Agent, InspectMessageBehavior][] ): Test[][] { const paramValues = params.map( (param) => param.value.value.agentArgumentValue @@ -20,32 +20,56 @@ export function generateTests( const expectedResult = returnType.value.agentResponseValue; return [ - [ - { - name: `${mode} method "${functionName}"`, - test: async () => { - const actor = getActor(__dirname); - try { - const result = await actor[functionName]( - ...paramValues - ); - - if (mode === 'update' && behavior !== 'ACCEPT') { - return { - Err: 'Expected canister method to throw but it did not' - }; - } - - return { Ok: deepEqual(result, expectedResult) }; - } catch (error) { - if (mode === 'update' && behavior !== 'ACCEPT') { - return { Ok: true }; - } - - throw error; - } + agents.map(([agent, behavior]) => { + return generateTest( + agent, + functionName, + paramValues, + expectedResult, + behavior + ); + }) + ]; +} + +function generateTest( + agent: Agent, + functionName: string, + paramValues: CorrespondingJSType[], + expectedResult: CorrespondingJSType, + behavior: InspectMessageBehavior +): Test { + return { + name: `method "${functionName}" expected ${behavior}`, + test: async () => { + await agent.fetchRootKey(); + const actor = getActor(__dirname, agent); + try { + const result = await actor[functionName](...paramValues); + + if (behavior === 'ACCEPT') { + return { Ok: deepEqual(result, expectedResult) }; } + + return { + Err: 'Expected canister method to throw but it did not' + }; + } catch (error: any) { + if (behavior === 'RETURN') { + return { + Ok: error.message.includes('rejected the message') + }; + } + + if (behavior === 'THROW') { + const expectedError = `Method \\"${functionName}\\" not allowed`; + return { + Ok: error.message.includes(expectedError) + }; + } + + throw error; } - ] - ]; + } + }; } diff --git a/property_tests/tests/canister_methods/inspect_message/test/test.ts b/property_tests/tests/canister_methods/inspect_message/test/test.ts index 3a5be04251..99e2fdaee4 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/test.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/test.ts @@ -1,3 +1,5 @@ +import { Agent } from '@dfinity/agent'; +import { generateAuthenticatedAgentSync, getPrincipal } from 'azle/dfx'; import { runPropTests } from 'azle/property_tests'; import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; @@ -6,81 +8,78 @@ import { CanisterConfig } from 'azle/property_tests/arbitraries/canister_arb'; import { InspectMessageMethodArb } from 'azle/property_tests/arbitraries/canister_methods/inspect_message_method_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb'; import fc from 'fast-check'; +import { v4 } from 'uuid'; import { CorrespondingJSType } from '../../../../arbitraries/candid/corresponding_js_type'; import { generateTests } from './generate_tests'; export type InspectMessageBehavior = 'ACCEPT' | 'RETURN' | 'THROW'; -const CanisterConfigArb = fc - .constantFrom('ACCEPT', 'RETURN', 'THROW') - .chain((behavior) => { - const InspectMessageArb = InspectMessageMethodArb({ - generateBody: () => generateInspectMessageMethodBody(behavior), - generateTests: () => [] - }); +const AZLE_ACCEPT_IDENTITY_NAME = `_prop_test_azle_accept_identity_${v4()}`; +const AZLE_RETURN_IDENTITY_NAME = `_prop_test_azle_return_identity_${v4()}`; +const AZLE_THROW_IDENTITY_NAME = `_prop_test_azle_throw_identity_${v4()}`; - const HeterogeneousQueryMethodArb = QueryMethodArb( - fc.array(CandidValueAndMetaArb()), - CandidReturnTypeArb(), - { - generateBody: (_, returnType) => - `return ${returnType.src.valueLiteral}`, - generateTests: (...args) => - generateTests('query', ...args, behavior) - } - ); - - const HeterogeneousUpdateMethodArb = UpdateMethodArb( - fc.array(CandidValueAndMetaArb()), - CandidReturnTypeArb(), - { - generateBody: (_, returnType) => - `return ${returnType.src.valueLiteral}`, - generateTests: (...args) => - generateTests('update', ...args, behavior) - } - ); +function CanisterConfigArb() { + const agents: [Agent, InspectMessageBehavior][] = [ + [generateAuthenticatedAgentSync(AZLE_ACCEPT_IDENTITY_NAME), 'ACCEPT'], + [generateAuthenticatedAgentSync(AZLE_RETURN_IDENTITY_NAME), 'RETURN'], + [generateAuthenticatedAgentSync(AZLE_THROW_IDENTITY_NAME), 'THROW'] + ]; - const small = { - minLength: 0, - maxLength: 20 - }; + const InspectMessageArb = InspectMessageMethodArb({ + generateBody: () => generateInspectMessageMethodBody(), + generateTests: () => [] + }); - return fc.tuple( - InspectMessageArb, - fc.array(HeterogeneousQueryMethodArb, small), - fc.array(HeterogeneousUpdateMethodArb, small) - ); - }) - .map( - ([inspectMessageMethod, queryMethods, updateMethods]): CanisterConfig< - CorrespondingJSType, - CorrespondingJSType - > => { - return { - inspectMessageMethod, - queryMethods, - updateMethods - }; + const HeterogeneousUpdateMethodArb = UpdateMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), + { + generateBody: (_, returnType) => + `return ${returnType.src.valueLiteral}`, + generateTests: (...args) => generateTests(...args, agents) } ); -runPropTests(CanisterArb(CanisterConfigArb)); + const small = { + minLength: 0, + maxLength: 20 + }; -function generateInspectMessageMethodBody( - behavior: InspectMessageBehavior -): string { - if (behavior === 'RETURN') { - return /*TS*/ ''; - } + return fc + .tuple(InspectMessageArb, fc.array(HeterogeneousUpdateMethodArb, small)) + .map( + ([inspectMessageMethod, updateMethods]): CanisterConfig< + CorrespondingJSType, + CorrespondingJSType + > => { + return { + inspectMessageMethod, + updateMethods + }; + } + ); +} - if (behavior === 'THROW') { - return /*TS*/ `throw \`Method "$\{ic.methodName()}" not allowed\``; - } +runPropTests(CanisterArb(CanisterConfigArb())); - return /*TS*/ `ic.acceptMessage();`; +function generateInspectMessageMethodBody(): string { + const acceptPrincipal = getPrincipal(AZLE_ACCEPT_IDENTITY_NAME); + const returnPrincipal = getPrincipal(AZLE_RETURN_IDENTITY_NAME); + const throwPrincipal = getPrincipal(AZLE_THROW_IDENTITY_NAME); + return ` + if (ic.caller().toText() === "${acceptPrincipal}") { + ic.acceptMessage() + return; + } + if (ic.caller().toText() === "${returnPrincipal}") { + return + } + if (ic.caller().toText() === "${throwPrincipal}") { + throw new Error(\`Method "$\{ic.methodName()}" not allowed\`) + } + throw new Error("Unexpected caller") + `; } diff --git a/src/compiler/file_uploader/uploader_actor.ts b/src/compiler/file_uploader/uploader_actor.ts index 8f4e60194d..7c5eb37cdc 100644 --- a/src/compiler/file_uploader/uploader_actor.ts +++ b/src/compiler/file_uploader/uploader_actor.ts @@ -1,6 +1,6 @@ import { Actor, ActorMethod, ActorSubclass } from '@dfinity/agent'; -import { createAuthenticatedAgent } from '../../../dfx'; +import { getAuthenticatedAgent } from '../../../dfx'; export type UploaderActor = ActorSubclass<_SERVICE>; @@ -8,7 +8,7 @@ export async function createActor( canisterId: string, identityName: string ): Promise { - const agent = await createAuthenticatedAgent(identityName); + const agent = await getAuthenticatedAgent(identityName); return Actor.createActor<_SERVICE>( ({ IDL }) => { diff --git a/src/compiler/file_watcher/file_watcher.ts b/src/compiler/file_watcher/file_watcher.ts index 10632ee461..5fb8b5699f 100644 --- a/src/compiler/file_watcher/file_watcher.ts +++ b/src/compiler/file_watcher/file_watcher.ts @@ -2,7 +2,7 @@ import { Actor } from '@dfinity/agent'; import { watch } from 'chokidar'; import { readFileSync, writeFileSync } from 'fs'; -import { createAuthenticatedAgent, whoami } from '../../../dfx'; +import { getAuthenticatedAgent, whoami } from '../../../dfx'; import { getCanisterJavaScript } from '../get_canister_javascript'; import { ok } from '../utils/result'; @@ -57,7 +57,7 @@ async function reloadJs( writeFileSync(reloadedJsPath, canisterJavaScriptResult.ok); - const agent = await createAuthenticatedAgent(whoami()); + const agent = await getAuthenticatedAgent(whoami()); const actor = Actor.createActor( ({ IDL }) => { From 63f19955d0aec94ce103f5a1148293e13f63cb95 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 16 Apr 2024 15:16:08 -0600 Subject: [PATCH 4/5] pr fixes --- dfx/index.ts | 63 +++++++------------ .../inspect_message_method_arb.ts | 4 +- property_tests/get_actor.ts | 21 +++---- .../inspect_message/test/generate_tests.ts | 4 +- .../inspect_message/test/test.ts | 22 ++++--- src/compiler/file_uploader/uploader_actor.ts | 4 +- src/compiler/file_watcher/file_watcher.ts | 4 +- 7 files changed, 53 insertions(+), 69 deletions(-) diff --git a/dfx/index.ts b/dfx/index.ts index 67b11070b5..180b1584a0 100644 --- a/dfx/index.ts +++ b/dfx/index.ts @@ -28,7 +28,7 @@ export function getAgentHost(): string { : `http://127.0.0.1:${getWebServerPort()}`; } -export async function getAnonymousAgent() { +export async function createAnonymousAgent() { const agent = new HttpAgent({ host: getAgentHost() }); @@ -41,12 +41,20 @@ export async function getAnonymousAgent() { /** * Returns an agent authenticated with the identity with the given name. * + * Generates a new identity with the given name if shouldGenerateIdentity and + * the identity doesn't already exist. + * * @param identityName * @returns */ -export async function getAuthenticatedAgent( - identityName: string +export async function createAuthenticatedAgent( + identityName: string, + shouldGenerateIdentity: boolean = false ): Promise { + if (shouldGenerateIdentity && !identityExists(identityName)) { + generateIdentity(identityName); + } + const agent = new HttpAgent({ host: getAgentHost(), identity: getSecp256k1KeyIdentity(identityName) @@ -62,13 +70,23 @@ export async function getAuthenticatedAgent( /** * Returns an agent authenticated with the identity with the given name. * + * Generates a new identity with the given name if shouldGenerateIdentity and + * the identity doesn't already exist. + * * IMPORTANT: In order to be synchronous this call will not fetch the root key. * If you are not on mainnet you will need to fetch the root key separately. * * @param identityName * @returns */ -export function getAuthenticatedAgentSync(identityName: string): HttpAgent { +export function createAuthenticatedAgentSync( + identityName: string, + shouldGenerateIdentity: boolean = false +): HttpAgent { + if (shouldGenerateIdentity && !identityExists(identityName)) { + generateIdentity(identityName); + } + const agent = new HttpAgent({ host: getAgentHost(), identity: getSecp256k1KeyIdentity(identityName) @@ -77,43 +95,6 @@ export function getAuthenticatedAgentSync(identityName: string): HttpAgent { return agent; } -/** - * Generates a new identity with the given name if there doesn't already exist - * an identity with that name, and returns an agent authenticated with that - * identity. - * - * IMPORTANT: In order to be synchronous this call will not fetch the root key. - * If you are not on mainnet you will need to fetch the root key separately. - * - * @param identityName - * @returns - */ -export function generateAuthenticatedAgentSync( - identityName: string -): HttpAgent { - if (!identityExists(identityName)) { - generateIdentity(identityName); - } - return getAuthenticatedAgentSync(identityName); -} - -/** - * Generates a new identity with the given name if there doesn't already exist - * an identity with that name, and returns an agent authenticated with that - * identity. - * - * @param identityName - * @returns - */ -export async function generateAuthenticatedAgent( - identityName: string -): Promise { - if (!identityExists(identityName)) { - generateIdentity(identityName); - } - return await getAuthenticatedAgent(identityName); -} - export function whoami(): string { return execSync(`dfx identity whoami`).toString().trim(); } diff --git a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts index 22b3af53c7..0c9830930b 100644 --- a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts @@ -25,10 +25,10 @@ export function InspectMessageMethodArb(constraints: { }) { return fc .tuple( - UniqueIdentifierArb('canisterMethod'), + UniqueIdentifierArb('canisterProperties'), VoidArb(), CallbackLocationArb, - UniqueIdentifierArb('typeDeclaration') + UniqueIdentifierArb('globalNames') // TODO: This unique id would be better named globalScope or something // But needs to match the same scope as typeDeclarations so I'm using // that for now. diff --git a/property_tests/get_actor.ts b/property_tests/get_actor.ts index 32774f6cd2..3d8c3b83b9 100644 --- a/property_tests/get_actor.ts +++ b/property_tests/get_actor.ts @@ -1,4 +1,4 @@ -import { Agent } from '@dfinity/agent'; +import { Agent, HttpAgent } from '@dfinity/agent'; import { getCanisterId } from '../dfx'; @@ -16,15 +16,12 @@ export function getActor(parentDir: string, agent?: Agent) { // eslint-disable-next-line @typescript-eslint/no-var-requires const { createActor } = require(`${parentDir}/dfx_generated/canister`); - const options = - agent !== undefined - ? { agent } - : { - agentOptions: { - host: 'http://127.0.0.1:8000', - verifyQuerySignatures: false // TODO Major issue: https://forum.dfinity.org/t/agent-js-0-20-0-is-released-replica-signed-query-edition/24743/16?u=lastmjs - } - }; - - return createActor(getCanisterId('canister'), options); + return createActor(getCanisterId('canister'), { + agent: + agent ?? + new HttpAgent({ + host: 'http://127.0.0.1:8000', + verifyQuerySignatures: false // TODO Major issue: https://forum.dfinity.org/t/agent-js-0-20-0-is-released-replica-signed-query-edition/24743/16?u=lastmjs + }) + }); } diff --git a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts index 9041a49b16..84f80b08e4 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/generate_tests.ts @@ -11,7 +11,7 @@ export function generateTests( functionName: string, params: Named>[], returnType: CandidValueAndMeta, - agents: [Agent, InspectMessageBehavior][] + agentAndBehaviors: [Agent, InspectMessageBehavior][] ): Test[][] { const paramValues = params.map( (param) => param.value.value.agentArgumentValue @@ -20,7 +20,7 @@ export function generateTests( const expectedResult = returnType.value.agentResponseValue; return [ - agents.map(([agent, behavior]) => { + agentAndBehaviors.map(([agent, behavior]) => { return generateTest( agent, functionName, diff --git a/property_tests/tests/canister_methods/inspect_message/test/test.ts b/property_tests/tests/canister_methods/inspect_message/test/test.ts index 99e2fdaee4..1192c4f997 100644 --- a/property_tests/tests/canister_methods/inspect_message/test/test.ts +++ b/property_tests/tests/canister_methods/inspect_message/test/test.ts @@ -1,5 +1,5 @@ import { Agent } from '@dfinity/agent'; -import { generateAuthenticatedAgentSync, getPrincipal } from 'azle/dfx'; +import { createAuthenticatedAgentSync, getPrincipal } from 'azle/dfx'; import { runPropTests } from 'azle/property_tests'; import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; @@ -23,9 +23,15 @@ const AZLE_THROW_IDENTITY_NAME = `_prop_test_azle_throw_identity_${v4()}`; function CanisterConfigArb() { const agents: [Agent, InspectMessageBehavior][] = [ - [generateAuthenticatedAgentSync(AZLE_ACCEPT_IDENTITY_NAME), 'ACCEPT'], - [generateAuthenticatedAgentSync(AZLE_RETURN_IDENTITY_NAME), 'RETURN'], - [generateAuthenticatedAgentSync(AZLE_THROW_IDENTITY_NAME), 'THROW'] + [ + createAuthenticatedAgentSync(AZLE_ACCEPT_IDENTITY_NAME, true), + 'ACCEPT' + ], + [ + createAuthenticatedAgentSync(AZLE_RETURN_IDENTITY_NAME, true), + 'RETURN' + ], + [createAuthenticatedAgentSync(AZLE_THROW_IDENTITY_NAME, true), 'THROW'] ]; const InspectMessageArb = InspectMessageMethodArb({ @@ -71,15 +77,15 @@ function generateInspectMessageMethodBody(): string { const throwPrincipal = getPrincipal(AZLE_THROW_IDENTITY_NAME); return ` if (ic.caller().toText() === "${acceptPrincipal}") { - ic.acceptMessage() + ic.acceptMessage(); return; } if (ic.caller().toText() === "${returnPrincipal}") { - return + return; } if (ic.caller().toText() === "${throwPrincipal}") { - throw new Error(\`Method "$\{ic.methodName()}" not allowed\`) + throw new Error(\`Method "$\{ic.methodName()}" not allowed\`); } - throw new Error("Unexpected caller") + throw new Error("Unexpected caller"); `; } diff --git a/src/compiler/file_uploader/uploader_actor.ts b/src/compiler/file_uploader/uploader_actor.ts index 7c5eb37cdc..8f4e60194d 100644 --- a/src/compiler/file_uploader/uploader_actor.ts +++ b/src/compiler/file_uploader/uploader_actor.ts @@ -1,6 +1,6 @@ import { Actor, ActorMethod, ActorSubclass } from '@dfinity/agent'; -import { getAuthenticatedAgent } from '../../../dfx'; +import { createAuthenticatedAgent } from '../../../dfx'; export type UploaderActor = ActorSubclass<_SERVICE>; @@ -8,7 +8,7 @@ export async function createActor( canisterId: string, identityName: string ): Promise { - const agent = await getAuthenticatedAgent(identityName); + const agent = await createAuthenticatedAgent(identityName); return Actor.createActor<_SERVICE>( ({ IDL }) => { diff --git a/src/compiler/file_watcher/file_watcher.ts b/src/compiler/file_watcher/file_watcher.ts index 5fb8b5699f..10632ee461 100644 --- a/src/compiler/file_watcher/file_watcher.ts +++ b/src/compiler/file_watcher/file_watcher.ts @@ -2,7 +2,7 @@ import { Actor } from '@dfinity/agent'; import { watch } from 'chokidar'; import { readFileSync, writeFileSync } from 'fs'; -import { getAuthenticatedAgent, whoami } from '../../../dfx'; +import { createAuthenticatedAgent, whoami } from '../../../dfx'; import { getCanisterJavaScript } from '../get_canister_javascript'; import { ok } from '../utils/result'; @@ -57,7 +57,7 @@ async function reloadJs( writeFileSync(reloadedJsPath, canisterJavaScriptResult.ok); - const agent = await getAuthenticatedAgent(whoami()); + const agent = await createAuthenticatedAgent(whoami()); const actor = Actor.createActor( ({ IDL }) => { From 569f341ddef0785ab83971c68095eb9bf08db017 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 17 Apr 2024 13:35:44 -0600 Subject: [PATCH 5/5] pr fixes --- .../arbitraries/canister_methods/inspect_message_method_arb.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts index 0c9830930b..4b5bdd450e 100644 --- a/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts @@ -29,9 +29,6 @@ export function InspectMessageMethodArb(constraints: { VoidArb(), CallbackLocationArb, UniqueIdentifierArb('globalNames') - // TODO: This unique id would be better named globalScope or something - // But needs to match the same scope as typeDeclarations so I'm using - // that for now. ) .map( ([