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

All prop tests use getCanisterActor #2361

Merged
merged 17 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions test/get_canister_actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ import { join } from 'path';

import { getCanisterId } from '../dfx';

/**
* Options for getting a canister actor
* @interface GetCanisterActorOptions
* @property {Identity} [identity] - Optional identity for authentication
* @property {Agent} [agent] - Optional pre-configured agent
* @property {string} [parentDir] - Optional parent directory path for the dfx generated files
*/
type GetCanisterActorOptions = {
identity?: Identity;
agent?: Agent;
parentDir?: string;
};

/**
* Creates an actor instance for interacting with a canister
* @template T - The interface type of the actor
* @param {string} canisterName - Name of the canister to create an actor for
* @param {GetCanisterActorOptions} [options={}] - Configuration options
* @returns {Promise<ActorSubclass<T>>} A promise that resolves to the actor instance
*/
export async function getCanisterActor<T>(
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
canisterName: string,
options: GetCanisterActorOptions = {}
Expand Down
13 changes: 11 additions & 2 deletions test/property/get_actor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Agent } from '@dfinity/agent';
import { ActorSubclass, Agent } from '@dfinity/agent';

import { getCanisterActor } from '../get_canister_actor';

export async function getActor(parentDir: string, agent?: Agent): Promise<any> {
/**
* Creates an actor instance with cache clearing functionality
* @param {string} parentDir - Parent directory path containing the dfx generated files
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
* @param {Agent} [agent] - Optional pre-configured agent
* @returns {Promise<ActorSubclass<T>>} A promise that resolves to the actor instance
*/
export async function getActor<T>(
parentDir: string,
agent?: Agent
): Promise<ActorSubclass<T>> {
const resolvedPathIndex = require.resolve(
`${parentDir}/dfx_generated/canister/index.js`
);
Expand Down
Loading