-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkaya_cmd
61 lines (43 loc) · 1.96 KB
/
kaya_cmd
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
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/python3
# coding:utf-8 -*-
import sys
sys.path.append("./middle_server")
import argparse
import requests
import json
import xml.etree.cElementTree as ET
from config import server_host
from utils import search_for_tree
from web_handler import run_web_crawler
from middle_server import convert_list2map
def get_params(contract_name, contract_src_filename):
contract_src_code = open(contract_src_filename, "r").read()
data = {
"contract_src_code": contract_src_code,
"contract_name": contract_name
}
variables_dict = requests.post("http://%s/evm/params" % server_host, data=data).json()["contracts_params"]["file:%s" % contract_name]
print(variables_dict)
def perform_test_cases(contract_name, contract_source_filename, kaya_source_filename):
contract_src_code = open(contract_source_filename, "r").read()
kaya_source_code = open(kaya_source_filename, "r").read()
kaya_source = search_for_tree(ET.fromstring(kaya_source_code), dict())
kaya_source["Transactions"] = run_web_crawler(kaya_source["Transactions"])
data = {
"contract_src_code": contract_src_code,
"context": json.dumps(kaya_source),
"contract_name": contract_name
}
r = requests.post("http://%s/evm/cmd-running" % server_host, data=data).json()
print(r)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("behavior", type=str, help="Indicate the behavior you want kaya to do, support `var` and `case`.")
parser.add_argument("-n", "--name", type=str, help="The name of the smart contract the DAPP used.")
parser.add_argument("-s", "--source", type=str, help="The name of file you want to input.")
parser.add_argument("-d", "--dbdl", type=str, help="The name of DBDL file")
args = parser.parse_args()
if args.behavior == "var":
get_params(args.name, args.source)
elif args.behavior == "case":
perform_test_cases(args.name, args.source, args.dbdl)