o1js icon indicating copy to clipboard operation
o1js copied to clipboard

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

Open Pfed-prog opened this issue 1 year ago • 4 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());
  });

Pfed-prog avatar Apr 21 '24 02:04 Pfed-prog

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

Pfed-prog avatar Apr 21 '24 04:04 Pfed-prog

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 avatar Apr 21 '24 07:04 mitschabaude

Downgraded to 0.17.0 as it does not force me to have async transactions and async deploy.

But I face a very similar errors when I call contract methods in async.

https://github.com/PinSaveDAO/PinSave/blob/master/packages/mina/src/NFTsMapContract.ts

deploy function

https://github.com/PinSaveDAO/PinSave/blob/f573cfd82ae0b87f60bae7089b7df6a038c78ab4/packages/mina/src/components/transactions.ts#L269C1-L289C2

test

https://github.com/PinSaveDAO/PinSave/blob/f573cfd82ae0b87f60bae7089b7df6a038c78ab4/packages/mina/tests/NFTsMapContract.test.ts#L54C1-L65C6

When only deploy tx in async this change works image

Pfed-prog avatar Apr 21 '24 18:04 Pfed-prog

@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

Pfed-prog avatar Apr 21 '24 18:04 Pfed-prog