File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,7 @@ type VmError interface {
131
131
Error () string
132
132
VmError () string
133
133
Ret () []byte
134
+ Reason () string
134
135
}
135
136
136
137
type vmErrorWithRet struct {
Original file line number Diff line number Diff line change @@ -51,3 +51,54 @@ func TestNewExecErrorWithReason(t *testing.T) {
51
51
require .Equal (t , 3 , errWithReason .ErrorCode ())
52
52
}
53
53
}
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
+ }
You can’t perform that action at this time.
0 commit comments