@@ -155,16 +155,26 @@ mod test {
155
155
Account :: mock_code_balance ( code)
156
156
}
157
157
158
+ #[ derive( Copy , Clone , Debug ) ]
159
+ enum FailureReason {
160
+ Sstore ,
161
+ TStore ,
162
+ CallWithValue ,
163
+ }
164
+
158
165
#[ test]
159
166
fn test_write_protection ( ) {
160
- // test sstore with write protection error
161
- test_internal_write_protection ( false ) ;
162
- // test call with write protection error
163
- test_internal_write_protection ( true ) ;
167
+ for reason in [
168
+ FailureReason :: Sstore ,
169
+ FailureReason :: CallWithValue ,
170
+ FailureReason :: TStore ,
171
+ ] {
172
+ test_internal_write_protection ( reason)
173
+ }
164
174
}
165
175
166
176
// ErrorWriteProtection error happen in internal call
167
- fn test_internal_write_protection ( is_call : bool ) {
177
+ fn test_internal_write_protection ( reason : FailureReason ) {
168
178
let mut caller_bytecode = bytecode ! {
169
179
PUSH1 ( 0 )
170
180
PUSH1 ( 0 )
@@ -185,26 +195,36 @@ mod test {
185
195
PUSH1 ( 0x02 )
186
196
} ;
187
197
188
- if is_call {
189
- callee_bytecode. append ( & bytecode ! {
190
- PUSH1 ( 0 )
191
- PUSH1 ( 0 )
192
- PUSH1 ( 10 )
193
- PUSH1 ( 200 ) // non zero value
194
- PUSH20 ( Address :: repeat_byte( 0xff ) . to_word( ) )
195
- PUSH2 ( 10000 ) // gas
196
- //this call got error: ErrorWriteProtection
197
- CALL
198
- RETURN
199
- STOP
200
- } ) ;
201
- } else {
202
- callee_bytecode. append ( & bytecode ! {
203
- // this SSTORE got error: ErrorWriteProtection
204
- SSTORE
205
- STOP
206
- } ) ;
207
- }
198
+ match reason {
199
+ FailureReason :: CallWithValue => {
200
+ callee_bytecode. append ( & bytecode ! {
201
+ PUSH1 ( 0 )
202
+ PUSH1 ( 0 )
203
+ PUSH1 ( 10 )
204
+ PUSH1 ( 200 ) // non zero value
205
+ PUSH20 ( Address :: repeat_byte( 0xff ) . to_word( ) )
206
+ PUSH2 ( 10000 ) // gas
207
+ //this call got error: ErrorWriteProtection
208
+ CALL
209
+ RETURN
210
+ STOP
211
+ } ) ;
212
+ }
213
+ FailureReason :: Sstore => {
214
+ callee_bytecode. append ( & bytecode ! {
215
+ // this SSTORE got error: ErrorWriteProtection
216
+ SSTORE
217
+ STOP
218
+ } ) ;
219
+ }
220
+ FailureReason :: TStore => {
221
+ callee_bytecode. append ( & bytecode ! {
222
+ // this TSTORE got error: ErrorWriteProtection
223
+ TSTORE
224
+ STOP
225
+ } ) ;
226
+ }
227
+ } ;
208
228
209
229
test_ok (
210
230
Account :: mock_100_ether ( caller_bytecode) ,
0 commit comments