matter-labs / zksync-cli

CLI tool that simplifies ZKsync development
MIT License
166 stars 96 forks source link

`tx.wait` behaves unexpectantly in tests #127

Closed spacesailor24 closed 1 month ago

spacesailor24 commented 7 months ago

🐛 Bug Report for zkSync CLI

📝 Description

There seems to be some sort of delay between a transaction that transfers ETH being included in a block, and the ETH balance of the receiving account being update and queryable via provider.getBalance - tx.wait doesn't seem to have an affect

🔄 Reproduction Steps

I've created a minimal reproduction repo here

🤔 Expected Behavior

After doing:

const tx = await wallet.sendTransaction({ value: parseEther('1'), to: receiver });
await tx.wait();

console.log(await wallet.provider.getBalance(receiver));

The console.loged value should immediately be 1000000000000000000n

😯 Current Behavior

The immediate console.log (and many after) log 0n, after sometime getBalance finally returns the expected incremented balance for the receiver

🖥️ Environment

📋 Additional Context

See reproduction repo

spacesailor24 commented 7 months ago

Using the cli, I created a new project using ethersv5 and it doesn't seem to be an issue anymore

uF4No commented 7 months ago

hey @spacesailor24 this might be related to the cache that ethers v6 has implemented by default. This has been mentioned across different issues (example here. Please try disabling the cache by initialising your provider this way:

const provider = new Provider(url, undefined, {cacheTimeout: -1});
dutterbutter commented 1 month ago

Closing due to staleness.