Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Collection of EOSIO function testcase scripts from the community.

Main functionatily of this project is to test the function of the eosio-mainnet conveniently.

We choose to use **Python3** for future.
We choose to use **Python3.6** for future.

[点击查看中文](README_CN.md)

Expand Down Expand Up @@ -48,7 +48,7 @@ Steps:
3. run startmoster.py

```
python3 ./startmoster.py
python3.6 ./startmoster.py
```

![image](./image/startmonster.png)
Expand Down
20 changes: 20 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@ startmonster.py 会循环调用,并把 common_params 和 testcase指定的para
3. 运行startmoster.py

![image](./image/startmonster.png)

1.新增的测试用例,需要修改成自己的内容,creator 表示转账发起者,newaccount表示转账接收者和注册bp的账户,bppubkey表示注册bp的公钥
```
{
"casename": "Testcase 01_get_request",
"pre_call": "echo 'This is called BEFORE cmdline call'",
"post_call": "echo 'This is called AFTER cmdline call'",
"stoponfail": "true",
Copy link
Collaborator

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

"cmdline": "python3.6 testcases/01_get_request.py",
"params": {
"demo_param1": "demo_param1",
"demo_param2": 100,
"creator": "zhangshiqi12",
"newaccount":"zhangshiqi11",
"bppubkey":"EOS8HrnMdHbgrchNFtV9ySE4uwCSnoix4f3JZnJcw9ryyydg2DSup"
}
}
```


15 changes: 14 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
"demo_param1": "demo_param1",
"demo_param2": 100
}
},
{
"casename": "Testcase 01_get_request",
"pre_call": "echo 'This is called BEFORE system_test call'",
"post_call": "echo 'This is called AFTER system_test call'",
"stoponfail": "true",
"cmdline": "python3.6 testcases/01_get_request.py",
"params": {
"creator": "zhangshiqi12",
"newaccount":"zhangshiqi11",
"bppubkey":"EOS8HrnMdHbgrchNFtV9ySE4uwCSnoix4f3JZnJcw9ryyydg2DSup",
"chain_id":"5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191"
}
}
]
}
}
188 changes: 188 additions & 0 deletions testcases/01_get_request.py
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused code should be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newaccount 这个功能要不要测试呢?如果生成无用的帐号没什么意义。

Copy link
Collaborator

Choose a reason for hiding this comment

The 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"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after you have finished your code, please run python3 startmonster.py to check the script works well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used python3.6,because httpapi/ used python3.6