From 1ee59ed111430a481a17e94aba1b291036f1e756 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 10 Feb 2025 12:43:15 -0700 Subject: [PATCH] examples fixes --- .../motoko_examples/phone-book/tsconfig.json | 1 + .../motoko_examples/superheroes/tsconfig.json | 1 + .../http_server/fetch_ic/src/frontend/index.ts | 2 +- .../complex_init/src/complex_init/index.ts | 2 +- .../end_to_end/candid_rpc/ic_api/src/index.ts | 5 ++++- .../candid_rpc/manual_reply/src/index.ts | 10 ++++++++-- .../motoko_examples/cert-var/test/tests.ts | 15 +++++++-------- .../motoko_examples/phone-book/tsconfig.json | 1 + .../motoko_examples/superheroes/tsconfig.json | 1 + .../motoko_examples/whoami/src/index.ts | 2 +- .../rejections/src/some_canister/index.ts | 5 ++++- .../property/ic_api/certified_data/test/tests.ts | 6 +++--- .../test/property/ic_api/msg_reject/src/index.ts | 14 ++++++++++---- .../ic_api/msg_reply/test/generate_canister.ts | 4 ++-- .../stable/test/property/ic_api/trap/src/index.ts | 7 ++++--- 15 files changed, 49 insertions(+), 27 deletions(-) diff --git a/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json b/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json index 8ec44f26e3..300bcee985 100644 --- a/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json +++ b/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json @@ -5,6 +5,7 @@ "forceConsistentCasingInFileNames": true, "jsx": "react", "module": "ES2022", + "moduleResolution": "node", "strict": true, "target": "ES2024", "outDir": "HACK_BECAUSE_OF_ALLOW_JS" diff --git a/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json b/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json index 8ec44f26e3..300bcee985 100644 --- a/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json +++ b/examples/experimental/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json @@ -5,6 +5,7 @@ "forceConsistentCasingInFileNames": true, "jsx": "react", "module": "ES2022", + "moduleResolution": "node", "strict": true, "target": "ES2024", "outDir": "HACK_BECAUSE_OF_ALLOW_JS" diff --git a/examples/experimental/test/end_to_end/http_server/fetch_ic/src/frontend/index.ts b/examples/experimental/test/end_to_end/http_server/fetch_ic/src/frontend/index.ts index f0cd262fec..b3c23dfb6c 100644 --- a/examples/experimental/test/end_to_end/http_server/fetch_ic/src/frontend/index.ts +++ b/examples/experimental/test/end_to_end/http_server/fetch_ic/src/frontend/index.ts @@ -217,7 +217,7 @@ export class AzleApp extends LitElement { ['Authorization', toJwt(this.identity)], ['Content-Type', 'application/json'] ], - body: encodedText.buffer + body: encodedText } ); const responseJson = await response.json(); diff --git a/examples/stable/test/end_to_end/candid_rpc/complex_init/src/complex_init/index.ts b/examples/stable/test/end_to_end/candid_rpc/complex_init/src/complex_init/index.ts index e5890bb769..08243cccf8 100644 --- a/examples/stable/test/end_to_end/candid_rpc/complex_init/src/complex_init/index.ts +++ b/examples/stable/test/end_to_end/candid_rpc/complex_init/src/complex_init/index.ts @@ -13,7 +13,7 @@ export default class { init(): void { const tuple = IDL.decode( [IDL.Tuple(IDL.Text, User)], - msgArgData() + new Uint8Array(msgArgData()).buffer )[0] as [string, User]; this.greeting = tuple[0]; diff --git a/examples/stable/test/end_to_end/candid_rpc/ic_api/src/index.ts b/examples/stable/test/end_to_end/candid_rpc/ic_api/src/index.ts index db7431da75..358c60f5ea 100644 --- a/examples/stable/test/end_to_end/candid_rpc/ic_api/src/index.ts +++ b/examples/stable/test/end_to_end/candid_rpc/ic_api/src/index.ts @@ -94,7 +94,10 @@ export default class { @query([IDL.Text], IDL.Empty, { manual: true }) msgReject(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; msgReject(message); } diff --git a/examples/stable/test/end_to_end/candid_rpc/manual_reply/src/index.ts b/examples/stable/test/end_to_end/candid_rpc/manual_reply/src/index.ts index 1ace73c29c..ab2e5a3f26 100644 --- a/examples/stable/test/end_to_end/candid_rpc/manual_reply/src/index.ts +++ b/examples/stable/test/end_to_end/candid_rpc/manual_reply/src/index.ts @@ -98,7 +98,10 @@ export default class { // Updates @update([IDL.Text], IDL.Text, { manual: true }) manualUpdate(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; if (message === 'reject') { msgReject(message); @@ -193,7 +196,10 @@ export default class { // Queries @query([IDL.Text], IDL.Text, { manual: true }) manualQuery(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; if (message === 'reject') { msgReject(message); diff --git a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/cert-var/test/tests.ts b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/cert-var/test/tests.ts index a618725ec4..e8fda2052e 100644 --- a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/cert-var/test/tests.ts +++ b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/cert-var/test/tests.ts @@ -123,17 +123,16 @@ function verifyCertifiedData( ): void { const rawData = findLookupValueOrThrow(certificate, [ 'canister', - canisterPrincipal.toUint8Array(), + new Uint8Array(canisterPrincipal.toUint8Array()).buffer, 'certified_data' ]); - const decodedData = IDL.decode( - [IDL.Nat32], - new Uint8Array([ - ...new TextEncoder().encode('DIDL\x00\x01\x79'), - ...new Uint8Array(rawData) - ]) - )[0]; + const candidEncodedRawData: ArrayBuffer = new Uint8Array([ + ...new TextEncoder().encode('DIDL\x00\x01\x79'), + ...new Uint8Array(rawData) + ]).buffer; + + const decodedData = IDL.decode([IDL.Nat32], candidEncodedRawData)[0]; expect(expectedValue).toBe(decodedData); } diff --git a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json index 8ec44f26e3..300bcee985 100644 --- a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json +++ b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/phone-book/tsconfig.json @@ -5,6 +5,7 @@ "forceConsistentCasingInFileNames": true, "jsx": "react", "module": "ES2022", + "moduleResolution": "node", "strict": true, "target": "ES2024", "outDir": "HACK_BECAUSE_OF_ALLOW_JS" diff --git a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json index 8ec44f26e3..300bcee985 100644 --- a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json +++ b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/superheroes/tsconfig.json @@ -5,6 +5,7 @@ "forceConsistentCasingInFileNames": true, "jsx": "react", "module": "ES2022", + "moduleResolution": "node", "strict": true, "target": "ES2024", "outDir": "HACK_BECAUSE_OF_ALLOW_JS" diff --git a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/whoami/src/index.ts b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/whoami/src/index.ts index eea2115526..ce1ae30095 100644 --- a/examples/stable/test/end_to_end/candid_rpc/motoko_examples/whoami/src/index.ts +++ b/examples/stable/test/end_to_end/candid_rpc/motoko_examples/whoami/src/index.ts @@ -27,7 +27,7 @@ class WhoAmI { postUpgrade(): void { const somebody = IDL.decode( [IDL.Principal], - msgArgData() + new Uint8Array(msgArgData()).buffer )[0] as unknown as Principal; this.install = msgCaller(); diff --git a/examples/stable/test/end_to_end/candid_rpc/rejections/src/some_canister/index.ts b/examples/stable/test/end_to_end/candid_rpc/rejections/src/some_canister/index.ts index 75a91711f1..0b4b2c79e0 100644 --- a/examples/stable/test/end_to_end/candid_rpc/rejections/src/some_canister/index.ts +++ b/examples/stable/test/end_to_end/candid_rpc/rejections/src/some_canister/index.ts @@ -3,7 +3,10 @@ import { IDL, msgArgData, msgReject, query } from 'azle'; export default class { @query([IDL.Text], IDL.Empty, { manual: true }) reject(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; msgReject(message); } diff --git a/examples/stable/test/property/ic_api/certified_data/test/tests.ts b/examples/stable/test/property/ic_api/certified_data/test/tests.ts index 73c502e3ec..98d3125ceb 100644 --- a/examples/stable/test/property/ic_api/certified_data/test/tests.ts +++ b/examples/stable/test/property/ic_api/certified_data/test/tests.ts @@ -406,17 +406,17 @@ function verifyCertifiedData( ): void { const rawData = findLookupValueOrThrow(certificate, [ 'canister', - canisterPrincipal.toUint8Array(), + new Uint8Array(canisterPrincipal.toUint8Array()).buffer, 'certified_data' ]); const lengthByte = String.fromCharCode(expectedValue.length); - const candidEncodedRawData = new Uint8Array([ + const candidEncodedRawData: ArrayBuffer = new Uint8Array([ ...new TextEncoder().encode('DIDL\x01\x6d\x7b\x01\x00'), ...new TextEncoder().encode(lengthByte), ...new Uint8Array(rawData) - ]); + ]).buffer; const decodedData = IDL.decode( [IDL.Vec(IDL.Nat8)], diff --git a/examples/stable/test/property/ic_api/msg_reject/src/index.ts b/examples/stable/test/property/ic_api/msg_reject/src/index.ts index 42ca0ca08f..47ba5610ec 100644 --- a/examples/stable/test/property/ic_api/msg_reject/src/index.ts +++ b/examples/stable/test/property/ic_api/msg_reject/src/index.ts @@ -3,14 +3,20 @@ import { IDL, msgArgData, msgReject, msgReply, query, update } from 'azle'; export default class { @query([IDL.Text], undefined, { manual: true }) alwaysRejectQuery(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; msgReject(`reject proptest message: ${message}`); } @update([IDL.Text], undefined, { manual: true }) alwaysRejectUpdate(): void { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; msgReject(`reject proptest message: ${message}`); } @@ -19,7 +25,7 @@ export default class { evenOrRejectQuery(): void { const number = IDL.decode( [IDL.Int], - msgArgData() + new Uint8Array(msgArgData()).buffer )[0] as unknown as bigint; if (number % 2n === 0n) { @@ -35,7 +41,7 @@ export default class { evenOrRejectUpdate(): void { const number = IDL.decode( [IDL.Int], - msgArgData() + new Uint8Array(msgArgData()).buffer )[0] as unknown as bigint; if (number % 2n === 0n) { diff --git a/examples/stable/test/property/ic_api/msg_reply/test/generate_canister.ts b/examples/stable/test/property/ic_api/msg_reply/test/generate_canister.ts index 38298a0a60..f6e1f1a934 100644 --- a/examples/stable/test/property/ic_api/msg_reply/test/generate_canister.ts +++ b/examples/stable/test/property/ic_api/msg_reply/test/generate_canister.ts @@ -14,7 +14,7 @@ ${variableAliasDeclarations.join('\n')} export default class { @query([${idlType}], ${idlType}, { manual: true }) alwaysReplyQuery(): void { - const input = IDL.decode([${idlType}], msgArgData())[0] as unknown as ${tsType}; + const input = IDL.decode([${idlType}], new Uint8Array(msgArgData()).buffer)[0] as unknown as ${tsType}; const encoded = new Uint8Array(IDL.encode([${idlType}], [input])); @@ -23,7 +23,7 @@ export default class { @update([${idlType}], ${idlType}, { manual: true }) alwaysReplyUpdate(): void { - const input = IDL.decode([${idlType}], msgArgData())[0] as unknown as ${tsType}; + const input = IDL.decode([${idlType}], new Uint8Array(msgArgData()).buffer)[0] as unknown as ${tsType}; const encoded = new Uint8Array(IDL.encode([${idlType}], [input])); diff --git a/examples/stable/test/property/ic_api/trap/src/index.ts b/examples/stable/test/property/ic_api/trap/src/index.ts index c673295dd6..ab0b167324 100644 --- a/examples/stable/test/property/ic_api/trap/src/index.ts +++ b/examples/stable/test/property/ic_api/trap/src/index.ts @@ -16,11 +16,12 @@ export default class { } if (msgMethodName() === 'inspectMessageTrap') { - const message = IDL.decode([IDL.Text], msgArgData())[0] as string; + const message = IDL.decode( + [IDL.Text], + new Uint8Array(msgArgData()).buffer + )[0] as string; trap(`trap proptest message: ${message}`); - - return false; } else { return true; }