-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
merge最新代码 #12
base: master
Are you sure you want to change the base?
merge最新代码 #12
Changes from all commits
c1267d7
1557529
02fdbf0
9158ca6
7c40e7d
0a9b989
1bfc65c
1613bc2
d055ca6
8ab95df
079db6b
b1ff612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
# | ||
from __future__ import unicode_literals | ||
import os | ||
import sys | ||
import time | ||
import json | ||
import string | ||
import requests | ||
import argparse | ||
import random | ||
from subprocess import Popen, PIPE | ||
import traceback | ||
import multiprocessing | ||
from decimal import Decimal, getcontext | ||
|
||
|
||
#creator = 'zhangshiqi12' | ||
#creator = sys.argv[1] | ||
#chain_id = sys.argv[4] | ||
def account_random(): | ||
seed = "12345abcdefghijklmnopqrstuvwxyz" | ||
sa = [] | ||
for i in range(12): | ||
sa.append(random.choice(seed)) | ||
res = ''.join(sa) | ||
return res | ||
|
||
#get info | ||
def get_info(chain_id): | ||
cmdline = "cleos get info" | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
param = json.loads(stdout) | ||
print('param:',param) | ||
if param['chain_id'] == chain_id: | ||
print(f'chain_id is right') | ||
return True | ||
else: | ||
print(f'chain_id is wrong') | ||
return False | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
return False | ||
|
||
#transfer | ||
def transfer(params): | ||
account1_balance1 = 0 | ||
account1_balance2 = 0 | ||
account2_balance1 = 0 | ||
account2_balance2 = 0 | ||
#创建一个账户 | ||
#newaccount = account_random() | ||
creator = params["creator"] | ||
newaccount = params["newaccount"] | ||
print('creator:',creator) | ||
print('new account :',newaccount) | ||
#cmdline = f'cleos system newaccount --stake-net \"5 EOS\" --stake-cpu \"5 EOS\" --buy-ram \"2 EOS\" {creator} {newaccount} ' | ||
#process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
#time.sleep(1) | ||
#cmdlinel = f"cleos get account {newaccount}" | ||
#process = Popen(cmdlinel, stdout=PIPE, stderr=PIPE,shell=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused code should be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newaccount 这个功能要不要测试呢?如果生成无用的帐号没什么意义。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 测试一下,可以用一个公知的私钥创建 |
||
#stdout, stderr = process.communicate() | ||
#if stdout: | ||
# print(f'{cmdline} =========================== ok') | ||
#if stderr: | ||
# print(f'{cmdline} =========================== fail') | ||
# print(stderr) | ||
|
||
#获取转账钱的=余额 | ||
cmdline = f"cleos get currency balance eosio.token {creator}" | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
print(f'{cmdline} =========================== ok') | ||
account1_balance1 = stdout | ||
print("account1_balance1 ==",account1_balance1) | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
|
||
cmdline = f"cleos get currency balance eosio.token {newaccount} " | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
print(f'{cmdline} =========================== ok') | ||
account2_balance1 = stdout | ||
print("account2_balance1 ==",account2_balance1) | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
#执行转账 | ||
cmdline2 = f'cleos transfer {creator} {newaccount} \"2.0000 EOS\" ' | ||
process = Popen(cmdline2, stdout=PIPE, stderr=PIPE,shell=True) | ||
|
||
time.sleep(3) | ||
#查看转账后的余额 | ||
cmdline = f"cleos get currency balance eosio.token {creator} " | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
account1_balance2 = stdout | ||
print("account1_balance1 ==",account1_balance2) | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
|
||
cmdline = f"cleos get currency balance eosio.token {newaccount}" | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
account2_balance2 = stdout | ||
print("account2_balance2 ==",account2_balance2) | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
#判断是否与预期相等 | ||
if (float(account1_balance1[:-4])- float(account1_balance2[:-4])) == (float(account2_balance2[:-4]) - float(account2_balance1[:-4])): | ||
print(f'{cmdline2} =========================== ok') | ||
else: | ||
print(f'{cmdline2} =========================== fail') | ||
|
||
#system contract | ||
def system_contract(params): | ||
#reprod | ||
newaccount= params["newaccount"] | ||
bppubkey = params["bppubkey"] | ||
cmdline = f"cleos system regproducer {newaccount} {bppubkey} https://www.xxx.com 900" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. xxx.com is what? |
||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
time.sleep(2) | ||
cmdline1 = "cleos get table eosio eosio producers -l 100" | ||
process = Popen(cmdline1, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
result = json.loads(stdout) | ||
pro = result['rows'] | ||
for i in pro: | ||
if i['owner'] == newaccount: | ||
print(f'{cmdline} =========================== ok') | ||
res = True | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
res = False | ||
|
||
cmdline = f"cleos system unregprod {newaccount}" | ||
process = Popen(cmdline, stdout=PIPE, stderr=PIPE,shell=True) | ||
time.sleep(2) | ||
cmdline1 = "cleos get table eosio eosio producers -l 100" | ||
process = Popen(cmdline1, stdout=PIPE, stderr=PIPE,shell=True) | ||
stdout, stderr = process.communicate() | ||
if stdout: | ||
result = json.loads(stdout) | ||
pro = result['rows'] | ||
for i in pro: | ||
if i['owner'] == newaccount: | ||
print(f'{cmdline} =========================== ok') | ||
res = True | ||
if stderr: | ||
print(f'{cmdline} =========================== fail') | ||
print(stderr) | ||
res = False | ||
return res | ||
|
||
def main(): | ||
if len(sys.argv)<1: | ||
print('ERROR:Please supply the param file') | ||
return False | ||
param_dict, param_str = None, '' | ||
with open(sys.argv[1], 'r') as fp: | ||
param_str = fp.read() | ||
param_dict = json.loads(param_str) | ||
if not param_dict: | ||
print('ERROR:param file can NOT be empty') | ||
return False | ||
print('Get params:', sys.argv[0], param_str) | ||
res = get_info(param_dict["chain_id"]) | ||
if not res: | ||
return False | ||
system_contract(param_dict) | ||
transfer(param_dict) | ||
return True | ||
|
||
if __name__ == '__main__': | ||
sys.exit( 0 if main() else 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after you have finished your code, please run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i used python3.6,because httpapi/ used python3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add
description
to describe the case of the script