#Jest worker encountered 4 child process exceptions, exceeding retry limit

5 messages · Page 1 of 1 (latest)

woeful cape
#
describe('Guardian', () => {
  beforeAll(async () => {
    await isReady;
  });
  describe('#Guardian().from', () => {
    it('create a new guardian', async () => {
      const guardianAccount = PrivateKey.random().toPublicKey();
      const guardian = Guardian.from(
        guardianAccount,
        Field(100),
        Field(1),
        Bool(true),
        new GuardianWitness(dummyWitness)
      );
      expect(guardian.publicKey).toEqual(guardianAccount);
      expect(guardian.guardianId).toEqual(Field(100));
      expect(guardian.nullifier).toEqual(Field(1));
      expect(guardian.isActive).toEqual(Bool(true));
      expect(guardian.witness).toEqual(new GuardianWitness(dummyWitness));
    });
  });

  describe('#empty().from', () => {
    it('create a new guardian', async () => {
      const guardian = Guardian.empty();
      expect(guardian.publicKey).toEqual(PublicKey.empty());
      expect(guardian.guardianId).toEqual(Field(0));
      expect(guardian.nullifier).toEqual(Field(0));
      expect(guardian.isActive).toEqual(Bool(false));
    });
  });

  describe('#hash()', () => {
    it('should return hash of the guardian', async () => {
      const guardianAccount = PrivateKey.random().toPublicKey();
      const guardianHash = Poseidon.hash(
        guardianAccount
          .toFields()
          .concat(Field(1))
          .concat(Field(2))
          .concat(Bool(true).toFields())
      );
      const newGuardian = Guardian.from(
        guardianAccount,
        Field(1),
        Field(2),
        Bool(true),
        new GuardianWitness(dummyWitness)
      );
      expect(newGuardian.hash()).toEqual(guardianHash);
    });
  });
});
#

Another test within the same file:

let proofsEnabled = true;

describe('GuardianZkApp', () => {
  let deployerAccount: PublicKey,
    deployerKey: PrivateKey,
    guardians: [
      {
        key: PrivateKey;
        account: PublicKey;
      }
    ],
    zkAppAddress: PublicKey,
    zkAppPrivateKey: PrivateKey,
    zkApp: GuardianZkApp;
  const guardianTree = new MerkleTree(8);
  beforeAll(async () => {
    await isReady;
    if (proofsEnabled) GuardianZkApp.compile();
  });
  beforeEach(() => {
    const Local = Mina.LocalBlockchain({ proofsEnabled });
    Mina.setActiveInstance(Local);
    ({ privateKey: deployerKey, publicKey: deployerAccount } =
      Local.testAccounts[0]);
    for (let i = 0; i < 7; i++) {
      ({ privateKey: guardians[i].key, publicKey: guardians[i].account });
      guardianTree.setLeaf(
        0n,
        Guardian.from(
          guardians[i].account,
          Field(i),
          Field(i),
          Bool(true),
          new GuardianWitness(dummyWitness)
        ).hash()
      );
    }
    zkAppPrivateKey = PrivateKey.random();
    zkAppAddress = zkAppPrivateKey.toPublicKey();
    zkApp = new GuardianZkApp(zkAppAddress);
  });

  afterAll(() => {
    setTimeout(shutdown, 0);
  });

  async function localDeploy() {
    const txn = await Mina.transaction(deployerAccount, () => {
      AccountUpdate.fundNewAccount(deployerAccount);
      zkApp.deploy();
    });
    await txn.prove();
    await txn.sign([deployerKey, zkAppPrivateKey]).send();

    console.log('deploy and fund user accounts');
  }

  describe('#init', () => {
    it('generates and deploys the `GuardianZkApp` smart contract', async () => {
      await localDeploy();
      const committedGuardians = await zkApp.committedGuardians.get();
      expect(committedGuardians).toEqual(Field(0));

      const accumulatedGuardians = await zkApp.accumulatedGuardians.get();
      expect(accumulatedGuardians).toEqual(Field(0));
    });
  });
});
winter kindle
#

My humble advice is to make your flow work in a plain nodejs script first, so you don't have to debug through Jest which is annoying in my experience

#

Then when you know it all should work, you can start making it work as a set of Jest tests and fix any additional problems there

woeful cape
#

it works now. Solution:

  • separated Guardian.test.ts with GuardianZkApp.test.ts
  • separated for loop pushing guardians array with setting guardianTree