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

feat: upgrade to server v6 #64

Merged
merged 1 commit into from
Oct 7, 2024
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
2 changes: 1 addition & 1 deletion packages/pic/postinstall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const __dirname = dirname(__filename);

const IS_LINUX = process.platform === 'linux';
const PLATFORM = IS_LINUX ? 'x86_64-linux' : 'x86_64-darwin';
const VERSION = '5.0.0';
const VERSION = '6.0.0';
const DOWNLOAD_PATH = `https://github.com/dfinity/pocketic/releases/download/${VERSION}/pocket-ic-${PLATFORM}.gz`;

const TARGET_PATH = resolve(__dirname, 'pocket-ic');
Expand Down
9 changes: 9 additions & 0 deletions packages/pic/src/pocket-ic-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CreateInstanceRequest {
bitcoin?: BitcoinSubnetConfig;
system?: SystemSubnetConfig[];
application?: ApplicationSubnetConfig[];
verifiedApplication?: VerifiedApplicationSubnetConfig[];
processingTimeoutMs?: number;
nonmainnetFeatures?: boolean;
}
Expand Down Expand Up @@ -58,6 +59,10 @@ export type ApplicationSubnetConfig =
SubnetConfig<ApplicationSubnetStateConfig>;
export type ApplicationSubnetStateConfig = NewSubnetStateConfig;

export type VerifiedApplicationSubnetConfig =
SubnetConfig<VerifiedApplicationSubnetStateConfig>;
export type VerifiedApplicationSubnetStateConfig = NewSubnetStateConfig;

export interface NewSubnetStateConfig {
type: SubnetStateType.New;
}
Expand Down Expand Up @@ -86,6 +91,7 @@ export interface EncodedCreateInstanceSubnetConfig {
bitcoin?: EncodedSubnetConfig;
system: EncodedSubnetConfig[];
application: EncodedSubnetConfig[];
verified_application: EncodedSubnetConfig[];
}

export interface EncodedSubnetConfig {
Expand Down Expand Up @@ -174,6 +180,9 @@ export function encodeCreateInstanceRequest(
application: encodeManySubnetConfigs(
defaultOptions.application ?? [defaultApplicationSubnet],
),
verified_application: encodeManySubnetConfigs(
defaultOptions.verifiedApplication,
),
},
nonmainnet_features: defaultOptions.nonmainnetFeatures ?? false,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/pic/src/pocket-ic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
decodeCanisterCallResponse,
} from './pocket-ic-client-types';

const PROCESSING_TIME_VALUE_MS = 10_000;
const PROCESSING_TIME_VALUE_MS = 30_000;

export class PocketIcClient {
private isInstanceDeleted = false;
Expand Down
16 changes: 6 additions & 10 deletions packages/pic/src/pocket-ic-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class PocketIcServer {
const pid = process.ppid;
const picFilePrefix = `pocket_ic_${pid}`;
const portFilePath = tmpFile(`${picFilePrefix}.port`);
const readyFilePath = tmpFile(`${picFilePrefix}.ready`);

const serverProcess = spawn(binPath, ['--pid', pid.toString()]);

Expand All @@ -95,16 +94,13 @@ export class PocketIcServer {

return await poll(
async () => {
const isPocketIcReady = await exists(readyFilePath);

if (isPocketIcReady) {
const portString = await readFileAsString(portFilePath);
const port = parseInt(portString);

return new PocketIcServer(serverProcess, port);
const portString = await readFileAsString(portFilePath);
const port = parseInt(portString);
if (isNaN(port)) {
throw new BinTimeoutError();
}

throw new BinTimeoutError();
return new PocketIcServer(serverProcess, port);
},
{ intervalMs: POLL_INTERVAL_MS, timeoutMs: POLL_TIMEOUT_MS },
);
Expand Down Expand Up @@ -154,7 +150,7 @@ export class PocketIcServer {
}

const POLL_INTERVAL_MS = 20;
const POLL_TIMEOUT_MS = 5_000;
const POLL_TIMEOUT_MS = 30_000;

class NullStream extends Writable {
_write(
Expand Down
18 changes: 18 additions & 0 deletions packages/pic/src/pocket-ic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export interface CreateInstanceOptions {
*/
application?: ApplicationSubnetConfig[];

/**
* Configuration options for creating verified application subnets.
* A verified application subnet will be created for each configuration object provided.
* If no config objects are provided, no verified application subnets are setup.
*/
verifiedApplication?: VerifiedApplicationSubnetConfig[];

/**
* How long the PocketIC client should wait for a response from the server.
*/
Expand Down Expand Up @@ -163,6 +170,17 @@ export type ApplicationSubnetConfig =
*/
export type ApplicationSubnetStateConfig = NewSubnetStateConfig;

/**
* Options for creating a verified application subnet.
*/
export type VerifiedApplicationSubnetConfig =
SubnetConfig<VerifiedApplicationSubnetStateConfig>;

/**
* Options for a verified application subnet's state.
*/
export type VerifiedApplicationSubnetStateConfig = NewSubnetStateConfig;

/**
* Options for creating a new subnet an empty state.
*/
Expand Down