@@ -77,60 +77,39 @@ def check_balance(sender, destination):
7777 self .assertTrue (testcheck .visited_hookinsn )
7878
7979 def test_underflow_filename (self ):
80- ql = Qiling (["rootfs/evm/undeflow.hex" ], archtype = "evm" , verbose = 4 )
81- testcheck = Checklist ()
82- argu = ql .arch .evm .abi .convert (['uint256' ], [20 ])
83- code = ql .code + argu
80+ ql = Qiling (["rootfs/evm/Hexagon.hex" ], archtype = "evm" , verbose = 4 )
8481
8582 user1 = ql .arch .evm .create_account (balance = 100 * 10 ** 18 )
8683 user2 = ql .arch .evm .create_account (balance = 100 * 10 ** 18 )
8784 c1 = ql .arch .evm .create_account ()
8885
89- def hookcode_test (ql , * argv ):
90- testcheck .visited_hookcode = True
91-
92- def hookinsn_test (ql , * argv ):
93- testcheck .visited_hookinsn = True
94-
95- def hookaddr_test (ql ):
96- testcheck .visited_hookaddr = True
97-
98- h0 = ql .hook_code (hookcode_test )
99- h1 = ql .hook_address (hookaddr_test , 10 )
100-
101- # message1: deploy runtime code
102- msg0 = ql .arch .evm .create_message (user1 , b'' , code = code , contract_address = c1 )
103- ql .run (code = msg0 )
104-
105- ql .hook_del (h0 )
106- ql .hook_del (h1 )
107- h2 = ql .hook_insn (hookinsn_test , 'PUSH4' )
108-
109- # # SMART CONTRACT DEPENDENT - message2: check balance of user1, should be 20
11086 def check_balance (sender , destination ):
11187 call_data = '0x70a08231' + ql .arch .evm .abi .convert (['address' ], [sender ])
112- msg2 = ql .arch .evm .create_message (sender , destination , call_data )
88+ msg2 = ql .arch .evm .create_message (sender , destination , data = call_data )
11389 return ql .run (code = msg2 )
114-
90+
91+ # Deploy runtime code
92+ msg0 = ql .arch .evm .create_message (user1 , b'' , code = ql .code , contract_address = c1 )
93+ ql .run (code = msg0 )
94+
95+ # # SMART CONTRACT DEPENDENT: check balance of user1
11596 result = check_balance (user1 , c1 )
116- print ('\n \n user1 balance =' , int (result .output .hex ()[2 :], 16 ))
117- ql .hook_del (h2 )
97+ print ('User1 balance =' , int (result .output .hex ()[2 :], 16 ))
11898
119- # SMART CONTRACT DEPENDENT - message3 : transform 21 from user1 to user2
99+ # # SMART CONTRACT DEPENDENT: transform from user1 to user2
120100 call_data = '0xa9059cbb' + ql .arch .evm .abi .convert (['address' ], [user2 ]) + \
121- ql .arch .evm .abi .convert (['uint256' ], [21 ])
122- msg1 = ql .arch .evm .create_message (user1 , c1 , call_data )
101+ ql .arch .evm .abi .convert (['uint256' ], [0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe ])
102+ msg1 = ql .arch .evm .create_message (user1 , c1 , data = call_data )
123103 result = ql .run (code = msg1 )
124- print ('\n \n is success =' , int (result .output .hex ()[2 :], 16 ))
104+ if int (result .output .hex ()[2 :], 16 ) == 1 :
105+ print ('User1 transfered Token to User1' )
125106
126- # message4: check balance of user1, should be MAX - 1
107+ # # SMART CONTRACT DEPENDENT: User1 balance underflow, MAX - 1
127108 result = check_balance (user1 , c1 )
128- print ('\n \n user1 balance =' , hex (int (result .output .hex ()[2 :], 16 )))
129-
130- self .assertEqual (hex (int (result .output .hex ()[2 :], 16 )), '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' )
131- self .assertTrue (testcheck .visited_hookaddr )
132- self .assertTrue (testcheck .visited_hookcode )
133- self .assertTrue (testcheck .visited_hookinsn )
109+ self .assertEqual (int (result .output .hex ()[2 :], 16 ), 420000000000000 )
110+
111+ result = check_balance (user2 , c1 )
112+ self .assertEqual (int (result .output .hex ()[2 :], 16 ), 452312848583266388373324160190187140051835877600158453279131187530910662654 )
134113
135114if __name__ == "__main__" :
136115 unittest .main ()
0 commit comments