🧪 Announcing PicJS: TypeScript/JavaScript support for PocketIC!

The best source that I know of is the changelog.

A while back I heard some chatter about maybe adding the version to the state tree, but IDK if that resulted in something. It’s not in the spec AFAICT

1 Like

is there a way to check what version of the replica is being used by PocketIC?

You can query the status endpoint /instances/0/api/v2/status at runtime and read out the impl_version field of the returned cbor payload. Alternatively, for the PocketIC server included in dfx, the replica version of PocketIC can be read out from the nix/sources.json file (e.g., here for v0.20.2).

1 Like

I am getting an error when trying to test the method that performs https_outcall
PocketIC server is too busy to process the request
@NathanosDev

Can you try with the latest beta version and see if that helps?

npm i -D @hadronous/pic@beta

PocketIC server encountered an error BadIngressMessage(“Failed to answer to ingress 0x54e41af253fc7c0304cf06b06e532757d39e436551ec8c7d0209be7d40c7de2d after 100 rounds.”)

@mraszyk do you know why this might happen? This is using PocketIC server v4.

Canister https outcalls are not yet supported in PocketIC (they’ll be supported in the upcoming release in a few weeks) which is why you see the error.

2 Likes

Not sure what my issue is now, but I can’t seem to get pocket-ic to ‘create’ properly:

The subnet that was spit out after running the SNS scenario was: 6hddd-nszlm-yb7u4-wqfxt-btk2p-w2jgp-emsaz-ree4f-cmeth-y3gko-gae

I figured out that the config structure changed a bit, and now I have:

pic = await PocketIc.create(process.env.PIC_URL,{
      nns: {
        state: {
          type: SubnetStateType.FromPath,
      
          path: NNS_STATE_PATH,
          subnetId: Principal.fromText(NNS_SUBNET_ID),
        },
      },
    });

But now I get a bunch of message in my log

thread ‘tokio-runtime-worker’ panicked at rs/pocket_ic_server/src/state_api/routes.rs:959:10:
Failed to launch PocketIC: JoinError::Panic(Id(21), …)
thread ‘tokio-runtime-worker’ panicked at rs/pocket_ic_server/src/pocket_ic.rs:125:60:

I notice that a bunch of other options are now available on the object, so maybe I’ll play with those a bit? Since I constructed this with dfx I’m guessing everything is on the same subnet…maybe that is going to be a problem?

Ps. I’m running pic.js beta with a state produced with dfx 20.1

I did change to

pic = await PocketIc.create(process.env.PIC_URL,{
      nns: {
        state: {
          type: SubnetStateType.FromPath,
          path: NNS_STATE_PATH,
          subnetId: Principal.fromText(NNS_SUBNET_ID),
        },
      },
      sns: {
        state: {
          type: SubnetStateType.New,
        },
      },
    });

…and the errors went away, but now I get a
TypeError: fetch failed

  at async makeRequest (node_modules/@hadronous/pic/src/http2-client.ts:59:19)
  at async intervalMs (node_modules/@hadronous/pic/src/http2-client.ts:130:21)
  at async Timeout.runPoll [as _onTimeout] (node_modules/@hadronous/pic/src/util/poll.ts:17:24)

Cause:
connect ECONNREFUSED 127.0.0.1:53189

Now I’m getting something. I think my debugs breaks were causing the server to stop:

Jul 10 19:35:48.586 WARN s:/n:/ic_state_manager/ic_state_manager No state available with certification.
Jul 10 19:35:48.590 WARN s:/n:/ic_messaging/message_routing mr_non_increasing_batch_time: Non-increasing batch time at height 6801: state_time = 2024-07-10 17:55:32.046328 UTC, batch_time = 2021-05-06 19:17:10.000000001 UTC.
thread ‘tokio-runtime-worker’ panicked at rs/state_machine_tests/src/lib.rs:1573:17:
Critical error mr_non_increasing_batch_time occurred.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

But after this it kind of dies.

looks like it is getting to pic.tick() call but that is failing with:

Error: A request to the PocketIC server timed out.
at eval (eval-b3e01baf.repl:1:1)
at
at EventTarget. (/Users/afat/Dropbox/development/origyn/gitlab/snsgovapp/node_modules/@hadronous/pic/src/http2-client.ts:51:11)
at EventTarget.[nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
at EventTarget.dispatchEvent (node:internal/event_target:761:26)
at abortSignal (node:internal/abort_controller:371:10)
at AbortController.abort (node:internal/abort_controller:393:5)
at makeRequest (/Users/afat/Dropbox/development/origyn/gitlab/snsgovapp/node_modules/@hadronous/pic/src/http2-client.ts:65:30)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async intervalMs (/Users/afat/Dropbox/development/origyn/gitlab/snsgovapp/node_modules/@hadronous/pic/src/http2-client.ts:130:21)
at async runPoll (/Users/afat/Dropbox/development/origyn/gitlab/snsgovapp/node_modules/@hadronous/pic/src/util/poll.ts:17:24) {stack: ‘Error: A request to the PocketIC server timed…odules/@hadronous/pic/src/util/poll.ts:17:24)’, message: ‘A request to the PocketIC server timed out.’}

calling

{method: ‘POST’, path: ‘/instances/0/update/tick’, headers: {…}, body: undefined}
body:
undefined
headers:
{Content-Type: ‘application/json’}
Content-Type:
‘application/json’
[[Prototype]]:
Object
method:
‘POST’
path:
‘/instances/0/update/tick’

Sometimes I get:
tokio-runtime-worker’ panicked at rs/state_machine_tests/src/lib.rs:1573:17:
Critical error mr_non_increasing_batch_time occurred.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
2024-07-10T19:47:40.803557Z INFO pocket_ic_server: The PocketIC server will terminate

in my output.

What version exactly? If you want I can quickly try to update the version in Juno and see if my tests are still running.

I’m using v0.8.1 and quickly tested v0.9.0-b0 but in both case, my test suite was ok. I fear I cannot really help.

I’m stupid. I had commented out my set time function. I added it back in and set the time to just after I had created the state(that was showing up in my error) and now it works.

Bttfm Back GIF

2 Likes

This actually didn’t work. :frowning:

The first time I call list_neuons on my sns_governance canister I get this message repeated over and over in my console until things timeout:

console.error
PocketIC server encountered an error BadIngressMessage(“Canister not found”)

  at intervalMs (node_modules/@hadronous/pic/src/http2-client.ts:144:19)
  at async Timeout.runPoll [as _onTimeout] (node_modules/@hadronous/pic/src/util/poll.ts:17:24)

I’ve confirmed it is trying to make the ingress call for list neurons by putting break points in the pic client.


I’ve called list neurons on the same canister on my dfx state successfully, so I don’t know what is going on unless there is something internal that maps that br5f7-7uaaa-aaaaa-qaaca-cai canister id to a theoretical SNS subnet. My SNS canisters are all on the NNS subnet because I have to give the whole state to the nns when I fire it up:

pic = await PocketIc.create(process.env.PIC_URL,{
      processingTimeoutMs: 30000,
      nns: {
        state: {
          type: SubnetStateType.FromPath,
          path: NNS_STATE_PATH,
          subnetId: Principal.fromText(NNS_SUBNET_ID),
          
        },
      },
      
    });


    const snsGovActor = await pic.createActor<SNSGovenranceService>(
      snsgovIdlFactory,
      Principal.fromText(snsgovCanisterId),
    );

    const neurons = await snsGovActor.list_neurons({
      limit: 5,
      start_page_at:[],
      of_principal: []
    });

When I call getCanisterSubnet for the target canister I also get null.

The getSNSSubnet is also null, which I expect, but makes me suspicious if the range is hardcoded.

Can you outline what steps you followed to produce the replica state that you’re importing into PocketIC?

You’re sailing in unchartered territory now :laughing:

  1. Ran the setup_locally and run_basic_scenario from the apple silicone instructions from GitHub - dfinity/sns-testing: Testing SNS in local testing environment(I think I did something to force dfx 0.20.1.

  2. It produced this state with a SNS aggregator that put out the listed json:

I exported it and used the import command listed there for your beta if pic.js