diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64b9d344be..ec764033b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -263,7 +263,6 @@ jobs: "tests/end_to_end/candid_rpc/class_syntax/timers", "tests/end_to_end/candid_rpc/class_syntax/tuple_types", "tests/end_to_end/candid_rpc/class_syntax/update", - "tests/end_to_end/candid_rpc/class_syntax/vanilla_js", ] END ) diff --git a/src/lib/stable/globals.ts b/src/lib/stable/globals.ts new file mode 100644 index 0000000000..6f6e583e2b --- /dev/null +++ b/src/lib/stable/globals.ts @@ -0,0 +1,4 @@ +import { TextDecoder, TextEncoder } from 'text-encoding'; + +globalThis.TextDecoder = TextDecoder; +globalThis.TextEncoder = TextEncoder; diff --git a/src/lib/stable/index.ts b/src/lib/stable/index.ts index 79a172ba8c..5e9a4e3b8b 100644 --- a/src/lib/stable/index.ts +++ b/src/lib/stable/index.ts @@ -1,3 +1,4 @@ +import './globals'; export * from '../stable_structures/stable_b_tree_map'; export * from '../stable_structures/stable_json'; export { heartbeat } from './heartbeat'; diff --git a/src/lib/stable/system_types/rejection_code.ts b/src/lib/stable/system_types/rejection_code.ts index 9b6fd09520..5d7d29a98c 100644 --- a/src/lib/stable/system_types/rejection_code.ts +++ b/src/lib/stable/system_types/rejection_code.ts @@ -1,20 +1,16 @@ -import { IDL } from '..'; +import { IDL } from '@dfinity/candid'; /** * Indicates an error was encountered during a canister method. */ export const RejectionCode = IDL.Variant({ - NoError: IDL.Null - // TODO we are getting some sort of error when all of these are added in. It - // is happening during what looks like a sort of the properties (which might - // explain why one is fine (it doesn't need to be sorted)). The error is - // ReferenceError: 'TextEncoder' is not defined - // SysFatal: IDL.Null, - // SysTransient: IDL.Null, - // DestinationInvalid: IDL.Null - // CanisterReject: IDL.Null, - // CanisterError: IDL.Null, - // Unknown: IDL.Null, + NoError: IDL.Null, + SysFatal: IDL.Null, + SysTransient: IDL.Null, + DestinationInvalid: IDL.Null, + CanisterReject: IDL.Null, + CanisterError: IDL.Null, + Unknown: IDL.Null }); export type RejectionCode = diff --git a/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts index 84128b1e10..7bd62cc221 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts @@ -25,6 +25,10 @@ export default class { fee: bigint, createdAtTime: [bigint] | [] ) { + const created_at_time = + createdAtTime.length === 0 + ? [] + : [{ timestamp_nanos: createdAtTime[0] }]; return await call(getIcpCanisterPrincipal(), 'transfer', { paramIdls: [TransferArgs], returnIdl: TransferResult, @@ -39,7 +43,7 @@ export default class { }, from_subaccount: [], to: binaryAddressFromAddress(to), - created_at_time: createdAtTime + created_at_time } ] }); diff --git a/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts index c8c80b1259..6ad93cc077 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts @@ -214,10 +214,10 @@ export default class { @update([CanisterStatusArgs], CanisterStatusResult) async getCanisterStatus( args: CanisterStatusArgs - ): Promise { + ): Promise { return await call('aaaaa-aa', 'canister_status', { paramIdls: [CanisterStatusArgs], - returnIdl: CanisterInfoResult, + returnIdl: CanisterStatusResult, args: [args] }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts index 29ddee0727..ccc42070b6 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts @@ -10,7 +10,9 @@ import { export default class { @update([], RejectionCode) async getRejectionCodeNoError() { - await call(getSomeCanisterPrincipal(), 'accept'); + await call(getSomeCanisterPrincipal(), 'accept', { + returnIdl: IDL.Bool + }); return rejectCode(); } @@ -30,6 +32,7 @@ export default class { async getRejectionCodeCanisterReject() { try { await call(getSomeCanisterPrincipal(), 'reject', { + paramIdls: [IDL.Text], args: ['reject'] }); } catch (error) { @@ -54,6 +57,7 @@ export default class { async getRejectionMessage(message: string) { try { await call(getSomeCanisterPrincipal(), 'reject', { + paramIdls: [IDL.Text], args: [message] }); } catch (error) { diff --git a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/some_canister/index.ts b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/some_canister/index.ts index e7d3c20094..ed7127e91c 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/some_canister/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/some_canister/index.ts @@ -2,17 +2,17 @@ import { IDL, query, reject } from 'azle'; export default class { @query([IDL.Text], IDL.Empty, { manual: true }) - reject(message: string) { + reject(message: string): void { reject(message); } @query([], IDL.Bool) - accept() { + accept(): boolean { return true; } @query([], IDL.Empty, { manual: true }) - error() { + error(): void { // This errors because neither ic.reject nor ic.reply were called } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json index 1edbfb0b77..ade8d9bd75 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json +++ b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json @@ -1,10 +1,9 @@ { - "name": "vanilla_js_end_to_end_test_functional_syntax", + "name": "vanilla_js", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "vanilla_js_end_to_end_test_functional_syntax", "dependencies": { "azle": "0.22.0", "js-sha256": "0.9.0" @@ -17,6 +16,7 @@ } }, "../../../../../examples/vanilla_js": { + "name": "vanilla_js_end_to_end_test_functional_syntax", "dev": true, "dependencies": { "azle": "0.22.0", @@ -24,6 +24,8 @@ }, "devDependencies": { "@dfinity/agent": "^0.19.2", + "jest": "^29.7.0", + "ts-jest": "^29.1.5", "ts-node": "^10.9.1", "typescript": "^5.2.2" }