Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

def login(url, pr_key, role=0, ecosystem=1):
token, uid = api.getuid(url)
print('UID: ', uid)
result = api.login(
url=url,
token=token,
Expand Down Expand Up @@ -70,6 +71,7 @@ def tx_status(url, sleep_time, hsh, jvt_token):
time.sleep(1)
resp = api.tx_status(url, jvt_token, hsh)
jresp = resp['results'][hsh]
print(jresp)
if (len(jresp['blockid']) > 0 and 'errmsg' not in json.dumps(jresp)) or ('errmsg' in json.dumps(jresp)):
break
else:
Expand All @@ -79,6 +81,7 @@ def tx_status(url, sleep_time, hsh, jvt_token):
if 'errmsg' not in jresp and int(jresp['blockid']) > 0:
return {'blockid': int(jresp['blockid']), 'result': jresp['result'], 'error': None}
else:
print('error in block', jresp['errmsg']['error'])
return {'blockid': 0, 'error': jresp['errmsg']['error'], 'result': None}

def is_sync(config, wait_time, nodes):
Expand Down
3 changes: 2 additions & 1 deletion libs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def getuid(url):


def login(url, token, uid, private_key, role_id=0, ecosystem=1, expire=3600):

print('net_id: ', tools.read_config('test')['networkID'])
signature = sign(private_key, 'LOGIN' + tools.read_config('test')['networkID'] + uid)
print("Private_key", private_key)
pubkey = get_public_key(private_key)
full_token = 'Bearer ' + token
data = {
Expand Down
1 change: 1 addition & 0 deletions libs/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def compare_nodes(config):

def is_tx_in_block(url, wait, tx, token):
status = actions.tx_status(url, wait, tx['hash'], token)
print('status: ', status)
if status['blockid'] > 0:
return status['blockid']
else:
Expand Down
30 changes: 20 additions & 10 deletions libs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,27 @@ def generate_code(contract_name, source_code):

def read_config(type):
path = ''
if type == 'main':
path = os.path.join(os.getcwd(), 'config.json')
if type == 'nodes':
path = os.path.join(os.getcwd(), 'nodesConfig.json')
if type == 'nodes_ex':
path = os.path.join(os.getcwd(), 'nodesConfig_ex.json')
if type == 'test':
path = os.path.join(os.getcwd(), 'testConfig.json')
with open(path, 'r') as f:
data = f.read()
return json.loads(data)
path1 = os.path.join(os.getcwd(), 'testConfig.json')
path2 = os.path.join(os.getcwd(), 'testConfig.default.json')
with open(path1, 'r') as f1:
data1 = f1.read()
conf = json.loads(data1)
with open(path2, 'r') as f2:
data2 = f2.read()
conf_d = json.loads(data2)
conf_d.update(conf)
return conf_d
else:
if type == 'main':
path = os.path.join(os.getcwd(), 'config.json')
if type == 'nodes':
path = os.path.join(os.getcwd(), 'nodesConfig.json')
if type == 'nodes_ex':
path = os.path.join(os.getcwd(), 'nodesConfig_ex.json')
with open(path, 'r') as f:
data = f.read()
return json.loads(data)


def write_config(new_conf):
Expand Down
6 changes: 3 additions & 3 deletions link_nodes_x.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

if __name__ == '__main__':
log.info('Start ' + __name__)
config = tools.read_config('test')
print('TestConfig: ', config)
wait = tools.read_config('test')['wait_tx_status']
conf = tools.read_config('nodes')
url = conf[0]['url']
pr_key1 = conf[0]['private_key']
pr_key2 = conf[1]['private_key']
pr_key3 = conf[2]['private_key']
test_config = tools.read_config('test')
test_config.update({'net_work': 'xreg'})
tools.write_config(test_config)
data = actions.login(url, pr_key1, 0)
token1 = data['jwtToken']
actions.imp_app('system', url, pr_key1, token1, data['account'])
Expand All @@ -34,6 +33,7 @@
print("Strt update full_nodes")
data = {'Name': 'full_nodes', 'Value': full_nodes}
res = actions.call_contract(url, pr_key1, 'UpdateSysParam', data, token1)
print('here')
if check.is_tx_in_block(url, wait, {'hash': res}, token1):
log.info('Nodes successfully linked')
else:
Expand Down
15 changes: 13 additions & 2 deletions scripts/run_three_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
parser.add_argument('-test', default='true')
parser.add_argument('-wait', default='3')
parser.add_argument('-private', default='true')

parser.add_argument('-net_type', default='cn')

args = parser.parse_args()

Expand All @@ -66,6 +66,7 @@

# Set centrifugo variables
centrifugo_secret = '4597e75c-4376-42a6-8c1f-7e3fc7eb2114'
centKey = '123456'
centrifugo_url = 'http://127.0.0.1:8000'
cenConfig = os.path.join(args.centrifugo, 'config.json')
cenPath = os.path.join(args.centrifugo, 'centrifugo')
Expand All @@ -74,6 +75,7 @@
# Create config for centrifugo
cen_config_string = {
'secret': centrifugo_secret,
"api_key": centKey,
'admin_secret': 'admin'
}
with open(cenConfig, 'w') as cen_conf_file:
Expand Down Expand Up @@ -110,6 +112,7 @@
'--dbUser='+args.dbUser,
'--centUrl='+centrifugo_url,
'--centSecret='+centrifugo_secret,
'--centKey='+centKey,
'--tcpPort='+args.tcpPort1,
'--httpPort='+args.httpPort1,
'--dbName='+args.dbName1,
Expand Down Expand Up @@ -174,6 +177,7 @@
'--dbPassword='+args.dbPassword,
'--centUrl='+centrifugo_url,
'--centSecret='+centrifugo_secret,
'--centKey='+centKey,
'--nodesAddr='+'127.0.0.1:'+args.tcpPort1,
'--mpgt=2000',
'--networkID=130186',
Expand Down Expand Up @@ -206,6 +210,7 @@
'--dbPassword='+args.dbPassword,
'--centUrl='+centrifugo_url,
'--centSecret='+centrifugo_secret,
'--centKey='+centKey,
'--nodesAddr='+'127.0.0.1:'+args.tcpPort1,
'--mpgt=2000',
'--networkID=130186',
Expand Down Expand Up @@ -338,11 +343,17 @@
}
}]

# Update config for tests
# Update configs for tests
confPath = os.path.join(curDir + '/../', 'nodesConfig.json')
confTestPath = os.path.join(curDir + '/../', 'testConfig.json')

with open(confPath, 'w') as fconf:
fconf.write(json.dumps(config, indent=4))
log.info('Updated file nodesConfig.json')

testConf = {"net_work": args.net_type}
with open(confTestPath, 'w') as tconf:
tconf.write(json.dumps(testConf, indent=4))
log.info('Updated file testConfig.json')

log.info('Nodes successfully started')
File renamed without changes.