Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor the whole actor and add management canister #804

Merged
merged 10 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
23 changes: 8 additions & 15 deletions e2e/node/utils/canisters/counter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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'));

Expand All @@ -11,30 +11,23 @@ type CounterActor = Actor & {
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