-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathto_javascript_tests.py
50 lines (41 loc) · 1.37 KB
/
to_javascript_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# Convert output of --dump-json to JavaScript tests
import sys
import json
def toBigInt(v):
if v == '-':
v = '-0'
return 'BigInt("{}")'.format(v)
BIGNUMCALC_ADD_TPL = '{} + {} == {}'
BIGNUMCALC_SUB_TPL = '{} - {} == {}'
BIGNUMCALC_MUL_TPL = '{} * {} == {}'
BIGNUMCALC_DIV_TPL = '{} / {} == {}'
BIGNUMCALC_MOD_TPL = '{} % {} == {}'
def constructAssert(cond):
return 'console.assert({});'.format(cond)
with open(sys.argv[1], 'rb') as fp:
for l in fp:
j = json.loads(l)
op = j['operation']
if op['operation'] == 'BignumCalc':
if op['calcOp'] == '10633833424446033180':
tpl = BIGNUMCALC_ADD_TPL
elif op['calcOp'] == '7565474059520578463':
tpl = BIGNUMCALC_SUB_TPL
elif op['calcOp'] == '12211643382727132651':
tpl = BIGNUMCALC_MUL_TPL
elif op['calcOp'] == '13646095757308424912':
tpl = BIGNUMCALC_DIV_TPL
elif op['calcOp'] == '12110391648600810285':
tpl = BIGNUMCALC_MOD_TPL
else:
continue
print(
constructAssert(
tpl.format(
toBigInt(op['bn0']),
toBigInt(op['bn1']),
toBigInt(j['result'])
)
)
)