icopen / lightic

MIT License
13 stars 1 forks source link

Can't start test in Jest #2

Open ilbertt opened 1 year ago

ilbertt commented 1 year ago

I'm trying to use LightIC with Jest.

I wrote this simple test:

import { Actor } from "@dfinity/agent";
import { Principal } from "@dfinity/principal";
import { TestContext } from "lightic";

const context = new TestContext();
let actor: Actor;

describe("Canister", () => {
  beforeAll(async () => {
    // @ts-ignore
    const canister = await context.deploy('./.dfx/local/canisters/backend/backend.wasm');
    console.log(canister)

    const caller = Principal.anonymous();

    // @ts-ignore
    actor = Actor.createActor(canister.getIdlBuilder(), {
      // @ts-ignore
      agent: context.getAgent(caller),
      canisterId: canister.get_id()
    })
  });

  it("is true", () => {
    console.log(actor);
    expect(true).toBe(true);
  });
});

Run it simply with:

npx jest

But I got this error:

FAIL  tests/integration/canister.test.ts
  Canister
    ✕ is true (1 ms)

  ● Canister › is true

    TypeError: WebAssembly.Module.customSections(): Argument 0 must be a WebAssembly.Module

      at WasmCanister.get_candid (node_modules/lightic/src/wasm_canister.ts:270:42)
      at async WasmCanister.install_module_candid (node_modules/lightic/src/wasm_canister.ts:116:20)
      at async ReplicaContext.install_canister (node_modules/lightic/src/replica_context.ts:198:5)
      at async TestContext.deploy (node_modules/lightic/src/test_context.ts:49:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.083 s

The ./.dfx/local/canisters/backend/backend.wasm file exists.

(Note that I also had to use @ts-ignore, which I think is due to different versions of the @dfinity/* packages)

Context:

stopak commented 1 year ago

It looks like an issue with wasm file. I will check and try to fix this

ilbertt commented 1 year ago

I forgot to mention the dfx version:

which can probably help.

I've also added to my first issue comment.