mirror of https://github.com/ConsenSys/mythril
Add more precompile tests (#1576)
* Add tests for natives * Black updates * Update blackpull/1577/head
parent
4003ff1e80
commit
c72ac81de1
@ -0,0 +1,67 @@ |
||||
import pytest |
||||
|
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import ecrecover, NativeContractException |
||||
from mythril.laser.smt import symbol_factory |
||||
|
||||
msg = b"\x6b\x8d\x2c\x81\xb1\x1b\x2d\x69\x95\x28\xdd\xe4\x88\xdb\xdf\x2f\x94\x29\x3d\x0d\x33\xc3\x2e\x34\x7f\x25\x5f\xa4\xa6\xc1\xf0\xa9" |
||||
v = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1c" |
||||
r = b"\x53\x56\x92\x27\x4f\x15\x24\x34\x00\x2a\x7c\x4c\x7d\x7c\xd0\x16\xea\x3e\x2d\x70\x2f\x2d\x2f\xd5\xb3\x32\x64\x6a\x9e\x40\x9a\x6b" |
||||
s = b"\x1f\x59\x24\xf5\x9c\x6d\x77\x66\xa6\x93\x17\xa3\xdf\x72\x9d\x8b\x61\x3c\x67\xaa\xf2\xfe\x06\x13\x39\x8b\x9f\x94\x4b\x98\x8e\xbd" |
||||
|
||||
GOOD_DATA = list(msg + v + r + s) |
||||
|
||||
|
||||
@pytest.mark.parametrize( |
||||
"input_list, expected_result", |
||||
( |
||||
([], []), |
||||
([10, 20], []), |
||||
( |
||||
GOOD_DATA, |
||||
[ |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
131, |
||||
23, |
||||
8, |
||||
48, |
||||
142, |
||||
77, |
||||
185, |
||||
107, |
||||
254, |
||||
47, |
||||
229, |
||||
79, |
||||
224, |
||||
43, |
||||
181, |
||||
99, |
||||
36, |
||||
171, |
||||
166, |
||||
119, |
||||
], |
||||
), |
||||
), |
||||
) |
||||
def test_ecrecover(input_list, expected_result): |
||||
assert ecrecover(input_list) == expected_result |
||||
|
||||
|
||||
def test_ecrecover_symbol(): |
||||
input_list = ["bab", symbol_factory.BitVecSym("name", 256)] |
||||
with pytest.raises(NativeContractException): |
||||
ecrecover(input_list) |
@ -0,0 +1,13 @@ |
||||
import pytest |
||||
|
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import identity, NativeContractException |
||||
from mythril.laser.smt import symbol_factory |
||||
|
||||
|
||||
@pytest.mark.parametrize( |
||||
"input_list, expected_result", (([], []), ([10, 20], [10, 20])) |
||||
) |
||||
def test_identity(input_list, expected_result): |
||||
assert identity(input_list) == expected_result |
@ -0,0 +1,95 @@ |
||||
import pytest |
||||
|
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import ripemd160, NativeContractException |
||||
from mythril.laser.smt import symbol_factory |
||||
|
||||
|
||||
@pytest.mark.parametrize( |
||||
"input_list, expected_result", |
||||
( |
||||
( |
||||
[], |
||||
[ |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
156, |
||||
17, |
||||
133, |
||||
165, |
||||
197, |
||||
233, |
||||
252, |
||||
84, |
||||
97, |
||||
40, |
||||
8, |
||||
151, |
||||
126, |
||||
232, |
||||
245, |
||||
72, |
||||
178, |
||||
37, |
||||
141, |
||||
49, |
||||
], |
||||
), |
||||
( |
||||
[10, 20], |
||||
[ |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
92, |
||||
161, |
||||
226, |
||||
233, |
||||
76, |
||||
11, |
||||
228, |
||||
69, |
||||
224, |
||||
14, |
||||
89, |
||||
120, |
||||
246, |
||||
184, |
||||
197, |
||||
182, |
||||
35, |
||||
215, |
||||
51, |
||||
130, |
||||
], |
||||
), |
||||
), |
||||
) |
||||
def test_ripemd160(input_list, expected_result): |
||||
assert ripemd160(input_list) == expected_result |
||||
|
||||
|
||||
def test_ripemd160_symbol(): |
||||
input_list = ["bab", symbol_factory.BitVecSym("name", 256)] |
||||
with pytest.raises(NativeContractException): |
||||
ripemd160(input_list) |
@ -0,0 +1,95 @@ |
||||
import pytest |
||||
|
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import sha256, NativeContractException |
||||
from mythril.laser.smt import symbol_factory |
||||
|
||||
|
||||
@pytest.mark.parametrize( |
||||
"input_list, expected_result", |
||||
( |
||||
( |
||||
[], |
||||
[ |
||||
227, |
||||
176, |
||||
196, |
||||
66, |
||||
152, |
||||
252, |
||||
28, |
||||
20, |
||||
154, |
||||
251, |
||||
244, |
||||
200, |
||||
153, |
||||
111, |
||||
185, |
||||
36, |
||||
39, |
||||
174, |
||||
65, |
||||
228, |
||||
100, |
||||
155, |
||||
147, |
||||
76, |
||||
164, |
||||
149, |
||||
153, |
||||
27, |
||||
120, |
||||
82, |
||||
184, |
||||
85, |
||||
], |
||||
), |
||||
( |
||||
[10, 20], |
||||
[ |
||||
195, |
||||
48, |
||||
250, |
||||
117, |
||||
58, |
||||
197, |
||||
190, |
||||
59, |
||||
143, |
||||
203, |
||||
82, |
||||
116, |
||||
80, |
||||
98, |
||||
247, |
||||
129, |
||||
204, |
||||
158, |
||||
15, |
||||
79, |
||||
169, |
||||
129, |
||||
162, |
||||
189, |
||||
6, |
||||
252, |
||||
185, |
||||
105, |
||||
53, |
||||
91, |
||||
148, |
||||
105, |
||||
], |
||||
), |
||||
), |
||||
) |
||||
def test_sha256(input_list, expected_result): |
||||
assert sha256(input_list) == expected_result |
||||
|
||||
|
||||
def test_sha_symbol(): |
||||
input_list = ["bab", symbol_factory.BitVecSym("name", 256)] |
||||
with pytest.raises(NativeContractException): |
||||
sha256(input_list) |
Loading…
Reference in new issue