Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 17, 2025
1 parent 3a66801 commit e597047
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
dataCertificate,
id,
IDL,
inReplicatedExecution,
isController,
performanceCounter,
Principal,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -61,15 +62,17 @@ export default class {
@preUpgrade
preUpgrade(): void {
this.preUpgradeIsInReplicatedExecution.insert(
'PRE_UPGRADE_VERSION',
'PRE_UPGRADE_IS_IN_REPLICATED_EXECUTION',
inReplicatedExecution()
);
}

@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 [];
Expand Down Expand Up @@ -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;
Expand All @@ -118,7 +123,7 @@ export default class {

@update([], IDL.Bool)
getInspectMessageIsInReplicatedExecution(): boolean {
return true;
return false;
}

@query([], IDL.Bool)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,7 +18,7 @@ export function getTests(): Test {
for (let i = 0; i < 10; i++) {
expect(
await actor.getInspectMessageIsInReplicatedExecution()
).toBe(true);
).toBe(false);
}
});

Expand Down Expand Up @@ -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`);
});

Expand Down Expand Up @@ -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]);
}
}

Expand All @@ -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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::in_replicated_execution;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || in_replicated_execution())
Function::new(ctx, || -> bool { in_replicated_execution() })
}
11 changes: 0 additions & 11 deletions src/lib/experimental/ic/in_replicated_execution.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib/experimental/ic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,7 +51,6 @@ export const ic = {
clearTimer,
dataCertificate,
id,
inReplicatedExecution,
isController,
methodName,
msgCyclesAccept,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/in_replicated_execution.ts
Original file line number Diff line number Diff line change
@@ -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**:
Expand Down

0 comments on commit e597047

Please sign in to comment.