-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
99 lines (87 loc) · 3.8 KB
/
conftest.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from modules import *
def pytest_addoption(parser):
parser.addoption("--chain", action="store",default="dextestchain",help="option to specify chain")
parser.addoption("--notcheckrte", action="store_true",help="option to disable the assert for rte")
@pytest.fixture(scope='session')
def INSTANCE(pytestconfig):
chainName = pytestconfig.getoption('chain')
chainId = CFG[chainName]['chain_id']
chainNodeUrl = CFG[chainName]['node_url']
if chainId != '90be01e82b981c8f201c9a78a3d31f655743b29ff3274727b1439b093d04aa23':
cybex.cybex.cybex_debug_config(chainId)
instance = cybex.cybex.Cybex(node = chainNodeUrl)
instance.const = dict(CFG[chainName])
instance.chain = dict(CFG[chainName])
instance.notcheckrte = pytestconfig.getoption('notcheckrte')
fees = instance.rpc.get_global_properties([])['parameters']['current_fees']['parameters']
ops = cybex.cybex.intercept_bitshares.cybex_ops
instance.fee = [{'id': fees[i][0], 'op': ops[i], 'fee': fees[i][1]} for i in range(len(ops))]
logging.info(instance.const)
return instance
@pytest.fixture(autouse=True, scope='session')
def initialize(INSTANCE):
# if INSTANCE.const['chain_id'] != '90be01e82b981c8f201c9a78a3d31f655743b29ff3274727b1439b093d04aa23':
# cybex.cybex.cybex_debug_config(INSTANCE.const['chain_id'])
if sys.platform == 'darwin':
sqlite_path = os.path.join(os.environ['HOME'], 'Library/Application Support/bitshares/')
else:
sqlite_path = os.path.join(os.environ['HOME'], '.local/share/bitshares/')
def backup_wallet():
""" constructing a wallet will backup old wallet sqlite file
"""
if os.path.exists(sqlite_path):
backup_path = os.path.join(os.getcwd(), '.backup')
try:
os.remove(os.path.join(backup_path, 'bitshares.sqlite'))
shutil.move(os.path.join(sqlite_path, 'bitshares.sqlite'),
backup_path)
except:
pass
def restore_wallet():
""" Restore wallet sqlite file from tmp directory
"""
try:
os.remove(os.path.join(sqlite_path, 'bitshares.sqlite'))
except:
pass
backup_path = os.path.join(os.getcwd(), '.backup')
if os.path.exists(os.path.join(backup_path, 'bitshares.sqlite')):
shutil.move(
os.path.join(
backup_path, 'bitshares.sqlite'),
sqlite_path)
backup_wallet()
if not INSTANCE.wallet.created():
INSTANCE.wallet.create(CFG['wallet']['test_wallet_pwd'])
if INSTANCE.wallet.locked():
INSTANCE.wallet.unlock(CFG['wallet']['test_wallet_pwd'])
yield
restore_wallet()
@pytest.fixture(scope='function')
def market(INSTANCE, data4market):
cancel_all(INSTANCE, [data4market['alice']['account'], data4market['bob']['account']])
yield
cancel_all(INSTANCE, [data4market['alice']['account'], data4market['bob']['account']])
@pytest.fixture(scope='module')
def data4market(INSTANCE):
# logging.info(debug_data())
data = create_data(INSTANCE)
# data = debug_data()
add_private_key(INSTANCE,[data['alice']['active']['wif_priv_key'],data['bob']['active']['wif_priv_key']])
logging.info("add private key in wallet for alice and bob")
return data
@pytest.fixture(scope='module')
def data4cybexop(INSTANCE):
# logging.info(debug_data())
data = create_data(INSTANCE)
# data = debug_data()
add_private_key(INSTANCE,[data['alice']['active']['wif_priv_key'],data['bob']['active']['wif_priv_key']])
logging.info("add private key in wallet for alice and bob")
return data
@pytest.fixture(scope='function')
def cleartxpool(INSTANCE):
INSTANCE.clear()
# reset_wallet(INSTANCE)
yield
INSTANCE.clear()
# reset_wallet(INSTANCE)