diff --git a/examples/experimental/test/end_to_end/candid_rpc/ic_api/src/index.ts b/examples/experimental/test/end_to_end/candid_rpc/ic_api/src/index.ts index aa78867fe9..4c3ce97a89 100644 --- a/examples/experimental/test/end_to_end/candid_rpc/ic_api/src/index.ts +++ b/examples/experimental/test/end_to_end/candid_rpc/ic_api/src/index.ts @@ -86,10 +86,6 @@ export default Canister({ id: query([], Principal, () => { return ic.id(); }), - // returns true if the canister is in replicated execution - inReplicatedExecution: update([], bool, () => { - return ic.inReplicatedExecution(); - }), // determines whether the given principal is a controller of the canister isController: query([Principal], bool, (principal) => { return ic.isController(principal); diff --git a/examples/experimental/test/end_to_end/candid_rpc/ic_api/test/tests.ts b/examples/experimental/test/end_to_end/candid_rpc/ic_api/test/tests.ts index 6db4d2987c..1302f3f3d6 100644 --- a/examples/experimental/test/end_to_end/candid_rpc/ic_api/test/tests.ts +++ b/examples/experimental/test/end_to_end/candid_rpc/ic_api/test/tests.ts @@ -79,12 +79,6 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test { expect(result.toText()).toBe(icApiCanisterId); }); - it('calls inReplicatedExecution on the ic object', async () => { - const result = await icApiCanister.inReplicatedExecution(); - - expect(result).toBe(true); - }); - it('calls isController on the ic object', async () => { const principal = Principal.fromText( execSync(`dfx identity get-principal`).toString().trim() 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 f24e0ca410..a6b2135dc5 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 @@ -6,7 +6,6 @@ import { dataCertificate, id, IDL, - inReplicatedExecution, isController, performanceCounter, Principal, @@ -121,11 +120,6 @@ export default class { return id(); } - @update([], IDL.Bool) - inReplicatedExecution(): boolean { - return inReplicatedExecution(); - } - // determines whether the given principal is a controller of the canister @query([IDL.Principal], IDL.Bool) isController(principal: Principal): boolean { diff --git a/examples/stable/test/property/ic_api/in_replicated_execution/src/index.ts b/examples/stable/test/property/ic_api/in_replicated_execution/src/index.ts index 36fcc42927..eb9dc1e8ef 100644 --- a/examples/stable/test/property/ic_api/in_replicated_execution/src/index.ts +++ b/examples/stable/test/property/ic_api/in_replicated_execution/src/index.ts @@ -21,11 +21,12 @@ export default class { initIsInReplicatedExecution: boolean | null = null; postUpgradeIsInReplicatedExecution: boolean | null = null; preUpgradeIsInReplicatedExecution = new StableBTreeMap< - 'PRE_UPGRADE_VERSION', + 'PRE_UPGRADE_IS_IN_REPLICATED_EXECUTION', boolean >(0); timerIsInReplicatedExecution: boolean | null = null; heartbeatIsInReplicatedExecution: boolean | null = null; + sneakyInspect: number | null = null; @init init(): void { @@ -61,7 +62,7 @@ export default class { @preUpgrade preUpgrade(): void { this.preUpgradeIsInReplicatedExecution.insert( - 'PRE_UPGRADE_VERSION', + 'PRE_UPGRADE_IS_IN_REPLICATED_EXECUTION', inReplicatedExecution() ); } @@ -69,7 +70,9 @@ export default class { @query([], IDL.Opt(IDL.Bool)) getPreUpgradeIsInReplicatedExecution(): [boolean] | [] { const preUpgradeIsInReplicatedExecution = - this.preUpgradeIsInReplicatedExecution.get('PRE_UPGRADE_VERSION'); + this.preUpgradeIsInReplicatedExecution.get( + 'PRE_UPGRADE_IS_IN_REPLICATED_EXECUTION' + ); if (preUpgradeIsInReplicatedExecution === null) { return []; @@ -103,11 +106,13 @@ export default class { @inspectMessage inspectMessage(): void { - if ( - methodName() === - 'getInspectMessageIsInReplicatedExecutionWhenInspectingUpdates' - ) { + if (methodName() === 'getInspectMessageIsInReplicatedExecution') { + console.log('inspecting getInspectMessageIsInReplicatedExecution'); + console.log( + `inReplicatedExecution() === ${inReplicatedExecution()}` + ); if (inReplicatedExecution() === true) { + // TODO for https://github.com/demergent-labs/azle/issues/2539 acceptMessage(); } return; @@ -118,7 +123,7 @@ export default class { @update([], IDL.Bool) getInspectMessageIsInReplicatedExecution(): boolean { - return true; + return false; } @query([], IDL.Bool) diff --git a/examples/stable/test/property/ic_api/in_replicated_execution/test/pretest.ts b/examples/stable/test/property/ic_api/in_replicated_execution/test/pretest.ts index b611469790..468655084d 100644 --- a/examples/stable/test/property/ic_api/in_replicated_execution/test/pretest.ts +++ b/examples/stable/test/property/ic_api/in_replicated_execution/test/pretest.ts @@ -1,11 +1,7 @@ import { execSync } from 'child_process'; function pretest(): void { - execSync(`dfx canister stop canister || true`, { - stdio: 'inherit' - }); - - execSync(`dfx canister delete canister || true`, { + execSync(`dfx canister uninstall-code canister || true`, { stdio: 'inherit' }); diff --git a/examples/stable/test/property/ic_api/in_replicated_execution/test/tests.ts b/examples/stable/test/property/ic_api/in_replicated_execution/test/tests.ts index b1280da8ea..e2c11c9196 100644 --- a/examples/stable/test/property/ic_api/in_replicated_execution/test/tests.ts +++ b/examples/stable/test/property/ic_api/in_replicated_execution/test/tests.ts @@ -1,4 +1,4 @@ -import { expect, getCanisterActor, it, Test } from 'azle/test'; +import { expect, getCanisterActor, it, please, Test } from 'azle/test'; import { execSync } from 'child_process'; import { _SERVICE as Actor } from './dfx_generated/canister/canister.did'; @@ -18,7 +18,7 @@ export function getTests(): Test { for (let i = 0; i < 10; i++) { expect( await actor.getInspectMessageIsInReplicatedExecution() - ).toBe(true); + ).toBe(false); } }); @@ -70,7 +70,7 @@ export function getTests(): Test { ).toStrictEqual([true]); }); - it('redeploys the canister', async () => { + please('redeploys the canister', async () => { execSync(`dfx deploy canister --upgrade-unchanged`); }); @@ -104,9 +104,9 @@ async function checkInitIsInReplicatedExecution( await actor.getInitIsInReplicatedExecution(); if (isInitialDeployment === false) { - expect(initIsInReplicatedExecution).toHaveLength(0); + expect(initIsInReplicatedExecution).toStrictEqual([]); } else { - expect(initIsInReplicatedExecution[0]).toBe(true); + expect(initIsInReplicatedExecution).toStrictEqual([true]); } } @@ -117,18 +117,18 @@ async function checkUpgradeIsInReplicatedExecution( if (isInitialDeployment === true) { const postUpgradeCanisterVersion = await actor.getPostUpgradeIsInReplicatedExecution(); - expect(postUpgradeCanisterVersion).toHaveLength(0); + expect(postUpgradeCanisterVersion).toStrictEqual([]); const preUpgradeCanisterVersion = await actor.getPreUpgradeIsInReplicatedExecution(); - expect(preUpgradeCanisterVersion).toHaveLength(0); + expect(preUpgradeCanisterVersion).toStrictEqual([]); } else { const postUpgradeCanisterVersionAfterUpgrade = await actor.getPostUpgradeIsInReplicatedExecution(); - expect(postUpgradeCanisterVersionAfterUpgrade[0]).toBe(true); + expect(postUpgradeCanisterVersionAfterUpgrade).toStrictEqual([true]); const preUpgradeCanisterVersionAfterUpgrade = await actor.getPreUpgradeIsInReplicatedExecution(); - expect(preUpgradeCanisterVersionAfterUpgrade[0]).toBe(true); + expect(preUpgradeCanisterVersionAfterUpgrade).toStrictEqual([true]); } } diff --git a/src/build/stable/commands/compile/candid_and_method_meta/execute.ts b/src/build/stable/commands/compile/candid_and_method_meta/execute.ts index 8de8c71fa2..d593384f8e 100644 --- a/src/build/stable/commands/compile/candid_and_method_meta/execute.ts +++ b/src/build/stable/commands/compile/candid_and_method_meta/execute.ts @@ -34,8 +34,8 @@ export async function execute( console.info(message); }, global_timer_set: (): void => {}, - instruction_counter: (): void => {}, in_replicated_execution: (): void => {}, + instruction_counter: (): void => {}, is_controller: (): void => {}, msg_arg_data_copy: (): void => {}, msg_arg_data_size: (): void => {}, diff --git a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/in_replicated_execution.rs b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/in_replicated_execution.rs index fd581345c7..9ddf51e0ac 100644 --- a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/in_replicated_execution.rs +++ b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/in_replicated_execution.rs @@ -2,5 +2,5 @@ use ic_cdk::api::in_replicated_execution; use rquickjs::{Ctx, Function, Result}; pub fn get_function(ctx: Ctx) -> Result { - Function::new(ctx, || in_replicated_execution()) + Function::new(ctx, || -> bool { in_replicated_execution() }) } diff --git a/src/lib/experimental/ic/in_replicated_execution.ts b/src/lib/experimental/ic/in_replicated_execution.ts deleted file mode 100644 index f52cc0a406..0000000000 --- a/src/lib/experimental/ic/in_replicated_execution.ts +++ /dev/null @@ -1,11 +0,0 @@ -import '../experimental'; - -import { bool } from '../candid/types/primitive/bool'; - -export function inReplicatedExecution(): bool { - if (globalThis._azleIcExperimental === undefined) { - return false; - } - - return globalThis._azleIcExperimental.inReplicatedExecution(); -} diff --git a/src/lib/experimental/ic/index.ts b/src/lib/experimental/ic/index.ts index 3a03eff10c..53a8f63588 100644 --- a/src/lib/experimental/ic/index.ts +++ b/src/lib/experimental/ic/index.ts @@ -14,7 +14,6 @@ import { chunk } from './chunk'; import { clearTimer } from './clear_timer'; import { dataCertificate } from './data_certificate'; import { id } from './id'; -import { inReplicatedExecution } from './in_replicated_execution'; import { isController } from './is_controller'; import { methodName } from './method_name'; import { msgCyclesAccept } from './msg_cycles_accept'; @@ -52,7 +51,6 @@ export const ic = { clearTimer, dataCertificate, id, - inReplicatedExecution, isController, methodName, msgCyclesAccept, diff --git a/src/lib/stable/ic_apis/in_replicated_execution.ts b/src/lib/stable/ic_apis/in_replicated_execution.ts index 102b27066d..c3755e1e36 100644 --- a/src/lib/stable/ic_apis/in_replicated_execution.ts +++ b/src/lib/stable/ic_apis/in_replicated_execution.ts @@ -1,7 +1,7 @@ /** - * Checks if in replicated execution. + * Checks if the current call is in replicated or non-replicated execution mode. * - * @returns true if in replicated execution, false otherwise + * @returns true if in replicated execution mode, false otherwise * * @remarks * - **Call Context**: