diff --git a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/call_raw.rs b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/call_raw.rs index 2942bc460c..a307b21664 100644 --- a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/call_raw.rs +++ b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/call_raw.rs @@ -18,7 +18,7 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult { canister_id_bytes: TypedArray, method: String, args_raw: TypedArray, - payment_string: String| + cycles_string: String| -> QuickJsResult<()> { let canister_id = Principal::from_slice(canister_id_bytes.as_ref()); let args_raw = args_raw @@ -28,7 +28,7 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult { "args_raw could not be converted into bytes", ))? .to_vec(); - let payment: u128 = payment_string + let payment: u128 = cycles_string .parse() .map_err(|e| throw_error(ctx.clone(), e))?; diff --git a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/notify_raw.rs b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/notify_raw.rs index 65eb210867..e9b8297b0d 100644 --- a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/notify_raw.rs +++ b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/notify_raw.rs @@ -10,7 +10,7 @@ pub fn get_function(ctx: Ctx) -> Result { move |canister_id_bytes: TypedArray, method: String, args_raw: TypedArray, - payment_string: String| + cycles_string: String| -> Result { let canister_id = Principal::from_slice(canister_id_bytes.as_ref()); let args_raw = args_raw @@ -20,7 +20,7 @@ pub fn get_function(ctx: Ctx) -> Result { "args_raw could not be converted into bytes", ))? .to_vec(); - let payment: u128 = payment_string + let payment: u128 = cycles_string .parse() .map_err(|e| throw_error(ctx.clone(), e))?; diff --git a/src/lib/stable/ic_apis/azle_ic_stable.ts b/src/lib/stable/ic_apis/azle_ic_stable.ts index fde62fc137..351127e1e6 100644 --- a/src/lib/stable/ic_apis/azle_ic_stable.ts +++ b/src/lib/stable/ic_apis/azle_ic_stable.ts @@ -9,7 +9,7 @@ export type AzleIcStable = { canisterIdBytes: Uint8Array, method: string, argsRaw: Uint8Array, - paymentString: string + cyclesString: string ) => void; caller: () => Uint8Array; candidCompiler: (candidPath: string) => string; @@ -30,7 +30,7 @@ export type AzleIcStable = { canisterIdBytes: Uint8Array, method: string, argsRawBuffer: Uint8Array, - paymentString: string + cyclesString: string ) => void; performanceCounter: (counterType: number) => bigint; rejectCode: () => number; diff --git a/src/lib/stable/ic_apis/call.ts b/src/lib/stable/ic_apis/call.ts index 8b6e67ca02..448763fccf 100644 --- a/src/lib/stable/ic_apis/call.ts +++ b/src/lib/stable/ic_apis/call.ts @@ -11,7 +11,7 @@ export async function call( paramIdlTypes?: IDL.Type[]; returnIdlType?: IDL.Type; args?: Args; - payment?: bigint; // TODO this should be called cycles: https://github.com/demergent-labs/azle/issues/2104 + cycles?: bigint; raw?: Uint8Array; } ): Promise { @@ -58,7 +58,7 @@ export async function call( const paramIdlTypes = options?.paramIdlTypes ?? []; const args = options?.args ?? []; - const payment = options?.payment ?? 0n; + const cycles = options?.cycles ?? 0n; const canisterIdPrincipal = typeof canisterId === 'string' @@ -67,7 +67,7 @@ export async function call( const canisterIdBytes = canisterIdPrincipal.toUint8Array(); const argsRaw = raw === undefined ? idlEncode(paramIdlTypes, args) : raw; - const paymentString = payment.toString(); + const cyclesString = cycles.toString(); // TODO consider finally, what if deletion goes wrong try { @@ -77,7 +77,7 @@ export async function call( canisterIdBytes.buffer, method, argsRaw.buffer, - paymentString + cyclesString ); } else { globalThis._azleIcStable.callRaw( @@ -85,7 +85,7 @@ export async function call( canisterIdBytes, method, argsRaw, - paymentString + cyclesString ); } } catch (error) { diff --git a/src/lib/stable/ic_apis/chunk.ts b/src/lib/stable/ic_apis/chunk.ts index c6edff6b37..0a3ec314c6 100644 --- a/src/lib/stable/ic_apis/chunk.ts +++ b/src/lib/stable/ic_apis/chunk.ts @@ -21,5 +21,5 @@ export async function chunk(): Promise { return undefined; } - await call(id(), '_azle_chunk', { raw: candidEncode('()'), payment: 0n }); + await call(id(), '_azle_chunk', { raw: candidEncode('()'), cycles: 0n }); } diff --git a/src/lib/stable/ic_apis/notify.ts b/src/lib/stable/ic_apis/notify.ts index 6aee565f59..de4d8f49d6 100644 --- a/src/lib/stable/ic_apis/notify.ts +++ b/src/lib/stable/ic_apis/notify.ts @@ -16,7 +16,7 @@ export function notify( options?: { paramIdlTypes?: IDL.Type[]; args?: any[]; - payment?: bigint; + cycles?: bigint; raw?: Uint8Array; } ): void { @@ -29,7 +29,7 @@ export function notify( const paramIdlTypes = options?.paramIdlTypes ?? []; const args = options?.args ?? []; - const payment = options?.payment ?? 0n; + const cycles = options?.cycles ?? 0n; const raw = options?.raw; const canisterIdPrincipal = @@ -38,14 +38,14 @@ export function notify( : canisterId; const canisterIdBytes = canisterIdPrincipal.toUint8Array(); const argsRaw = raw === undefined ? idlEncode(paramIdlTypes, args) : raw; - const paymentString = payment.toString(); + const cyclesString = cycles.toString(); if (globalThis._azleIcExperimental !== undefined) { return globalThis._azleIcExperimental.notifyRaw( canisterIdBytes.buffer, method, argsRaw.buffer, - paymentString + cyclesString ); } @@ -53,6 +53,6 @@ export function notify( canisterIdBytes, method, argsRaw, - paymentString + cyclesString ); } diff --git a/test/index.ts b/test/index.ts index 790a39779f..80c5a50021 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,7 +1,7 @@ import * as dns from 'node:dns'; dns.setDefaultResultOrder('ipv4first'); -import { ActorSubclass } from '@dfinity/agent'; +import { ActorSubclass, HttpAgent } from '@dfinity/agent'; import { describe, expect, test } from '@jest/globals'; import { join } from 'path'; @@ -116,10 +116,15 @@ export async function getCanisterActor( const { createActor } = await import( join(process.cwd(), 'test', 'dfx_generated', canisterName) ); + + const agent = new HttpAgent({ + host: 'http://127.0.0.1:8000' + }); + + await agent.fetchRootKey(); + const actor = createActor(getCanisterId(canisterName), { - agentOptions: { - host: 'http://127.0.0.1:8000' - } + agent }); return actor; diff --git a/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts index eb4c454d5d..2cf6af273b 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts @@ -29,7 +29,7 @@ export default class { network: { regtest: null } } ], - payment: BITCOIN_API_CYCLE_COST + cycles: BITCOIN_API_CYCLE_COST }); } @@ -46,7 +46,7 @@ export default class { network: { regtest: null } } ], - payment: BITCOIN_API_CYCLE_COST + cycles: BITCOIN_API_CYCLE_COST }); } @@ -65,7 +65,7 @@ export default class { network: { regtest: null } } ], - payment: BITCOIN_API_CYCLE_COST + cycles: BITCOIN_API_CYCLE_COST } ); } @@ -88,7 +88,7 @@ export default class { network: { regtest: null } } ], - payment: transactionFee + cycles: transactionFee } ); diff --git a/tests/end_to_end/candid_rpc/class_syntax/call_raw/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/call_raw/src/index.ts index 275055b661..f8f7fd2075 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/call_raw/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/call_raw/src/index.ts @@ -6,11 +6,11 @@ export default class { canisterId: Principal, method: string, candidArgs: string, - payment: bigint + cycles: bigint ): Promise { const result = await call(canisterId, method, { raw: candidEncode(candidArgs), - payment + cycles }); return candidDecode(result); diff --git a/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts b/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts index 5e23d2d172..4938c44660 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts @@ -49,7 +49,7 @@ export default class { return notify(this.canister2Id, 'receiveNotification', { paramIdlTypes: [IDL.Text], args: ['This is the notification'], - payment: 10n + cycles: 10n }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts b/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts index 0baa7e8ef9..67fc93f090 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts @@ -6,14 +6,14 @@ export default class { async sendCycles(): Promise { return await call(getCyclesPrincipal(), 'receiveCycles', { returnIdlType: IDL.Nat64, - payment: 1_000_000n + cycles: 1_000_000n }); } @update([]) sendCyclesNotify(): void { return notify(getCyclesPrincipal(), 'receiveCycles', { - payment: 1_000_000n + cycles: 1_000_000n }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts index e0e1cdddfa..dd5f967349 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts @@ -94,7 +94,7 @@ async function getBalance( ] } ], - payment: 50_000_000n + cycles: 50_000_000n } ); @@ -136,7 +136,7 @@ async function getBlockByNumber(url: string, number: number): Promise { ] } ], - payment: 50_000_000n + cycles: 50_000_000n } ); 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 6d0ebb38cb..1b0528938f 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 @@ -148,7 +148,7 @@ export default class { sender_canister_version: [] } ], - payment: 100_000_000_000n + cycles: 100_000_000_000n }); return true; @@ -178,7 +178,7 @@ export default class { sender_canister_version: [] } ], - payment: 100_000_000_000n + cycles: 100_000_000_000n } ); @@ -285,7 +285,7 @@ export default class { canister_id: canisterId } ], - payment: 10_000_000n + cycles: 10_000_000n }); return true; @@ -355,7 +355,7 @@ async function createCanister(): Promise { paramIdlTypes: [create_canister_args], returnIdlType: create_canister_result, args: [{ settings: [], sender_canister_version: [] }], - payment: 50_000_000_000_000n + cycles: 50_000_000_000_000n } ); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts index a7a69f142a..ed05d9f769 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts @@ -84,7 +84,7 @@ async function getSignatureResult( } } ], - payment: 10_000_000_000n + cycles: 10_000_000_000n } ); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/notify_raw/src/canister1/index.ts b/tests/end_to_end/candid_rpc/class_syntax/notify_raw/src/canister1/index.ts index 67e691e430..f5e005b420 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/notify_raw/src/canister1/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/notify_raw/src/canister1/index.ts @@ -11,7 +11,7 @@ export default class { 'receiveNotification', { raw: Uint8Array.from(candidEncode('()')), - payment: 0n + cycles: 0n } ); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts index a0fe0c44f6..e6cfa0a74f 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts @@ -43,7 +43,7 @@ export default class { ] } ], - payment: 50_000_000n + cycles: 50_000_000n }); return new TextDecoder().decode(Uint8Array.from(httpResponse.body)); @@ -67,7 +67,7 @@ export default class { } ) `), - payment: 50_000_000n + cycles: 50_000_000n } ); diff --git a/tests/end_to_end/candid_rpc/functional_syntax/stable_b_tree_map_instruction_threshold/test/tests.ts b/tests/end_to_end/candid_rpc/functional_syntax/stable_b_tree_map_instruction_threshold/test/tests.ts index f7c9414186..48c01634f2 100644 --- a/tests/end_to_end/candid_rpc/functional_syntax/stable_b_tree_map_instruction_threshold/test/tests.ts +++ b/tests/end_to_end/candid_rpc/functional_syntax/stable_b_tree_map_instruction_threshold/test/tests.ts @@ -15,7 +15,7 @@ export function getTests( const keysResult = await stableBTreeMapInstructionThresholdCanister.keysSmallRecord( - 3_800 + 3_500 ); const valuesResult = @@ -28,7 +28,7 @@ export function getTests( 1_000 ); - expect(keysResult).toHaveLength(3_800); + expect(keysResult).toHaveLength(3_500); expect(valuesResult).toHaveLength(4_000); expect(itemsResult).toHaveLength(1_000); }, 100_000); diff --git a/tests/property/ic_api/cycles_burn/test/tests.ts b/tests/property/ic_api/cycles_burn/test/tests.ts index 0d0909559e..6ec8919441 100644 --- a/tests/property/ic_api/cycles_burn/test/tests.ts +++ b/tests/property/ic_api/cycles_burn/test/tests.ts @@ -1,9 +1,14 @@ -import { getCanisterId } from 'azle/dfx'; import { execSyncPretty } from 'azle/src/build/stable/utils/exec_sync_pretty'; -import { defaultPropTestParams, expect, it, Test } from 'azle/test'; +import { + defaultPropTestParams, + expect, + getCanisterActor, + it, + Test +} from 'azle/test'; import fc from 'fast-check'; -import { createActor } from './dfx_generated/canister'; +import { _SERVICE as Actor } from './dfx_generated/canister/canister.did'; export function getTests(): Test { return () => { @@ -19,11 +24,7 @@ export function getTests(): Test { 'inherit' ); - const actor = createActor(getCanisterId('canister'), { - agentOptions: { - host: 'http://127.0.0.1:8000' - } - }); + const actor = await getCanisterActor('canister'); const cycleBalanceBefore = await actor.getCycleBalance();