diff --git a/e2e/node/basic/basic.test.ts b/e2e/node/basic/basic.test.ts index 0f48adae1..4b21ed6ab 100644 --- a/e2e/node/basic/basic.test.ts +++ b/e2e/node/basic/basic.test.ts @@ -1,7 +1,7 @@ /** * @jest-environment node */ -import { Certificate, getManagementCanister } from '@dfinity/agent'; +import { ActorMethod, Certificate, getManagementCanister } from '@dfinity/agent'; import { IDL } from '@dfinity/candid'; import { Principal } from '@dfinity/principal'; import agent from '../utils/agent'; @@ -37,23 +37,24 @@ test('createCanister', async () => { // Make sure this doesn't fail. await getManagementCanister({ agent: await agent, - }).provisional_create_canister_with_cycles({ amount: [1e12], settings: [] }); + }).provisional_create_canister_with_cycles({ amount: [BigInt(1e12)], settings: [] }); }); test('withOptions', async () => { // Make sure this fails. await expect( (async () => { - await getManagementCanister({ + const canisterActor = await getManagementCanister({ agent: await agent, - }).provisional_create_canister_with_cycles.withOptions({ + }); + await (canisterActor.provisional_create_canister_with_cycles as ActorMethod).withOptions({ canisterId: 'abcde-gghhi', - })({ amount: [1e12], settings: [] }); + })({ amount: [BigInt(1e12)], settings: [] }); })(), ).rejects.toThrow(); // Make sure this doesn't fail. await getManagementCanister({ agent: await agent, - }).provisional_create_canister_with_cycles({ amount: [1e12], settings: [] }); + }).provisional_create_canister_with_cycles({ amount: [BigInt(1e12)], settings: [] }); }); diff --git a/packages/agent/src/canisters/management.ts b/packages/agent/src/canisters/management.ts index 7d12975b5..9124e1950 100644 --- a/packages/agent/src/canisters/management.ts +++ b/packages/agent/src/canisters/management.ts @@ -1,45 +1,16 @@ -import { Actor, ActorMethod, ActorSubclass, CallConfig } from '../actor'; +import { Actor, ActorSubclass, CallConfig } from '../actor'; import { Principal } from '@dfinity/principal'; import managementCanisterIdl from './management_idl'; +import _SERVICE from './management_service'; -export interface CanisterSettings { - controller: [] | [Principal]; - compute_allocation: [] | [bigint]; - memory_allocation: [] | [bigint]; - freezing_threshold: [] | [bigint]; -} - -/* tslint:disable */ -export interface ManagementCanisterRecord { - provisional_create_canister_with_cycles: ActorMethod< - [ - { - amount: [] | [number]; - settings: [] | [CanisterSettings]; - }, - ], - { canister_id: Principal } - >; - install_code: ActorMethod< - [ - { - mode: { install: null } | { reinstall: null } | { upgrade: null }; - canister_id: Principal; - wasm_module: number[]; - arg: number[]; - }, - ], - void - >; -} -/* tslint:enable */ +export type ManagementCanisterRecord = _SERVICE; /** - * Create a management canister actor. + * Create a management canister actor * @param config */ export function getManagementCanister(config: CallConfig): ActorSubclass { - function transform(methodName: string, args: unknown[], callConfig: CallConfig) { + function transform(_methodName: string, args: unknown[], _callConfig: CallConfig) { const first = args[0] as any; let effectiveCanisterId = Principal.fromHex(''); if (first && typeof first === 'object' && first.canister_id) { diff --git a/packages/agent/src/canisters/management_idl.ts b/packages/agent/src/canisters/management_idl.ts index f83fd58b1..5780608cd 100644 --- a/packages/agent/src/canisters/management_idl.ts +++ b/packages/agent/src/canisters/management_idl.ts @@ -5,32 +5,86 @@ // @ts-ignore export default ({ IDL }) => { const canister_id = IDL.Principal; - const wasm_module = IDL.Vec(IDL.Nat8); - const CanisterSettings = IDL.Record({ - compute_allocation: IDL.Opt(IDL.Nat), + const definite_canister_settings = IDL.Record({ + controllers: IDL.Vec(IDL.Principal), + freezing_threshold: IDL.Nat, + memory_allocation: IDL.Nat, + compute_allocation: IDL.Nat, + }); + const canister_settings = IDL.Record({ + controllers: IDL.Opt(IDL.Vec(IDL.Principal)), + freezing_threshold: IDL.Opt(IDL.Nat), memory_allocation: IDL.Opt(IDL.Nat), + compute_allocation: IDL.Opt(IDL.Nat), }); + const wasm_module = IDL.Vec(IDL.Nat8); return IDL.Service({ - provisional_create_canister_with_cycles: IDL.Func( - [IDL.Record({ amount: IDL.Opt(IDL.Nat), settings: IDL.Opt(CanisterSettings) })], + canister_status: IDL.Func( + [IDL.Record({ canister_id: canister_id })], + [ + IDL.Record({ + status: IDL.Variant({ + stopped: IDL.Null, + stopping: IDL.Null, + running: IDL.Null, + }), + memory_size: IDL.Nat, + cycles: IDL.Nat, + settings: definite_canister_settings, + module_hash: IDL.Opt(IDL.Vec(IDL.Nat8)), + }), + ], + [], + ), + create_canister: IDL.Func( + [IDL.Record({ settings: IDL.Opt(canister_settings) })], [IDL.Record({ canister_id: canister_id })], [], ), - create_canister: IDL.Func([], [IDL.Record({ canister_id: canister_id })], []), + delete_canister: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), + deposit_cycles: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), install_code: IDL.Func( [ IDL.Record({ - mode: IDL.Variant({ install: IDL.Null, reinstall: IDL.Null, upgrade: IDL.Null }), - canister_id: canister_id, - wasm_module: wasm_module, arg: IDL.Vec(IDL.Nat8), + wasm_module: wasm_module, + mode: IDL.Variant({ + reinstall: IDL.Null, + upgrade: IDL.Null, + install: IDL.Null, + }), + canister_id: canister_id, + }), + ], + [], + [], + ), + provisional_create_canister_with_cycles: IDL.Func( + [ + IDL.Record({ + settings: IDL.Opt(canister_settings), + amount: IDL.Opt(IDL.Nat), }), ], + [IDL.Record({ canister_id: canister_id })], + [], + ), + provisional_top_up_canister: IDL.Func( + [IDL.Record({ canister_id: canister_id, amount: IDL.Nat })], [], [], ), - set_controller: IDL.Func( - [IDL.Record({ canister_id: canister_id, new_controller: IDL.Principal })], + raw_rand: IDL.Func([], [IDL.Vec(IDL.Nat8)], []), + start_canister: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), + stop_canister: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), + uninstall_code: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), + update_settings: IDL.Func( + [ + IDL.Record({ + canister_id: IDL.Principal, + settings: canister_settings, + }), + ], [], [], ), diff --git a/packages/agent/src/canisters/management_service.ts b/packages/agent/src/canisters/management_service.ts new file mode 100644 index 000000000..1c295dff3 --- /dev/null +++ b/packages/agent/src/canisters/management_service.ts @@ -0,0 +1,57 @@ +/** + * This file is generated from the candid for asset management. + */ +/* tslint:disable */ +// @ts-ignore +import type { Principal } from '@dfinity/principal'; +export type canister_id = Principal; +export interface canister_settings { + controllers: [] | [Array]; + freezing_threshold: [] | [bigint]; + memory_allocation: [] | [bigint]; + compute_allocation: [] | [bigint]; +} +export interface definite_canister_settings { + controllers: Array; + freezing_threshold: bigint; + memory_allocation: bigint; + compute_allocation: bigint; +} +export type user_id = Principal; +export type wasm_module = Array; +export default interface _SERVICE { + canister_status: (arg_0: { canister_id: canister_id }) => Promise<{ + status: { stopped: null } | { stopping: null } | { running: null }; + memory_size: bigint; + cycles: bigint; + settings: definite_canister_settings; + module_hash: [] | [Array]; + }>; + create_canister: (arg_0: { + settings: [] | [canister_settings]; + }) => Promise<{ canister_id: canister_id }>; + delete_canister: (arg_0: { canister_id: canister_id }) => Promise; + deposit_cycles: (arg_0: { canister_id: canister_id }) => Promise; + install_code: (arg_0: { + arg: Array; + wasm_module: wasm_module; + mode: { reinstall: null } | { upgrade: null } | { install: null }; + canister_id: canister_id; + }) => Promise; + provisional_create_canister_with_cycles: (arg_0: { + settings: [] | [canister_settings]; + amount: [] | [bigint]; + }) => Promise<{ canister_id: canister_id }>; + provisional_top_up_canister: (arg_0: { + canister_id: canister_id; + amount: bigint; + }) => Promise; + raw_rand: () => Promise>; + start_canister: (arg_0: { canister_id: canister_id }) => Promise; + stop_canister: (arg_0: { canister_id: canister_id }) => Promise; + uninstall_code: (arg_0: { canister_id: canister_id }) => Promise; + update_settings: (arg_0: { + canister_id: Principal; + settings: canister_settings; + }) => Promise; +}