import { CanisterResult, $query, query, ExternalCanister } from 'azle';
class MyService extends ExternalCanister {
@query
method1: () => CanisterResult<string>;
}
$query;
export function test(myService: MyService): MyService {
return myService;
}
It produces this Candid file:
service : () -> {
test : (service { method1 : () -> (text) query }) -> (
service { method1 : () -> (text) query },
) query;
}
I've run dfx generate and I'm trying to do some tests using the agent:
import { Test } from 'azle/test';
import { _SERVICE } from './dfx_generated/service/service.did';
import { ActorSubclass } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] {
return [
{
name: 'test',
test: async () => {
const result = await serviceCanister.test(
Principal.fromText('aaaaa-aa')
);
return {
Ok: result.toString() === 'aaaaa-aa'
};
}
}
];
}
When I run this code I get: Illegal service definition: services can only contain functions. When I run the canister manually from the command line with dfx everything works fine.
You can find more information here: https://forum.dfinity.org/t/illegal-service-definition-services-can-only-contain-functions/17609
I have an Azle canister:
It produces this Candid file:
I've run dfx generate and I'm trying to do some tests using the agent:
When I run this code I get:
Illegal service definition: services can only contain functions
. When I run the canister manually from the command line withdfx
everything works fine.