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

Overwriting/mocking stable vars #9

Open
jake-beardo opened this issue Mar 12, 2024 · 1 comment
Open

Overwriting/mocking stable vars #9

jake-beardo opened this issue Mar 12, 2024 · 1 comment

Comments

@jake-beardo
Copy link

I have an actor class which looks like this

actor class Orchestrator() = this {
    let { phash } = Map;

    private stable var pool = Map.new<Principal, Types.CanisterInfo>();

    let management = Management.service(Constants.ManagementCanisterId);
    
    // Auth so that only server and admin can talk to this canister
    let admin = Principal.fromText("qcjer-cl7l3-dae");
    let game_controller = Principal.fromText("7k7-lqlgk-x56ep");
    private stable var admins = Vector.fromArray<Principal>([admin, game_controller]);

I then have some tests which look like this

var orchestrator = await Orchestrator();

let caller : Principal = Principal.fromText("wo5qg-ysjiq-5da");

let user1 : Principal = Principal.fromText("kufey-x4r");
let user2 : Principal = Principal.fromText("mm6ly-2yowe");
let user3 : Principal = Principal.fromText("wkvns-5prta");
var admins : Vector<Principal> = Vector.fromArray([caller, user1, user2]);

func resetMocks() : () {
  admins := Vector.fromArray([caller, user1, user2]);
};


await suite(
  "createEvent",
  func() : async () {
    await test(
      "setEventWasm works correctly",
      func() : async () {
        resetMocks();


        let oldEventWasm = await orchestrator.getEventWasm();

The getEventWasm function requires admin verification so i need to change the admins in my Orchestrator actor class to include this principal wo5qg-ysjiq-5da. have you got a good way of suggesting how I do this? I could pass it as an argument to my actor orchestrator class when i create it i suppose but i was wondering if there might be a better way to do it

@ZenVoich
Copy link
Owner

Unfortunately there is no way to fake the caller principal id.

You can take a look at pocket-ic that might be more powerful to write e2e tests(and use rust, python or js):
https://forum.dfinity.org/t/announcing-picjs-typescript-javascript-support-for-pocketic/24479
https://forum.dfinity.org/t/announcing-picjs-typescript-javascript-support-for-pocketic/24479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants