Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions e2e/node/utils/canisters/counter.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import { Actor, blobFromUint8Array } from '@dfinity/agent';
import { httpAgent } from '../agent';
import { Actor, IDL, blobFromUint8Array } from '@dfinity/agent';
import * as path from 'path';
import { readFileSync } from 'fs';
import { httpAgent } from '../agent';

const wasm = readFileSync(path.join(__dirname, 'counter.wasm'));

type CounterActor = Actor & {
read(): Promise<number>;
inc_read(): Promise<number>;
inc(): Promise<void>;
write(n: number): Promise<void>;
};

const factory = httpAgent.makeActorFactory(({ IDL }) =>
const factory: IDL.InterfaceFactory = ({ IDL }) =>
IDL.Service({
read: IDL.Func([], [IDL.Nat], ['query']),
inc_read: IDL.Func([], [IDL.Nat], []),
inc: IDL.Func([], [], []),
write: IDL.Func([IDL.Nat], [], []),
}),
);
});

// TODO(hansl): Add a type to create an Actor interface from a IDL.Service definition.
export async function counterFactory(): Promise<CounterActor> {
let actor = (await factory({ agent: httpAgent })) as CounterActor;
let cid = await actor.__createCanister();
actor.__setCanisterId(cid);

await actor.__install(
return ((await Actor.createAndInstallCanister(
factory,
{
module: blobFromUint8Array(wasm),
},
{
maxAttempts: 600,
throttleDurationInMSecs: 100,
agent: httpAgent,
},
);

return actor;
)) as unknown) as CounterActor;
}
21 changes: 7 additions & 14 deletions e2e/node/utils/canisters/identity.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import { blobFromUint8Array } from '@dfinity/agent';
import { httpAgent, canisterIdFactory } from '../agent';
import { Actor, IDL, blobFromUint8Array } from '@dfinity/agent';
import * as path from 'path';
import { readFileSync } from 'fs';
import { default as idl, Identity } from './identity/main.did';
import { httpAgent } from '../agent';
import { default as factory, Identity } from './identity/main.did';

const wasm = readFileSync(path.join(__dirname, 'identity/main.wasm'));
const factory = httpAgent.makeActorFactory(idl);

// TODO(hansl): Add a type to create an Actor interface from a IDL.Service definition.
export async function identityFactory(): Promise<Identity> {
let actor = (await factory({ agent: httpAgent })) as Identity;
let cid = await actor.__createCanister();
actor.__setCanisterId(cid);

await actor.__install(
return ((await Actor.createAndInstallCanister(
factory as IDL.InterfaceFactory,
{
module: blobFromUint8Array(wasm),
},
{
maxAttempts: 600,
throttleDurationInMSecs: 100,
agent: httpAgent,
},
);

return actor;
)) as unknown) as Identity;
}
10 changes: 6 additions & 4 deletions e2e/node/utils/canisters/identity/main.did.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Actor, IDL } from '@dfinity/agent';

export type Identity = Actor & {
hashFromCall(): IDL.NatClass;
hashFromQuery(): IDL.NatClass;
hashFromCall(): Promise<number>;
hashFromQuery(): Promise<number>;
};

export default ({ IDL }: any) => {
return IDL.Service({'hashFromCall': IDL.Func([], [IDL.Nat], []),
'hashFromQuery': IDL.Func([], [IDL.Nat], ['query'])});
return IDL.Service({
hashFromCall: IDL.Func([], [IDL.Nat], []),
hashFromQuery: IDL.Func([], [IDL.Nat], ['query']),
});
};
Loading