diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c54ec1fc9c..97a3e5a96e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -212,7 +212,7 @@ jobs: with: node-version: 18 - if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }} - run: DFX_VERSION=0.15.3-largewasm.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + run: DFX_VERSION=0.17.0-beta.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" - if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }} uses: actions/cache@v3 with: diff --git a/examples/async_await/package.json b/examples/async_await/package.json index 41245efd75..dc327b50e3 100644 --- a/examples/async_await/package.json +++ b/examples/async_await/package.json @@ -1,7 +1,8 @@ { "scripts": { - "pretest": "ts-node --transpile-only --ignore=false test/pretest.ts", - "test": "ts-node --transpile-only --ignore=false test/test.ts" + "pre_tests": "ts-node --transpile-only --ignore=false test/pretest.ts", + "tests": "npm run pre_tests && ts-node --transpile-only --ignore=false test/test.ts", + "test": "AZLE_TEST_FETCH=false npm run tests && AZLE_TEST_FETCH=true npm run tests" }, "dependencies": { "azle": "0.19.0" diff --git a/examples/canister/dfx.json b/examples/canister/dfx.json index aca1128233..39255d8d46 100644 --- a/examples/canister/dfx.json +++ b/examples/canister/dfx.json @@ -11,7 +11,8 @@ "output": "test/dfx_generated/canister", "node_compatibility": true }, - "env": ["SOME_CANISTER_PRINCIPAL"] + "env": ["SOME_CANISTER_PRINCIPAL", "AZLE_TEST_FETCH"], + "assets": ["src"] }, "some_canister": { "type": "custom", diff --git a/examples/canister/package-lock.json b/examples/canister/package-lock.json index da042fb953..8f1a81dd08 100644 --- a/examples/canister/package-lock.json +++ b/examples/canister/package-lock.json @@ -8,7 +8,7 @@ "azle": "0.19.0" }, "devDependencies": { - "@dfinity/agent": "0.15.4", + "@dfinity/agent": "^0.21.4", "ts-node": "10.7.0", "typescript": "4.6.3" } @@ -33,211 +33,41 @@ } }, "node_modules/@dfinity/agent": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.15.4.tgz", - "integrity": "sha512-JuWaLUUtdGJx2DwHgnGrtTNwF5bC6a+izMbcHeN2M0RSaukeVNkRdYz4Bfxg7yTwdFxQRfQWcXcwvKF8/R2IEg==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.21.4.tgz", + "integrity": "sha512-k5k8v1BmDE8RStC22FtuqbFzMLaQAQL3cE/wF45ZMKP4WmBBmCPss75RDgIVGiFwLGEKKKXE1muHQDy9g+m5yQ==", "dev": true, "dependencies": { + "@noble/curves": "^1.2.0", + "@noble/hashes": "^1.3.1", "base64-arraybuffer": "^0.2.0", - "bignumber.js": "^9.0.0", "borc": "^2.1.1", - "js-sha256": "0.9.0", - "simple-cbor": "^0.4.1", - "ts-node": "^10.8.2" - }, - "peerDependencies": { - "@dfinity/candid": "^0.15.4", - "@dfinity/principal": "^0.15.4" - } - }, - "node_modules/@dfinity/agent/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/agent/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" + "buffer": "^6.0.3", + "simple-cbor": "^0.4.1" }, "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 - } + "@dfinity/candid": "^0.21.4", + "@dfinity/principal": "^0.21.4" } }, "node_modules/@dfinity/candid": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.15.4.tgz", - "integrity": "sha512-ImoZ18i95DDstn+EXm/Y1ms7RqF1KVS7+KqZLNvpHFTlcOgfAQc5Bq8W6l1nfkOqeh7wcehDYdjFJwLxBoeTlw==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.21.4.tgz", + "integrity": "sha512-BRdgLQjPbqEZDRIR985jpy92uwhdBn4mN2D8StMKyOXQLmR6hKSD0p/P2b632Sh7zPUY8HuiA8njpMZ67JEyAg==", "dev": true, "peer": true, - "dependencies": { - "ts-node": "^10.8.2" - } - }, - "node_modules/@dfinity/candid/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, - "peer": true, - "dependencies": { - "@jridgewell/trace-mapping": "0.3.9" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@dfinity/candid/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, - "peer": 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 - } + "@dfinity/principal": "^0.21.4" } }, "node_modules/@dfinity/principal": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.15.4.tgz", - "integrity": "sha512-ZH0InIXaIQqXfUDgkSa0S+9VlkAduhu2JJ984KtRs3BSHUyxG32OGnRcvxfJDdm6GHXWndTWoQUraHPoA3RplQ==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.21.4.tgz", + "integrity": "sha512-r9d+9BYZdFMzrq1+zcdIg6q6tlWeZ9SKnakVdhQ21qUJ6iDe0yxDlah6k9QKEh6fVsg2yv95nID++nqEosvt1Q==", "dev": true, "peer": true, "dependencies": { - "js-sha256": "^0.9.0", - "ts-node": "^10.8.2" - } - }, - "node_modules/@dfinity/principal/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, - "peer": true, - "dependencies": { - "@jridgewell/trace-mapping": "0.3.9" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@dfinity/principal/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, - "peer": 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 - } + "@noble/hashes": "^1.3.1" } }, "node_modules/@esbuild/android-arm": { @@ -570,35 +400,22 @@ "node": ">=12" } }, - "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", - "dev": true, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "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==", + "node_modules/@noble/curves": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz", + "integrity": "sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==", "dev": true, "dependencies": { - "@jridgewell/resolve-uri": "^3.0.3", - "@jridgewell/sourcemap-codec": "^1.4.10" + "@noble/hashes": "1.3.3" + }, + "funding": { + "url": "https://paulmillr.com/funding/" } }, "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==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", "engines": { "node": ">= 16" }, @@ -896,29 +713,6 @@ "@noble/hashes": "^1.3.1" } }, - "node_modules/azle/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/azle/node_modules/ts-node": { "version": "10.3.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", @@ -1000,9 +794,9 @@ ] }, "node_modules/bignumber.js": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", - "integrity": "sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", "dev": true, "engines": { "node": "*" @@ -1026,7 +820,7 @@ "node": ">=4" } }, - "node_modules/buffer": { + "node_modules/borc/node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", @@ -1050,6 +844,29 @@ "ieee754": "^1.1.13" } }, + "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/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1360,138 +1177,35 @@ } }, "@dfinity/agent": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.15.4.tgz", - "integrity": "sha512-JuWaLUUtdGJx2DwHgnGrtTNwF5bC6a+izMbcHeN2M0RSaukeVNkRdYz4Bfxg7yTwdFxQRfQWcXcwvKF8/R2IEg==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-0.21.4.tgz", + "integrity": "sha512-k5k8v1BmDE8RStC22FtuqbFzMLaQAQL3cE/wF45ZMKP4WmBBmCPss75RDgIVGiFwLGEKKKXE1muHQDy9g+m5yQ==", "dev": true, "requires": { + "@noble/curves": "^1.2.0", + "@noble/hashes": "^1.3.1", "base64-arraybuffer": "^0.2.0", - "bignumber.js": "^9.0.0", "borc": "^2.1.1", - "js-sha256": "0.9.0", - "simple-cbor": "^0.4.1", - "ts-node": "^10.8.2" - }, - "dependencies": { - "@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, - "requires": { - "@jridgewell/trace-mapping": "0.3.9" - } - }, - "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, - "requires": { - "@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" - } - } + "buffer": "^6.0.3", + "simple-cbor": "^0.4.1" } }, "@dfinity/candid": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.15.4.tgz", - "integrity": "sha512-ImoZ18i95DDstn+EXm/Y1ms7RqF1KVS7+KqZLNvpHFTlcOgfAQc5Bq8W6l1nfkOqeh7wcehDYdjFJwLxBoeTlw==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-0.21.4.tgz", + "integrity": "sha512-BRdgLQjPbqEZDRIR985jpy92uwhdBn4mN2D8StMKyOXQLmR6hKSD0p/P2b632Sh7zPUY8HuiA8njpMZ67JEyAg==", "dev": true, "peer": true, - "requires": { - "ts-node": "^10.8.2" - }, - "dependencies": { - "@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, - "peer": true, - "requires": { - "@jridgewell/trace-mapping": "0.3.9" - } - }, - "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, - "peer": true, - "requires": { - "@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" - } - } - } + "requires": {} }, "@dfinity/principal": { - "version": "0.15.4", - "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.15.4.tgz", - "integrity": "sha512-ZH0InIXaIQqXfUDgkSa0S+9VlkAduhu2JJ984KtRs3BSHUyxG32OGnRcvxfJDdm6GHXWndTWoQUraHPoA3RplQ==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.21.4.tgz", + "integrity": "sha512-r9d+9BYZdFMzrq1+zcdIg6q6tlWeZ9SKnakVdhQ21qUJ6iDe0yxDlah6k9QKEh6fVsg2yv95nID++nqEosvt1Q==", "dev": true, "peer": true, "requires": { - "js-sha256": "^0.9.0", - "ts-node": "^10.8.2" - }, - "dependencies": { - "@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, - "peer": true, - "requires": { - "@jridgewell/trace-mapping": "0.3.9" - } - }, - "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, - "peer": true, - "requires": { - "@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" - } - } + "@noble/hashes": "^1.3.1" } }, "@esbuild/android-arm": { @@ -1626,32 +1340,19 @@ "integrity": "sha512-HP0GDNla1T3ZL8Ko/SHAS2GgtjOg+VmWnnYLhuTksr++EnduYB0f3Y2LzHsUwb2iQ13JGoY6G3R8h6Du/WG6uA==", "optional": true }, - "@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", - "dev": true - }, - "@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, - "@jridgewell/trace-mapping": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", - "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "@noble/curves": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz", + "integrity": "sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==", "dev": true, "requires": { - "@jridgewell/resolve-uri": "^3.0.3", - "@jridgewell/sourcemap-codec": "^1.4.10" + "@noble/hashes": "1.3.3" } }, "@noble/hashes": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", - "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==" + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" }, "@swc/core": { "version": "1.3.91", @@ -1820,15 +1521,6 @@ "@noble/hashes": "^1.3.1" } }, - "buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "ts-node": { "version": "10.3.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", @@ -1867,9 +1559,9 @@ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, "bignumber.js": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", - "integrity": "sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", "dev": true }, "borc": { @@ -1885,16 +1577,27 @@ "iso-url": "~0.4.7", "json-text-sequence": "~0.1.0", "readable-stream": "^3.6.0" + }, + "dependencies": { + "buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + } } }, "buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "dev": true, + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", "requires": { "base64-js": "^1.3.1", - "ieee754": "^1.1.13" + "ieee754": "^1.2.1" } }, "commander": { diff --git a/examples/canister/package.json b/examples/canister/package.json index 85416294cc..dc7666456a 100644 --- a/examples/canister/package.json +++ b/examples/canister/package.json @@ -1,13 +1,14 @@ { "scripts": { - "pretest": "ts-node --transpile-only --ignore=false test/pretest.ts", - "test": "ts-node --transpile-only --ignore=false test/test.ts" + "pre_tests": "ts-node --transpile-only --ignore=false test/pretest.ts", + "tests": "npm run pre_tests && ts-node --transpile-only --ignore=false test/test.ts", + "test": "AZLE_TEST_FETCH=false npm run tests && AZLE_TEST_FETCH=true npm run tests" }, "dependencies": { "azle": "0.19.0" }, "devDependencies": { - "@dfinity/agent": "0.15.4", + "@dfinity/agent": "^0.21.4", "ts-node": "10.7.0", "typescript": "4.6.3" } diff --git a/examples/canister/src/index.ts b/examples/canister/src/index.ts index 454d917ab3..4c6cc631ee 100644 --- a/examples/canister/src/index.ts +++ b/examples/canister/src/index.ts @@ -4,6 +4,7 @@ import { Principal, query, Record, + serialize, text, update, Vec @@ -19,22 +20,12 @@ export default Canister({ return someCanister; }), canisterReturnType: query([], SomeCanister, () => { - return SomeCanister( - Principal.fromText( - process.env.SOME_CANISTER_PRINCIPAL ?? - ic.trap('process.env.SOME_CANISTER_PRINCIPAL is undefined') - ) - ); + return SomeCanister(Principal.fromText(getSomeCanisterPrincipal())); }), canisterNestedReturnType: update([], Wrapper, () => { return { someCanister: SomeCanister( - Principal.fromText( - process.env.SOME_CANISTER_PRINCIPAL ?? - ic.trap( - 'process.env.SOME_CANISTER_PRINCIPAL is undefined' - ) - ) + Principal.fromText(getSomeCanisterPrincipal()) ) }; }), @@ -49,7 +40,29 @@ export default Canister({ [SomeCanister], text, async (someCanister) => { - return await ic.call(someCanister.update1); + if (process.env.AZLE_TEST_FETCH === 'true') { + const response = await fetch( + `icp://${getSomeCanisterPrincipal()}/update1`, + { + body: serialize({ + candidPath: `/src/some_canister.did` + }) + } + ); + const responseJson = await response.json(); + + return responseJson; + } else { + return await ic.call(someCanister.update1); + } } ) }); + +function getSomeCanisterPrincipal(): string { + if (process.env.SOME_CANISTER_PRINCIPAL !== undefined) { + return process.env.SOME_CANISTER_PRINCIPAL; + } + + throw new Error(`process.env.SOME_CANISTER_PRINCIPAL is not defined`); +} diff --git a/examples/canister/test/tests.ts b/examples/canister/test/tests.ts index af62813fd1..3941e325d9 100644 --- a/examples/canister/test/tests.ts +++ b/examples/canister/test/tests.ts @@ -1,7 +1,7 @@ import { getCanisterId, Test } from 'azle/test'; import { _SERVICE } from './dfx_generated/canister/canister.did'; import { ActorSubclass } from '@dfinity/agent'; -import { execSync } from 'child_process'; +import { Principal } from '@dfinity/principal'; // TODO these tests should be rewritten to use @dfinity/agent once this issue is resolved: https://github.com/dfinity/agent-js/issues/702 // TODO this issue also needs to be resolved: https://forum.dfinity.org/t/services-wont-deserialize-properly-if-functions-arent-in-alphabetical-order/20885 @@ -10,85 +10,62 @@ export function getTests(canister: ActorSubclass<_SERVICE>): Test[] { { name: 'canisterParam', test: async () => { - const result = execSync( - `dfx canister call canister canisterParam '(service "aaaaa-aa")'` - ) - .toString() - .trim(); + const result = await canister.canisterParam( + Principal.fromText('aaaaa-aa') + ); return { - Ok: result === '(service "aaaaa-aa")' + Ok: result.toText() === 'aaaaa-aa' }; } }, { name: 'canisterReturnType', test: async () => { - const result = execSync( - `dfx canister call canister canisterReturnType` - ) - .toString() - .trim(); + const result = await canister.canisterReturnType(); return { - Ok: - result === - `(service "${getCanisterId('some_canister')}")` + Ok: result.toText() === getCanisterId('some_canister') }; } }, { name: 'canisterNestedReturnType', test: async () => { - const result = execSync( - `dfx canister call canister canisterNestedReturnType` - ) - .toString() - .trim(); + const result = await canister.canisterNestedReturnType(); return { Ok: - result === - `(record { someCanister = service "${getCanisterId( - 'some_canister' - )}" })` + result.someCanister.toText() === + getCanisterId('some_canister') }; } }, { name: 'canisterList', test: async () => { - const result = execSync( - `dfx canister call canister canisterList '(vec { service "r7inp-6aaaa-aaaaa-aaabq-cai"; service "rrkah-fqaaa-aaaaa-aaaaq-cai" })'` - ) - .toString() - .trim(); + const result = await canister.canisterList([ + Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'), + Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai') + ]); return { Ok: - result === - `( - vec { - service "r7inp-6aaaa-aaaaa-aaabq-cai"; - service "rrkah-fqaaa-aaaaa-aaaaq-cai"; - }, -)` + result.length === 2 && + result[0].toText() === 'r7inp-6aaaa-aaaaa-aaabq-cai' && + result[1].toText() === 'rrkah-fqaaa-aaaaa-aaaaq-cai' }; } }, { name: 'canisterCrossCanisterCall', test: async () => { - const result = execSync( - `dfx canister call canister canisterCrossCanisterCall '(service "${getCanisterId( - 'some_canister' - )}")'` - ) - .toString() - .trim(); + const result = await canister.canisterCrossCanisterCall( + Principal.fromText(getCanisterId('some_canister')) + ); return { - Ok: result === '("SomeCanister update1")' + Ok: result === 'SomeCanister update1' }; } } diff --git a/examples/cross_canister_calls/src/canister1/index.ts b/examples/cross_canister_calls/src/canister1/index.ts index 659fe3be8e..af53e742fc 100644 --- a/examples/cross_canister_calls/src/canister1/index.ts +++ b/examples/cross_canister_calls/src/canister1/index.ts @@ -20,16 +20,19 @@ let canister2: typeof Canister2; export default Canister({ init: init([], () => { - canister2 = Canister2(Principal.fromText(getCanister2Id())); + canister2 = Canister2(Principal.fromText(getCanister2Principal())); }), transfer: update([text, text, nat64], nat64, async (from, to, amount) => { if (process.env.AZLE_TEST_FETCH === 'true') { - const response = await fetch(`icp://${getCanister2Id()}/transfer`, { - body: serialize({ - candidPath: 'canister2/index.did', - args: [from, to, amount] - }) - }); + const response = await fetch( + `icp://${getCanister2Principal()}/transfer`, + { + body: serialize({ + candidPath: 'canister2/index.did', + args: [from, to, amount] + }) + } + ); const responseJson = await response.json(); return responseJson; @@ -41,12 +44,15 @@ export default Canister({ }), balance: update([text], nat64, async (id) => { if (process.env.AZLE_TEST_FETCH === 'true') { - const response = await fetch(`icp://${getCanister2Id()}/balance`, { - body: serialize({ - candidPath: 'canister2/index.did', - args: [id] - }) - }); + const response = await fetch( + `icp://${getCanister2Principal()}/balance`, + { + body: serialize({ + candidPath: 'canister2/index.did', + args: [id] + }) + } + ); const responseJson = response.json(); return responseJson; @@ -58,12 +64,15 @@ export default Canister({ }), account: update([AccountArgs], Opt(Account), async (args) => { if (process.env.AZLE_TEST_FETCH === 'true') { - const response = await fetch(`icp://${getCanister2Id()}/account`, { - body: serialize({ - candidPath: 'canister2/index.did', - args: [args] - }) - }); + const response = await fetch( + `icp://${getCanister2Principal()}/account`, + { + body: serialize({ + candidPath: 'canister2/index.did', + args: [args] + }) + } + ); const responseJson = await response.json(); if (responseJson.length === 1) { @@ -79,12 +88,15 @@ export default Canister({ }), accounts: update([], Vec(Account), async () => { if (process.env.AZLE_TEST_FETCH === 'true') { - const response = await fetch(`icp://${getCanister2Id()}/accounts`, { - body: serialize({ - candidPath: 'canister2/index.did', - args: [] - }) - }); + const response = await fetch( + `icp://${getCanister2Principal()}/accounts`, + { + body: serialize({ + candidPath: 'canister2/index.did', + args: [] + }) + } + ); const responseJson = await response.json(); return responseJson; @@ -96,12 +108,15 @@ export default Canister({ }), trap: update([], text, async () => { if (process.env.AZLE_TEST_FETCH === 'true') { - const response = await fetch(`icp://${getCanister2Id()}/trap`, { - body: serialize({ - candidPath: 'canister2/index.did', - args: [] - }) - }); + const response = await fetch( + `icp://${getCanister2Principal()}/trap`, + { + body: serialize({ + candidPath: 'canister2/index.did', + args: [] + }) + } + ); const responseJson = await response.json(); return responseJson; @@ -121,7 +136,7 @@ export default Canister({ }) }); -function getCanister2Id(): string { +function getCanister2Principal(): string { if (process.env.CANISTER2_PRINCIPAL !== undefined) { return process.env.CANISTER2_PRINCIPAL; }