@@ -155,16 +155,25 @@ mod test {
155155        Account :: mock_code_balance ( code) 
156156    } 
157157
158+     enum  FailureReason  { 
159+         Sstore , 
160+         TStore , 
161+         CallWithValue , 
162+     } 
163+ 
158164    #[ test]  
159165    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+         } 
164173    } 
165174
166175    // ErrorWriteProtection error happen in internal call 
167-     fn  test_internal_write_protection ( is_call :   bool )  { 
176+     fn  test_internal_write_protection ( reason :   FailureReason )  { 
168177        let  mut  caller_bytecode = bytecode !  { 
169178            PUSH1 ( 0 ) 
170179            PUSH1 ( 0 ) 
@@ -185,26 +194,36 @@ mod test {
185194            PUSH1 ( 0x02 ) 
186195        } ; 
187196
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+         } ; 
208227
209228        test_ok ( 
210229            Account :: mock_100_ether ( caller_bytecode) , 
0 commit comments