Skip to content

Commit

Permalink
Merge branch 'main' into missing_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 17, 2025
2 parents 0411b96 + ef77a8d commit 3a66801
Show file tree
Hide file tree
Showing 71 changed files with 103 additions and 455 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
AZLE_VERBOSE=true npx azle install-global-dependencies --rust --wasi2ic
- name: Build stable template
run: AZLE_VERBOSE=true npx azle template
run: npx azle template

- name: Build experimental template
run: AZLE_VERBOSE=true npx azle template --experimental
run: npx azle template --experimental

- uses: ./.github/actions/commit_and_push
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ jobs:
npm install
- name: Build stable template
run: AZLE_VERBOSE=true npx azle template
run: npx azle template

- name: Build experimental template
run: AZLE_VERBOSE=true npx azle template --experimental
run: npx azle template --experimental

- uses: ./.github/actions/commit_and_push
with:
Expand Down
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ export default Canister({
performanceCounter: query([], nat64, () => {
return ic.performanceCounter(0);
}),
// prints a message through the local replica's output
print: query([text], bool, (message) => {
ic.print(message);

return true;
}),
reject: query(
[text],
Manual(empty),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,6 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
);
});

// it('calls argData on the ic object with zero params', async () => {
// const result = await icApiCanister.argDataZeroParams();

// expect(Array.isArray(result)).toBe(true);
// expect(result.length).toBe(0);
// });

// it('calls argData on the ic object with a single param', async () => {
// const result = await icApiCanister.argDataOneParam(true);

// expect(result).toBe(true);
// });

// it('calls argData on the ic object with multiple params', async () => {
// const blobString = 'Surprise!';
// const blob = blobString.split('').map((char) => char.charCodeAt(0));
// const int = 127;
// const bool = true;
// const string = 'test';

// const result = await icApiCanister.argDataMultipleParams(
// blob,
// int,
// bool,
// string
// );

// const expected = {
// blob,
// int,
// boolean: bool,
// string
// };

// expect(result).toStrictEqual(expected);
// });

it('calls argDataRaw on the ic object', async () => {
const blobString = 'Surprise!';
const blob = Uint8Array.from(
Expand Down Expand Up @@ -138,12 +101,6 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
expect(result).toBeGreaterThan(0n);
});

it('calls print on the ic object', async () => {
const result = await icApiCanister.print('Hello World!');

expect(result).toBe(true);
});

it('calls reject on the ic object', async () => {
const rejectionMessage = 'Rejected!';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Canister,
ic,
int,
Null,
query,
Expand Down Expand Up @@ -31,7 +30,7 @@ export default Canister({
return param;
}),
voidIsNotNull: query([], Void, () => {
ic.print(
console.info(
'Even though they are both None in Python, for Candid null and void are different.'
);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
isController,
performanceCounter,
Principal,
print,
query,
reject,
setCertifiedData,
Expand Down Expand Up @@ -138,14 +137,6 @@ export default class {
return performanceCounter(0);
}

// prints a message through the local replica's output
@query([IDL.Text], IDL.Bool)
print(message: string): boolean {
print(message);

return true;
}

@query([IDL.Text], IDL.Empty, { manual: true })
reject(message: string): void {
reject(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDL, print, query, update } from 'azle';
import { IDL, query, update } from 'azle';

const PartiallyNullRecord = IDL.Record({
firstItem: IDL.Int,
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class {

@query
voidIsNotNull(): void {
print(
console.info(
'Even though they are both None in Python, for Candid null and void are different.'
);
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"fast-check": "^3.23.2",
"husky": "9.1.7",
"jest": "^29.7.0",
"lint-staged": "15.3.0",
"lint-staged": "15.4.1",
"prettier": "^3.4.2",
"puppeteer": "^24.1.0",
"semver": "^7.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod canister_version;
mod clear_timer;
mod cycles_burn;
mod data_certificate;
mod debug_print;
mod id;
mod in_replicated_execution;
mod is_controller;
Expand All @@ -19,7 +20,6 @@ mod msg_cycles_available;
mod msg_cycles_refunded;
mod notify_raw;
mod performance_counter;
mod print;
mod reject;
mod reject_code;
mod reject_message;
Expand Down Expand Up @@ -126,6 +126,13 @@ pub fn register(context: &mut wasmedge_quickjs::Context) {
.into(),
);

ic.set(
"debugPrint",
context
.new_function::<debug_print::NativeFunction>("")
.into(),
);

ic.set("id", context.new_function::<id::NativeFunction>("").into());

ic.set(
Expand Down Expand Up @@ -184,11 +191,6 @@ pub fn register(context: &mut wasmedge_quickjs::Context) {
.into(),
);

ic.set(
"print",
context.new_function::<print::NativeFunction>("").into(),
);

ic.set(
"reject",
context.new_function::<reject::NativeFunction>("").into(),
Expand Down
19 changes: 13 additions & 6 deletions src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function build(): Promise<void> {
}

if (command === 'template') {
await handleTemplateCommand(ioType);
await handleTemplateCommand('inherit');

return;
}
Expand Down Expand Up @@ -159,14 +159,21 @@ async function handleCompileCommand(ioType: IOType): Promise<void> {
}

async function handleTemplateCommand(ioType: IOType): Promise<void> {
const experimental =
process.argv.includes('--experimental') ||
process.env.AZLE_EXPERIMENTAL === 'true';
const all = process.argv.includes('--all');

if (experimental === false) {
if (all === true) {
await runStableTemplateCommand(ioType);
} else {
await runExperimentalTemplateCommand(ioType);
} else {
const experimental =
process.argv.includes('--experimental') ||
process.env.AZLE_EXPERIMENTAL === 'true';

if (experimental === false) {
await runStableTemplateCommand(ioType);
} else {
await runExperimentalTemplateCommand(ioType);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::accept_message;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || accept_message())
Function::new(ctx, || -> () { accept_message() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::call::arg_data_raw;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<TypedArray<u8>> {
TypedArray::<u8>::new(ctx.clone(), arg_data_raw())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::caller;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<TypedArray<u8>> {
TypedArray::<u8>::new(ctx.clone(), caller().as_slice())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::canister_balance128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || canister_balance128().to_string())
Function::new(ctx, || -> String { canister_balance128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::canister_version;
use rquickjs::{BigInt, Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx.clone(), move || {
Function::new(ctx.clone(), move || -> Result<BigInt> {
BigInt::from_u64(ctx.clone(), canister_version())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::print;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |message: String| {
Function::new(ctx, |message: String| -> () {
print(message);
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_cdk::api::is_controller;
use rquickjs::{Ctx, Function, Result, TypedArray};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |principal_bytes: TypedArray<u8>| {
Function::new(ctx, |principal_bytes: TypedArray<u8>| -> bool {
let principal = Principal::from_slice(principal_bytes.as_ref());

is_controller(&principal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::method_name;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || method_name())
Function::new(ctx, || -> String { method_name() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod canister_version;
mod clear_timer;
mod cycles_burn;
mod data_certificate;
mod debug_print;
mod id;
mod in_replicated_execution;
mod is_controller;
Expand All @@ -22,7 +23,6 @@ mod msg_cycles_available;
mod msg_cycles_refunded;
mod notify_raw;
mod performance_counter;
mod print;
mod reject;
mod reject_code;
mod reject_message;
Expand Down Expand Up @@ -78,6 +78,8 @@ pub fn register(ctx: Ctx) -> Result<()> {
data_certificate::get_function(ctx.clone()),
)?;

ic.set("debugPrint", debug_print::get_function(ctx.clone()))?;

ic.set("id", id::get_function(ctx.clone()))?;

ic.set(
Expand Down Expand Up @@ -111,8 +113,6 @@ pub fn register(ctx: Ctx) -> Result<()> {
performance_counter::get_function(ctx.clone()),
)?;

ic.set("print", print::get_function(ctx.clone()))?;

ic.set("reject", reject::get_function(ctx.clone()))?;

ic.set("rejectCode", reject_code::get_function(ctx.clone()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::msg_cycles_available128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || msg_cycles_available128().to_string())
Function::new(ctx, || -> String { msg_cycles_available128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::msg_cycles_refunded128;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || msg_cycles_refunded128().to_string())
Function::new(ctx, || -> String { msg_cycles_refunded128().to_string() })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::reject;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, |message: String| reject(&message))
Function::new(ctx, |message: String| -> () { reject(&message) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ic_cdk::api::call::{reject_code, RejectionCode};
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || {
Function::new(ctx, || -> u32 {
let reject_code = reject_code();

match reject_code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use ic_cdk::api::call::reject_message;
use rquickjs::{Ctx, Function, Result};

pub fn get_function(ctx: Ctx) -> Result<Function> {
Function::new(ctx, || reject_message())
Function::new(ctx, || -> String { reject_message() })
}
Loading

0 comments on commit 3a66801

Please sign in to comment.