Skip to content

Commit

Permalink
Merge pull request #1309 from demergent-labs/rec_fix_example
Browse files Browse the repository at this point in the history
Fix Recursive
  • Loading branch information
lastmjs authored Sep 30, 2023
2 parents c1b8167 + ff9653c commit b4cdbcb
Show file tree
Hide file tree
Showing 85 changed files with 2,123 additions and 3,106 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
# 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

# All Examples TODO restore when https://github.com/demergent-labs/azle/issues/1192 is resolved
# "examples/complex_types",
# "examples/func_types",
# "examples/generics",
# "examples/motoko_examples/superheroes", # blocked by recursive
# "examples/run_time_errors",
# "examples/tuple_types",

name: Azle Tests
on:
Expand Down Expand Up @@ -74,12 +70,14 @@ jobs:
"examples/candid_encoding",
"examples/canister",
"examples/complex_init",
"examples/complex_types",
"examples/composite_queries",
"examples/counter",
"examples/cross_canister_calls",
"examples/cycles",
"examples/date",
"examples/ethereum_json_rpc",
"examples/func_types",
"examples/guard_functions",
"examples/heartbeat",
"examples/ic_api",
Expand All @@ -104,6 +102,7 @@ jobs:
"examples/motoko_examples/phone-book",
"examples/motoko_examples/quicksort",
"examples/motoko_examples/simple-to-do",
"examples/motoko_examples/superheroes",
"examples/motoko_examples/threshold_ecdsa",
"examples/motoko_examples/whoami",
"examples/notify_raw",
Expand All @@ -115,13 +114,15 @@ jobs:
"examples/principal",
"examples/query",
"examples/randomness",
"examples/recursion",
"examples/rejections",
"examples/robust_imports",
"examples/simple_erc20",
"examples/simple_user_accounts",
"examples/stable_memory",
"examples/stable_structures",
"examples/timers",
"examples/tuple_types",
"examples/update"
]
END
Expand Down
5 changes: 1 addition & 4 deletions examples/bitcoin/src/index.did
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
type rec_14 = record {txid:vec nat8; vout:nat32};
type rec_13 = record {height:nat32; value:nat64; outpoint:rec_14};
type rec_12 = record {next_page:opt vec nat8; tip_height:nat32; tip_block_hash:vec nat8; utxos:vec rec_13};
service: () -> {
getBalance: (text) -> (nat64);
getCurrentFeePercentiles: () -> (vec nat64);
getUtxos: (text) -> (rec_12);
getUtxos: (text) -> (record {next_page:opt vec nat8; tip_height:nat32; tip_block_hash:vec nat8; utxos:vec record {height:nat32; value:nat64; outpoint:record {txid:vec nat8; vout:nat32}}});
sendTransaction: (vec nat8) -> (bool);
}
11 changes: 5 additions & 6 deletions examples/canister/src/index.did
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
type rec_0 = record {someCanister:service {query1:() -> (bool) query; update1:() -> (text) }};
service: () -> {
canisterParam: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query;
canisterReturnType: () -> (service {query1:() -> (bool) query; update1:() -> (text) }) query;
canisterNestedReturnType: () -> (rec_0);
canisterList: (vec service {query1:() -> (bool) query; update1:() -> (text) }) -> (vec service {query1:() -> (bool) query; update1:() -> (text) });
canisterCrossCanisterCall: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (text);
canisterCrossCanisterCall: (service {query1: () -> (bool) query; update1: () -> (text);}) -> (text);
canisterList: (vec service {query1: () -> (bool) query; update1: () -> (text);}) -> (vec service {query1: () -> (bool) query; update1: () -> (text);});
canisterNestedReturnType: () -> (record {someCanister:service {query1: () -> (bool) query; update1: () -> (text);}});
canisterParam: (service {query1: () -> (bool) query; update1: () -> (text);}) -> (service {query1: () -> (bool) query; update1: () -> (text);}) query;
canisterReturnType: () -> (service {query1: () -> (bool) query; update1: () -> (text);}) query;
}
16 changes: 14 additions & 2 deletions examples/complex_init/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@
"canisters": {
"complex_init": {
"type": "custom",
"main": "src/index.ts",
"main": "src/complex_init/index.ts",
"build": "npx azle complex_init",
"candid": "src/index.did",
"candid": "src/complex_init/index.did",
"wasm": ".azle/complex_init/complex_init.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/complex_init",
"node_compatibility": true
}
},
"rec_init": {
"type": "custom",
"main": "src/rec_init/index.ts",
"build": "npx azle rec_init",
"candid": "src/rec_init/index.did",
"wasm": ".azle/rec_init/rec_init.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/rec_init",
"node_compatibility": true
}
}
}
}
3 changes: 3 additions & 0 deletions examples/complex_init/src/complex_init/index.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service: (record {text; record {id:text}}) -> {
greetUser: () -> (text) query;
}
File renamed without changes.
4 changes: 0 additions & 4 deletions examples/complex_init/src/index.did

This file was deleted.

4 changes: 4 additions & 0 deletions examples/complex_init/src/rec_init/index.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type rec_14 = variant {Leaf; Branch:rec_14};
service: (rec_14) -> {
countBranches: () -> (nat) query;
}
27 changes: 27 additions & 0 deletions examples/complex_init/src/rec_init/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Canister, init, Null, query, Recursive, Variant, nat } from 'azle';

const Node = Recursive(() =>
Variant({
Leaf: Null,
Branch: Node
})
);

let tree: typeof Node = { Leaf: null };

export default Canister({
init: init([Node], (node) => {
tree = node;
return undefined;
}),
countBranches: query([], nat, () => {
return countBranches(tree);
})
});

function countBranches(node: typeof Node): nat {
if (node.Leaf !== undefined) {
return 1n;
}
return countBranches(node.Branch);
}
15 changes: 15 additions & 0 deletions examples/complex_init/test/pretest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ async function pretest() {
stdio: 'inherit'
});

execSync(`dfx canister uninstall-code rec_init || true`, {
stdio: 'inherit'
});

execSync(
`dfx deploy complex_init --argument 'record {"Oh hello there user"; record { id = "1" }}'`,
{
stdio: 'inherit'
}
);

execSync(
`dfx deploy rec_init --argument 'variant {Branch = variant {Leaf}}'`,
{
stdio: 'inherit'
}
);

execSync(`dfx generate complex_init`, {
stdio: 'inherit'
});

execSync(`dfx generate rec_init`, {
stdio: 'inherit'
});
}

pretest();
18 changes: 14 additions & 4 deletions examples/complex_init/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { getCanisterId, runTests } from 'azle/test';
import { createActor } from '../test/dfx_generated/complex_init';
import { get_tests } from './tests';
import { createActor as createComplexActor } from '../test/dfx_generated/complex_init';
import { createActor as createRecActor } from '../test/dfx_generated/rec_init';
import { get_rec_tests, get_tests } from './tests';

const complexInitCanister = createActor(getCanisterId('complex_init'), {
const complexInitCanister = createComplexActor(getCanisterId('complex_init'), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

runTests(get_tests(complexInitCanister));
const recInitCanister = createRecActor(getCanisterId('rec_init'), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

runTests([
...get_tests(complexInitCanister),
...get_rec_tests(recInitCanister)
]);
22 changes: 20 additions & 2 deletions examples/complex_init/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { _SERVICE } from './dfx_generated/complex_init/complex_init.did';
import { _SERVICE as _COMPLEX_SERVICE } from './dfx_generated/complex_init/complex_init.did';
import { _SERVICE as _REC_SERVICE } from './dfx_generated/rec_init/rec_init.did';

export function get_tests(
complex_init_canister: ActorSubclass<_SERVICE>
complex_init_canister: ActorSubclass<_COMPLEX_SERVICE>
): Test[] {
return [
{
Expand All @@ -18,3 +19,20 @@ export function get_tests(
}
];
}

export function get_rec_tests(
rec_init_canister: ActorSubclass<_REC_SERVICE>
): Test[] {
return [
{
name: 'count branches',
test: async () => {
const result = await rec_init_canister.countBranches();

return {
Ok: result === 1n
};
}
}
];
}
3 changes: 2 additions & 1 deletion examples/complex_types/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.ts",
"build": "npx azle complex_types",
"candid": "src/index.did",
"wasm": ".azle/complex_types/complex_types.wasm.gz",
"wasm": ".azle/complex_types/complex_types.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/complex_types",
"node_compatibility": true
Expand Down
41 changes: 41 additions & 0 deletions examples/complex_types/src/candid_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Record, Null, text, Variant, Vec, Recursive } from 'azle';

export const ReactionType = Variant({
Fire: Null,
ThumbsUp: Null,
ThumbsDown: Null
});

export const User = Recursive(() =>
Record({
id: text,
posts: Vec(Post),
reactions: Vec(Reaction),
threads: Vec(Thread),
username: text
})
);

export const Post = Recursive(() =>
Record({
id: text,
author: User,
reactions: Vec(Reaction),
text: text,
thread: Thread
})
);

export const Thread = Record({
id: text,
author: User,
posts: Vec(Post),
title: text
});

export const Reaction = Record({
id: text,
author: User,
post: Post,
reactionType: ReactionType
});
21 changes: 0 additions & 21 deletions examples/complex_types/src/candid_types/post.ts

This file was deleted.

18 changes: 0 additions & 18 deletions examples/complex_types/src/candid_types/reaction.ts

This file was deleted.

12 changes: 0 additions & 12 deletions examples/complex_types/src/candid_types/reaction_type.ts

This file was deleted.

17 changes: 0 additions & 17 deletions examples/complex_types/src/candid_types/thread.ts

This file was deleted.

21 changes: 0 additions & 21 deletions examples/complex_types/src/candid_types/user.ts

This file was deleted.

Loading

0 comments on commit b4cdbcb

Please sign in to comment.