Skip to content

Commit

Permalink
Merge pull request #8 from InjectiveLabs/chore/vmerror-reason
Browse files Browse the repository at this point in the history
chore: add Reason() method to VmError interface
  • Loading branch information
arrivets authored Oct 25, 2024
2 parents 874b2db + a9fdaa3 commit 8f05d8e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/evm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type VmError interface {
Error() string
VmError() string
Ret() []byte
Reason() string
}

type vmErrorWithRet struct {
Expand Down
51 changes: 51 additions & 0 deletions x/evm/types/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,54 @@ func TestNewExecErrorWithReason(t *testing.T) {
require.Equal(t, 3, errWithReason.ErrorCode())
}
}

func TestNewVmErrorWithRet(t *testing.T) {
testCases := []struct {
name string
vmErr string
reason string
ret []byte
hash string
}{
{
"Empty reason",
"execution reverted",
"",
nil,
"0x",
},
{
"With unpackable reason",
"execution reverted",
"",
[]byte("a"),
"0x61",
},
{
"With packable reason but empty reason",
"execution reverted",
"",
revertSelector,
"0x08c379a0",
},
{
"With packable reason with reason",
"execution reverted",
"COUNTER_TOO_LOW",
hexutils.HexToBytes("08C379A00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000F434F554E5445525F544F4F5F4C4F570000000000000000000000000000000000"),
"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f434f554e5445525f544f4f5f4c4f570000000000000000000000000000000000",
},
}

for _, tc := range testCases {
tc := tc
vmErrorWithRet := NewVmErrorWithRet(
tc.vmErr,
tc.ret,
tc.hash,
0,
)
require.Equal(t, tc.vmErr, vmErrorWithRet.VmError())
require.Equal(t, tc.reason, vmErrorWithRet.Reason())
}
}

0 comments on commit 8f05d8e

Please sign in to comment.