Skip to content

Commit 8f05d8e

Browse files
authored
Merge pull request #8 from InjectiveLabs/chore/vmerror-reason
chore: add Reason() method to VmError interface
2 parents 874b2db + a9fdaa3 commit 8f05d8e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

x/evm/types/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type VmError interface {
131131
Error() string
132132
VmError() string
133133
Ret() []byte
134+
Reason() string
134135
}
135136

136137
type vmErrorWithRet struct {

x/evm/types/errors_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,54 @@ func TestNewExecErrorWithReason(t *testing.T) {
5151
require.Equal(t, 3, errWithReason.ErrorCode())
5252
}
5353
}
54+
55+
func TestNewVmErrorWithRet(t *testing.T) {
56+
testCases := []struct {
57+
name string
58+
vmErr string
59+
reason string
60+
ret []byte
61+
hash string
62+
}{
63+
{
64+
"Empty reason",
65+
"execution reverted",
66+
"",
67+
nil,
68+
"0x",
69+
},
70+
{
71+
"With unpackable reason",
72+
"execution reverted",
73+
"",
74+
[]byte("a"),
75+
"0x61",
76+
},
77+
{
78+
"With packable reason but empty reason",
79+
"execution reverted",
80+
"",
81+
revertSelector,
82+
"0x08c379a0",
83+
},
84+
{
85+
"With packable reason with reason",
86+
"execution reverted",
87+
"COUNTER_TOO_LOW",
88+
hexutils.HexToBytes("08C379A00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000F434F554E5445525F544F4F5F4C4F570000000000000000000000000000000000"),
89+
"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f434f554e5445525f544f4f5f4c4f570000000000000000000000000000000000",
90+
},
91+
}
92+
93+
for _, tc := range testCases {
94+
tc := tc
95+
vmErrorWithRet := NewVmErrorWithRet(
96+
tc.vmErr,
97+
tc.ret,
98+
tc.hash,
99+
0,
100+
)
101+
require.Equal(t, tc.vmErr, vmErrorWithRet.VmError())
102+
require.Equal(t, tc.reason, vmErrorWithRet.Reason())
103+
}
104+
}

0 commit comments

Comments
 (0)