-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.to.be.revertedWith only works with callStatic (Rinkeby) #579
Comments
I've tried it also with Ropsten and I have the same issue. Interestingly, the test works with hardhat locally. Also interestingly, when I do: TxReceipt = await (await marketplaceContractNftAddr1.withdraw(numberToWithdraw)).wait() I get the contract error (after some time waiting). However, the test runs much quicker, and reverts with no error (even though the transaction has failed). Its rather baffling - the matcher think its successful when its not, before even waiting for the receipt. |
So I tried to figure out exactly whats causing this - I made the simplest of contracts:
And the following test:
It works - great. However, if I make the function payable like this: `contract TestContract {
}` The test fails: ` AssertionError: Expected transaction to be reverted
I've tried this with different compiler versons (0.6.0/0.7.2/0.8.7) and its the same problem. Would appreciate some input - is this not meant to work for functions that could change state? Am I missing something? or is it a bug? Thank you |
Note that this is on testnet (Roptsten) |
To those interested - toberevertedwith doesn't work on Ropsten or Rinkeby as they dont return any error strings. It would be useful to include this information in the documentation as it took me a while to figure it out. |
I'm running into a very similar problem, and I am using the hardhat network with interval mining. I think it only works locally without mining because a state changing call can immediately revert, whereas the call needs to be mined on a testnet for it to revert correctly. I had forgotten about callStatic, and I think that is the best way to go around this so thank you for posting |
await expect(marketplaceContractNftAddr1.callStatic.withdraw(numberToWithdraw)) .to.be.revertedWith('Insufficient available balance')
Works as expected. However:
await expect(marketplaceContractNftAddr1.withdraw(numberToWithdraw)) .to.be.revertedWith('Insufficient available balance')
Produces:
AssertionError: Expected transaction to be reverted with Insufficient available balance, but other exception was thrown: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":3,"_isProviderError":true,"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e496e73756666696369656e7420617661696c61626c652062616c616e63650000"}, method="estimateGas", transaction={"from":"0xe5B256071adac2Ff3a7a27EC268b59b7f31d1F04","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x9502f900"},"maxFeePerGas":{"type":"BigNumber","hex":"0x9502f912"},"to":"0xf7C7f2AE52BcE0B785AF7795938DAaB6b2612952","data":"0xdee4dea00000000000000000000000000000000000000000000000000000000000000003","type":2,"accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.4.5)
Even though on Alchemy, I can see that the transaction reverted correctly:
{"jsonrpc": "2.0", "id": 50, "error": {"code": 3, "message": "execution reverted: Insufficient available balance", "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e496e73756666696369656e7420617661696c61626c652062616c616e63650000"}}
Is this a bug or am I missing something obvious?
The text was updated successfully, but these errors were encountered: