Skip to content

Commit

Permalink
finish conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jul 1, 2024
1 parent 7384419 commit 062173d
Show file tree
Hide file tree
Showing 29 changed files with 40,698 additions and 9,721 deletions.
3 changes: 2 additions & 1 deletion examples/complex_init/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ActorSubclass } from '@dfinity/agent';
import { expect, it, Test } from 'azle/test';

// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE as _COMPLEX_SERVICE } from './dfx_generated/complex_init/complex_init.did';
// @ts-ignore
// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE as _REC_SERVICE } from './dfx_generated/rec_init/rec_init.did';

export function getTests(
Expand Down
2 changes: 2 additions & 0 deletions examples/cycles/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ActorSubclass } from '@dfinity/agent';
import { expect, it, Test } from 'azle/test';

// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE as CYCLESCANISTERSERVICE } from './dfx_generated/cycles/cycles.did';
// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE as INTERMEDIARYCANISTERSERVICE } from './dfx_generated/intermediary/intermediary.did';

export function getTests(
Expand Down
12 changes: 6 additions & 6 deletions examples/date/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ export default Canister({

return date.getUTCSeconds();
}),
toDateString: query([text], text, (isoString) => {
dateToDateString: query([text], text, (isoString) => {
return new Date(isoString).toDateString();
}),
toISOString: query([text], text, (isoString) => {
dateToISOString: query([text], text, (isoString) => {
return new Date(isoString).toISOString();
}),
toJSONString: query([text], text, (isoString) => {
dateToJSONString: query([text], text, (isoString) => {
return new Date(isoString).toJSON();
}),
toString: query([text], text, (isoString) => {
dateToString: query([text], text, (isoString) => {
return new Date(isoString).toString();
}),
toTimeString: query([text], text, (isoString) => {
dateToTimeString: query([text], text, (isoString) => {
return new Date(isoString).toTimeString();
}),
toUtcString: query([text], text, (isoString) => {
dateToUtcString: query([text], text, (isoString) => {
return new Date(isoString).toUTCString();
}),
now: query([], nat64, () => {
Expand Down
22 changes: 16 additions & 6 deletions examples/date/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toDateString on a canister', async () => {
const date = new Date();

const result = await dateCanister.toDateString(date.toISOString());
const result = await dateCanister.dateToDateString(
date.toISOString()
);
type Options = {
timeZone: 'UTC';
weekday: 'short';
Expand All @@ -453,7 +455,9 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toIsoString on a canister', async () => {
const date = new Date();

const result = await dateCanister.toISOString(date.toISOString());
const result = await dateCanister.dateToISOString(
date.toISOString()
);
const expected = date.toISOString();

expect(result).toBe(expected);
Expand All @@ -462,7 +466,9 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toJson on a canister', async () => {
const date = new Date();

const result = await dateCanister.toJSONString(date.toISOString());
const result = await dateCanister.dateToJSONString(
date.toISOString()
);
const expected = date.toJSON();

expect(result).toBe(expected);
Expand All @@ -471,7 +477,7 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toString on a canister', async () => {
const date = new Date();

const result = await dateCanister.toString(date.toISOString());
const result = await dateCanister.dateToString(date.toISOString());
const resultSubstring = result.substring(0, result.indexOf(' GMT'));

const expected = new Date(
Expand All @@ -489,7 +495,9 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toTimeString on a canister', async () => {
const date = new Date();

const result = await dateCanister.toTimeString(date.toISOString());
const result = await dateCanister.dateToTimeString(
date.toISOString()
);
const resultSubstring = result.substring(0, result.indexOf(' GMT'));

const expected = new Date(
Expand All @@ -507,7 +515,9 @@ export function getTests(dateCanister: ActorSubclass<_SERVICE>): Test {
it('executes toUtcString on a canister', async () => {
const date = new Date();

const result = await dateCanister.toUtcString(date.toISOString());
const result = await dateCanister.dateToUtcString(
date.toISOString()
);
const expected = date.toUTCString();

expect(result).toBe(expected);
Expand Down
1 change: 1 addition & 0 deletions examples/list_of_lists/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActorSubclass } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { expect, it, Test } from 'azle/test';

// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE } from '../dfx_generated/list_of_lists/list_of_lists.did';

export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ export default class {
receiveCycles() {
return msgCyclesAccept(msgCyclesAvailable() / 2n);
}

// Moves all transferred cycles to the canister
@update([], IDL.Nat)
receiveCycles128() {
return msgCyclesAccept128(msgCyclesAvailable128() / 2n);
}

@query([], IDL.Nat64)
getCanisterBalance() {
return canisterBalance();
}

@query([], IDL.Nat)
getCanisterBalance128() {
return canisterBalance128();
Expand Down
12 changes: 6 additions & 6 deletions tests/end_to_end/candid_rpc/class_syntax/date/src/index.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
service: () -> {
dateToDateString: (text) -> (text) query;
dateToISOString: (text) -> (text) query;
dateToJSONString: (text) -> (text) query;
dateToString: (text) -> (text) query;
dateToTimeString: (text) -> (text) query;
dateToUtcString: (text) -> (text) query;
getDate: (text) -> (nat32) query;
getDay: (text) -> (nat32) query;
getFullYear: (text) -> (nat32) query;
Expand Down Expand Up @@ -34,11 +40,5 @@ service: () -> {
setUtcMinutes: (text, nat32) -> (nat32) query;
setUtcMonth: (text, nat32) -> (nat32) query;
setUtcSeconds: (text, nat32) -> (nat32) query;
toDateString: (text) -> (text) query;
toISOString: (text) -> (text) query;
toJSONString: (text) -> (text) query;
toString: (text) -> (text) query;
toTimeString: (text) -> (text) query;
toUtcString: (text) -> (text) query;
utc: (nat32, nat32) -> (nat64) query;
}
12 changes: 6 additions & 6 deletions tests/end_to_end/candid_rpc/class_syntax/date/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,32 +227,32 @@ export default class {
}

@query([IDL.Text], IDL.Text)
toDateString(isoString: string): string {
dateToDateString(isoString: string): string {
return new Date(isoString).toDateString();
}

@query([IDL.Text], IDL.Text)
toISOString(isoString: string): string {
dateToISOString(isoString: string): string {
return new Date(isoString).toISOString();
}

@query([IDL.Text], IDL.Text)
toJSONString(isoString: string): string {
dateToJSONString(isoString: string): string {
return new Date(isoString).toJSON();
}

@query([IDL.Text], IDL.Text)
toString(isoString: string): string {
dateToString(isoString: string): string {
return new Date(isoString).toString();
}

@query([IDL.Text], IDL.Text)
toTimeString(isoString: string): string {
dateToTimeString(isoString: string): string {
return new Date(isoString).toTimeString();
}

@query([IDL.Text], IDL.Text)
toUtcString(isoString: string): string {
dateToUtcString(isoString: string): string {
return new Date(isoString).toUTCString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execSync } from 'child_process';
import { join } from 'path';

async function pretest() {
linkAndInstallPatch(join('examples', 'func_types'));
linkAndInstallPatch(join('examples', 'guard_functions'));

execSync(`dfx canister uninstall-code guard_functions || true`, {
stdio: 'inherit'
Expand Down
4 changes: 4 additions & 0 deletions tests/end_to_end/candid_rpc/class_syntax/icrc/test/pretest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { linkAndInstallPatch } from 'azle/test/jest_link';
import { execSync } from 'child_process';
import { join } from 'path';

async function pretest(icrcPath: string) {
linkAndInstallPatch(join('examples', 'icrc'));

execSync(`dfx canister uninstall-code proxy || true`, {
stdio: 'inherit'
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getCanisterId } from 'azle/dfx';
import { linkAndInstallPatch } from 'azle/test/jest_link';
import { execSync } from 'child_process';
import { join } from 'path';

async function pretest(icp_ledger_path: string) {
linkAndInstallPatch(join('examples', 'ledger_canister'));

execSync(`dfx canister uninstall-code icp_ledger || true`, {
stdio: 'inherit'
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit 062173d

Please sign in to comment.