Skip to content

Commit

Permalink
examples fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Feb 10, 2025
1 parent cce5114 commit 1ee59ed
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"module": "ES2022",
"moduleResolution": "node",
"strict": true,
"target": "ES2024",
"outDir": "HACK_BECAUSE_OF_ALLOW_JS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"module": "ES2022",
"moduleResolution": "node",
"strict": true,
"target": "ES2024",
"outDir": "HACK_BECAUSE_OF_ALLOW_JS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"module": "ES2022",
"moduleResolution": "node",
"strict": true,
"target": "ES2024",
"outDir": "HACK_BECAUSE_OF_ALLOW_JS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"module": "ES2022",
"moduleResolution": "node",
"strict": true,
"target": "ES2024",
"outDir": "HACK_BECAUSE_OF_ALLOW_JS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
14 changes: 10 additions & 4 deletions examples/stable/test/property/ic_api/msg_reject/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand All @@ -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]));
Expand Down
7 changes: 4 additions & 3 deletions examples/stable/test/property/ic_api/trap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1ee59ed

Please sign in to comment.