hadronous / pic-js

An Internet Computer Protocol canister testing library for TypeScript and JavaScript.
https://hadronous.github.io/pic-js/
Apache License 2.0
11 stars 6 forks source link

Actor interface upgradeCanister #47

Open peterpeterparker opened 6 months ago

peterpeterparker commented 6 months ago

Feature request

It would be nice to be able to provide an ActorInterface to the upgradeCanister function, similar to setupCanister, and receive an updated actor as a result.

This can notably be useful if the candid declaration changes between version and one want to test an upgrade.

Currently, this can be solved by creating a new actor once the upgrade has been processed. Such a feature would spare few lines of code.

From:

await pic.upgradeCanister({
  canisterId,
  wasm: SATELLITE_WASM_PATH,
  sender: controller.getPrincipal()
});

const newActor = pic.createActor<SatelliteActorNEW>(idlFactorSatellite, canisterId);
newActor.setIdentity(controller);

To:

const {actor: newActor} = await pic.upgradeCanister<SatelliteActorNEW>({
  canisterId,
  wasm: SATELLITE_WASM_PATH,
  sender: controller.getPrincipal()
});
nathanosdev commented 6 months ago

This looks like it would be a nice ergonomic improvement.

With creating canisters this is separated into two methods:

I think a similar separation here would be good. I'll need to think about how to name these methods better. In any case I won't have time to look at this until next week, but I'll report back once it's done.

Thanks for the suggestion!

peterpeterparker commented 6 months ago

Definitely no rush from my side and only a suggestion, everything works already smoothly!