Skip to content

Commit

Permalink
Merge pull request #1853 from demergent-labs/api_refactor
Browse files Browse the repository at this point in the history
Api refactor
  • Loading branch information
lastmjs authored Jul 9, 2024
2 parents cc160c3 + 3b2a048 commit 0fc8322
Show file tree
Hide file tree
Showing 1,232 changed files with 465,917 additions and 2,298 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
'@typescript-eslint/prefer-for-of': 'error',
'prefer-arrow-callback': 'error',
'no-var': 'error',
'@typescript-eslint/explicit-function-return-type': ['error'],
eqeqeq: 'error',
'@typescript-eslint/no-unused-vars': [
'error',
Expand Down
62 changes: 61 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
# The basic-integration-tests matrix spins up one job per combination of example directory and code source (repo or npm).
# The check-basic-integration-tests-success job is designed to ensure that all jobs spun up from the matrix in the basic-integration-tests have succeeded

# Restore when https://github.com/demergent-labs/azle/issues/1799 is resolved
# TODO Restore when https://github.com/demergent-labs/azle/issues/1799 is resolved
# "examples/run_time_errors",
# TODO are these examples ever going to be added back into here?
# "examples/plugins",
# "examples/primitive_ops",

name: Azle Tests
on:
Expand Down Expand Up @@ -196,13 +199,70 @@ jobs:
"property_tests/tests/tuple",
"property_tests/tests/variant",
"property_tests/tests/vec",
"tests/end_to_end/candid_rpc/class_syntax/async_await",
"tests/end_to_end/candid_rpc/class_syntax/audio_recorder",
"tests/end_to_end/candid_rpc/class_syntax/bitcoin",
"tests/end_to_end/candid_rpc/class_syntax/blob_array",
"tests/end_to_end/candid_rpc/class_syntax/bytes",
"tests/end_to_end/candid_rpc/class_syntax/call_raw",
"tests/end_to_end/candid_rpc/class_syntax/candid_encoding",
"tests/end_to_end/candid_rpc/class_syntax/candid_keywords",
"tests/end_to_end/candid_rpc/class_syntax/canister",
"tests/end_to_end/candid_rpc/class_syntax/ckbtc",
"tests/end_to_end/candid_rpc/class_syntax/complex_init",
"tests/end_to_end/candid_rpc/class_syntax/complex_types",
"tests/end_to_end/candid_rpc/class_syntax/composite_queries",
"tests/end_to_end/candid_rpc/class_syntax/counter",
"tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls",
"tests/end_to_end/candid_rpc/class_syntax/cycles",
"tests/end_to_end/candid_rpc/class_syntax/date",
"tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc",
"tests/end_to_end/candid_rpc/class_syntax/func_types",
"tests/end_to_end/candid_rpc/class_syntax/guard_functions",
"tests/end_to_end/candid_rpc/class_syntax/heartbeat",
"tests/end_to_end/candid_rpc/class_syntax/ic_api",
"tests/end_to_end/candid_rpc/class_syntax/icrc",
"tests/end_to_end/candid_rpc/class_syntax/imports",
"tests/end_to_end/candid_rpc/class_syntax/init",
"tests/end_to_end/candid_rpc/class_syntax/inspect_message",
"tests/end_to_end/candid_rpc/class_syntax/key_value_store",
"tests/end_to_end/candid_rpc/class_syntax/ledger_canister",
"tests/end_to_end/candid_rpc/class_syntax/list_of_lists",
"tests/end_to_end/candid_rpc/class_syntax/management_canister",
"tests/end_to_end/candid_rpc/class_syntax/manual_reply",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/calc",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/counter",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/echo",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/factorial",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/hello",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/hello-world",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/http_counter",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/minimal-counter-dapp",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/persistent-storage",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/phone-book",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/quicksort",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/simple-to-do",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/superheroes",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami",
"tests/end_to_end/candid_rpc/class_syntax/notify_raw",
"tests/end_to_end/candid_rpc/class_syntax/null_example",
"tests/end_to_end/candid_rpc/class_syntax/optional_types",
"tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests",
"tests/end_to_end/candid_rpc/class_syntax/pre_and_post_upgrade",
"tests/end_to_end/candid_rpc/class_syntax/primitive_types",
"tests/end_to_end/candid_rpc/class_syntax/principal",
"tests/end_to_end/candid_rpc/class_syntax/query",
"tests/end_to_end/candid_rpc/class_syntax/randomness",
"tests/end_to_end/candid_rpc/class_syntax/recursion",
"tests/end_to_end/candid_rpc/class_syntax/rejections",
"tests/end_to_end/candid_rpc/class_syntax/simple_erc20",
"tests/end_to_end/candid_rpc/class_syntax/simple_user_accounts",
"tests/end_to_end/candid_rpc/class_syntax/stable_b_tree_map_instruction_threshold",
"tests/end_to_end/candid_rpc/class_syntax/stable_memory",
"tests/end_to_end/candid_rpc/class_syntax/stable_structures",
"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",
]
END
Expand Down
2 changes: 1 addition & 1 deletion benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function write_reports_to_file(
output_file: string,
benchmark_results: BenchmarkResult[],
num_benchmark_iterations: number
) {
): void {
const markdown_report = create_markdown_report(
benchmark_results,
num_benchmark_iterations,
Expand Down
4 changes: 2 additions & 2 deletions benchmark/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ function generate_benchmarks_string(
)}`;
}

function format_number_to_rust(number: string | number | bigint) {
function format_number_to_rust(number: string | number | bigint): string {
const number_is_negative = number.toString()[0] === '-';
const number_is_decimal_less_than_one =
(number_is_negative === false && Number(number) < 1) ||
Expand Down Expand Up @@ -1683,7 +1683,7 @@ function format_number_to_rust(number: string | number | bigint) {
);
}

function format_number_to_usd(number: number) {
function format_number_to_usd(number: number): string {
return number.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';

export async function run_setup(argument?: string) {
export async function run_setup(argument?: string): Promise<void> {
execSync(`dfx canister create azle`, {
stdio: 'inherit'
});
Expand Down
45 changes: 28 additions & 17 deletions canisters/icrc/errors.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import { nat, Record, text } from '../../src/lib';
import { IDL } from '../../src/lib/stable';

export const BadFee = Record({
expected_fee: nat
export const BadFee = IDL.Record({
expected_fee: IDL.Nat
});
export type BadFee = typeof BadFee.tsType;
export type BadFee = {
expected_fee: bigint;
};

export const BadBurn = Record({
min_burn_amount: nat
export const BadBurn = IDL.Record({
min_burn_amount: IDL.Nat
});
export type BadBurn = typeof BadBurn.tsType;
export type BadBurn = {
min_burn_amount: bigint;
};

export const InsufficientFunds = Record({
balance: nat
export const InsufficientFunds = IDL.Record({
balance: IDL.Nat
});
export type InsufficientFunds = typeof InsufficientFunds.tsType;
export type InsufficientFunds = {
balance: bigint;
};

export const Duplicate = Record({
duplicate_of: nat
export const Duplicate = IDL.Record({
duplicate_of: IDL.Nat
});
export type Duplicate = typeof Duplicate.tsType;
export type Duplicate = {
duplicate_of: bigint;
};

export const GenericError = Record({
error_code: nat,
message: text
export const GenericError = IDL.Record({
error_code: IDL.Nat,
message: IDL.Text
});
export type GenericError = typeof GenericError.tsType;
export type GenericError = {
error_code: bigint;
message: string;
};
121 changes: 79 additions & 42 deletions canisters/icrc/icrc_1.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
blob,
int,
nat,
nat64,
Null,
Opt,
Principal,
Record,
text,
Variant
} from '../../src/lib';
import { IDL, Principal } from '../../src/lib/stable';
import {
BadBurn,
BadFee,
Expand All @@ -19,55 +8,103 @@ import {
} from './errors';

// Number of nanoseconds since the UNIX epoch in UTC timezone.
export const Timestamp = nat64;
export type Timestamp = nat64;
export const Timestamp = IDL.Nat64;
export type Timestamp = bigint;

export const Subaccount = blob;
export type Subaccount = blob;
export const Subaccount = IDL.Vec(IDL.Nat8);
export type Subaccount = Uint8Array;

export const Account = Record({
owner: Principal,
subaccount: Opt(Subaccount)
export const Account = IDL.Record({
owner: IDL.Principal,
subaccount: IDL.Opt(Subaccount)
});
export type Account = typeof Account.tsType;
export type Account = {
owner: Principal;
subaccount: [Subaccount] | [];
};

export const TransferArgs = Record({
from_subaccount: Opt(Subaccount),
export const TransferArgs = IDL.Record({
from_subaccount: IDL.Opt(Subaccount),
to: Account,
amount: nat,
fee: Opt(nat),
memo: Opt(blob),
created_at_time: Opt(Timestamp)
amount: IDL.Nat,
fee: IDL.Opt(IDL.Nat),
memo: IDL.Opt(IDL.Vec(IDL.Nat8)),
created_at_time: IDL.Opt(Timestamp)
});
export type TransferArgs = typeof TransferArgs.tsType;
export type TransferArgs = {
from_subaccount: [Subaccount] | [];
to: Account;
amount: bigint;
fee: [bigint] | [];
memo: [Uint8Array] | [];
created_at_time: [Timestamp] | [];
};

export const CreatedInFuture = Record({
export const CreatedInFuture = IDL.Record({
ledger_time: Timestamp
});
export type CreatedInFuture = typeof CreatedInFuture.tsType;
export type CreatedInFuture = {
ledger_time: Timestamp;
};

export const TransferError = Variant({
export const TransferError = IDL.Variant({
BadFee,
BadBurn,
InsufficientFunds,
TooOld: Null,
TooOld: IDL.Null,
CreatedInFuture: CreatedInFuture,
Duplicate: Duplicate,
TemporarilyUnavailable: Null,
TemporarilyUnavailable: IDL.Null,
GenericError: GenericError
});
export type TransferError = typeof TransferError.tsType;
export type TransferError =
| {
BadFee: BadFee;
}
| {
BadBurn: BadBurn;
}
| {
InsufficientFunds: InsufficientFunds;
}
| {
TooOld: null;
}
| {
CreatedInFuture: CreatedInFuture;
}
| {
Duplicate: Duplicate;
}
| {
TemporarilyUnavailable: null;
}
| {
GenericError: GenericError;
};

export const TransferResult = Variant({
Ok: nat,
export const TransferResult = IDL.Variant({
Ok: IDL.Nat,
Err: TransferError
});
export type TransferResult = typeof TransferResult.tsType;
export type TransferResult = { Ok: bigint } | { Err: TransferError };

export const Value = Variant({
Nat: nat,
Int: int,
Text: text,
Blob: blob
export const Value = IDL.Variant({
Nat: IDL.Nat,
Int: IDL.Int,
Text: IDL.Text,
Blob: IDL.Vec(IDL.Nat8)
});
export type Value = typeof Value.tsType;
export type Value =
| {
Nat: bigint;
}
| {
Int: bigint;
}
| {
Text: string;
}
| {
Blob: Uint8Array;
};
Loading

0 comments on commit 0fc8322

Please sign in to comment.