FuelLabs/fuels-rs

Incorrect (generic) error propagation upon a `.simulate()`

Closed this issue · 0 comments

A function that contains a require() statement that uses .call() to change the state of the contract will propagate the error to the test enabling the developer to catch that specific error in a should_panic = "reason" ex.

https://github.com/FuelLabs/sway-applications/blob/c489f15bdc85787fa9b5d7db47839ca5d0bf21ea/escrow/escrow-contract/tests/functions/core/accept_arbiter.rs#L155

Another function that is pure (read-only) ought to use .simulate() instead of .call().
Lets say that function uses a require() for some configurables (it doesn't read from storage, only configurables to enforce a requirement).
Unlike the first example above once this function is simulated it will not propagate the correct error from the require() and instead provide a generic error Revert transaction error: Revert.

This does not allow the developer to simulate function calls that are restricted ex. via configurable "owner only" calls.
If the .simulate() is changed to .call() (despite not touching storage, only the configurables) then the correct error is propagated to the should_panic = "reason".