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