Skip to content

Commit

Permalink
feat: upgrade to pic server v4
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed May 5, 2024
1 parent 5af7e64 commit d96b4bf
Show file tree
Hide file tree
Showing 13 changed files with 618 additions and 308 deletions.
6 changes: 6 additions & 0 deletions docs/docs/guides/05-running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ For example:
POCKET_IC_LOG_DIR=./logs POCKET_IC_LOG_DIR_LEVELS=trace npm test
```

It's also possible to set individual log levels for different modules, for examples:

```shell
POCKET_IC_LOG_DIR=./logs POCKET_IC_LOG_DIR_LEVELS=pocket_ic_server=trace,tower_http=info,axum::rejection=info npm test
```

### Runtime logs

Logs for the IC runtime can be configured when running the PocketIC server using the `showRuntimeLogs` option, for example:
Expand Down
7 changes: 5 additions & 2 deletions docs/docs/guides/06-working-with-the-nns.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ Now you can setup your PocketIC instance to use the NNS state:
```ts
const pic = await PocketIc.create({
nns: {
fromPath: NNS_STATE_PATH,
subnetId: Principal.fromText(NNS_SUBNET_ID),
state: {
type: SubnetStateType.FromPath,
path: NNS_STATE_PATH,
subnetId: Principal.fromText(NNS_SUBNET_ID),
},
},
});
```
Expand Down
9 changes: 7 additions & 2 deletions examples/multicanister/tests/src/multicanister.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import { Actor, PocketIc } from '@hadronous/pic';
import { Actor, PocketIc, SubnetStateType } from '@hadronous/pic';
import { IDL } from '@dfinity/candid';

import {
Expand Down Expand Up @@ -54,7 +54,12 @@ describe('Multicanister', () => {
let actor: Actor<_SERVICE>;

beforeEach(async () => {
pic = await PocketIc.create(process.env.PIC_URL, { application: 2 });
pic = await PocketIc.create(process.env.PIC_URL, {
application: [
{ state: { type: SubnetStateType.New } },
{ state: { type: SubnetStateType.New } },
],
});

const applicationSubnets = pic.getApplicationSubnets();
const mainSubnet = applicationSubnets[0];
Expand Down
14 changes: 11 additions & 3 deletions examples/nns_proxy/tests/src/nns-proxy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { resolve } from 'path';
import { Principal } from '@dfinity/principal';
import { Actor, PocketIc, generateRandomIdentity } from '@hadronous/pic';
import {
Actor,
PocketIc,
SubnetStateType,
generateRandomIdentity,
} from '@hadronous/pic';
import { _SERVICE, idlFactory } from '../../declarations/nns_proxy.did';
import { Governance } from './support/governance';

Expand Down Expand Up @@ -40,8 +45,11 @@ describe('NNS Proxy', () => {
beforeEach(async () => {
pic = await PocketIc.create(process.env.PIC_URL, {
nns: {
fromPath: NNS_STATE_PATH,
subnetId: Principal.fromText(NNS_SUBNET_ID),
state: {
type: SubnetStateType.FromPath,
path: NNS_STATE_PATH,
subnetId: Principal.fromText(NNS_SUBNET_ID),
},
},
});
await pic.setTime(new Date(2024, 1, 30).getTime());
Expand Down
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 = '3.0.1';
const VERSION = '4.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
6 changes: 6 additions & 0 deletions packages/pic/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export class BinTimeoutError extends Error {
}
}

export class ServerRequestTimeoutError extends Error {
constructor() {
super('A request to the PocketIC server timed out.');
}
}

export class InstanceDeletedError extends Error {
constructor() {
super(
Expand Down
Loading

0 comments on commit d96b4bf

Please sign in to comment.