Skip to content

Commit

Permalink
return ErrRevert for revert errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lmittmann committed Aug 29, 2023
1 parent 9c65292 commit f269772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions w3vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var (
big1 = big.NewInt(1)
pendingBlockNumber = big.NewInt(-1)

ErrFetch = errors.New("fetch error")
ErrRevert = errors.New("revert error")
ErrFetch = errors.New("fetching failed")
ErrRevert = errors.New("execution reverted")
)

type VM struct {
Expand Down Expand Up @@ -173,9 +173,9 @@ func (v *VM) apply(msg *w3types.Message, isCall bool, tracer vm.EVMLogger) (*Rec

if err := result.Err; err != nil {
if reason, unpackErr := abi.UnpackRevert(result.ReturnData); unpackErr != nil {
receipt.Err = err
receipt.Err = ErrRevert
} else {
receipt.Err = fmt.Errorf("%w: %s", err, reason)
receipt.Err = fmt.Errorf("%w: %s", ErrRevert, reason)
}
}
if msg.To == nil {
Expand Down
8 changes: 4 additions & 4 deletions w3vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,25 @@ func TestVM_Fetcher(t *testing.T) {
}

_, err = vm.Nonce(addr0)
want := "fetch error: failed to fetch nonce of 0x0000000000000000000000000000000000000000"
want := "fetching failed: failed to fetch nonce of 0x0000000000000000000000000000000000000000"
if !errors.Is(err, w3vm.ErrFetch) || want != err.Error() {
t.Errorf("Nonce: want %q, got %q", want, err)
}

_, err = vm.Balance(addr0)
want = "fetch error: failed to fetch balance of 0x0000000000000000000000000000000000000000"
want = "fetching failed: failed to fetch balance of 0x0000000000000000000000000000000000000000"
if !errors.Is(err, w3vm.ErrFetch) || want != err.Error() {
t.Errorf("Balance: want %q, got %q", want, err)
}

_, err = vm.Code(addr0)
want = "fetch error: failed to fetch code of 0x0000000000000000000000000000000000000000"
want = "fetching failed: failed to fetch code of 0x0000000000000000000000000000000000000000"
if !errors.Is(err, w3vm.ErrFetch) || want != err.Error() {
t.Errorf("Code: want %q, got %q", want, err)
}

_, err = vm.StorageAt(addr0, common.Hash{})
want = "fetch error: failed to fetch storage of 0x0000000000000000000000000000000000000000 at 0x0000000000000000000000000000000000000000000000000000000000000000"
want = "fetching failed: failed to fetch storage of 0x0000000000000000000000000000000000000000 at 0x0000000000000000000000000000000000000000000000000000000000000000"
if !errors.Is(err, w3vm.ErrFetch) || want != err.Error() {
t.Errorf("StorageAt: want %q, got %q", want, err)
}
Expand Down

0 comments on commit f269772

Please sign in to comment.