o1-labs / o1js

TypeScript framework for zk-SNARKs and zkApps

Home Page:https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: `LocalBlockchain` does not update contract state unless some `SmartContract` state is explicitly called

Pfed-prog opened this issue · comments

LocalBlockchain does not update contract state unless any contract state is explicitly called

it('deploys app', async () => {
    await deployNFTContract(
      pkAdmin,
      nftContractPrivateKey,
      proofsEnabled,
      live
    );
});

it('inits app root', async () => {
    await initNFTContractRoot(
      pkAdmin,
      pkSender,
      map,
      nftContract,
      nftArray.length,
      live
    );
  });

produces FieldVector.get(): Index out of bounds, got 0/0 error in initNFTContractRoot

But it is fixed by calling a state in smart contract

  it('deploys app', async () => {
    await deployNFTContract(
      pkAdmin,
      nftContractPrivateKey,
      proofsEnabled,
      live
    );
    expect(nftContract.admin.get().toBase58()).toBe(pubAdmin.toBase58());
  });

With no expect(nftContract.admin.get().toBase58()).toBe(pubAdmin.toBase58());

Prove.log() also seems to stop logging before private function but continues just fine the private functions code is moved to the main function.

for another subsequent test with the same function

Prove.log() stops logging even earlier for some reason on signature.verify

There seems to be something wrong with smart contract states not reseting.

Because when I add expect(nftContract.admin.get().toBase58()).toBe(pubAdmin.toBase58());

but move an intentionally faulty test before the correct one

the correct one fails at setting a state

One general suggestion: check that you always await contract calls

Other than that it's very hard to say anything without seeing the code of those functions you call

@mitschabaude I am not sure where the error comes from exactly, but it has definitely to do with calling async contract methods
image

I am not sure if i should declare async private and public methods
or something is off with how i call transactions, but it definitely works without async