-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_wallet.py
89 lines (78 loc) · 3.34 KB
/
test_wallet.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
from modules import *
def test_create(INSTANCE, cleartxpool):
reset_wallet(INSTANCE)
logging.info('test create wallet')
if sys.platform == 'darwin':
assert os.path.exists(os.path.join(os.environ['HOME'],'Library/Application Support/bitshares/'))
else:
assert os.path.exists(os.path.join(os.environ['HOME'],'.local/share/bitshares/bitshares.sqlite'))
assert INSTANCE.wallet.created()
def test_getAccounts(INSTANCE, cleartxpool):
reset_wallet(INSTANCE)
logging.info('test get accounts from wallet')
account = create_accounts(INSTANCE)[0]
name = account['account']
logging.info("account %s has been created", name)
activeKey = account['active']['wif_priv_key']
before = len(INSTANCE.wallet.getAccounts())
INSTANCE.wallet.addPrivateKey(activeKey)
after = len(INSTANCE.wallet.getAccounts())
assert after > before
allAccounts = INSTANCE.wallet.getAccounts()
check = False
for element in allAccounts:
if name == element['name']:
check = True
break
assert check
def test_lock(INSTANCE, cleartxpool):
logging.info('test lock wallet')
INSTANCE.wallet.lock()
assert INSTANCE.wallet.locked()
def test_unlock(INSTANCE, cleartxpool):
logging.info('test unlock wallet')
INSTANCE.wallet.unlock(CFG['wallet']['test_wallet_pwd'])
assert not INSTANCE.wallet.locked()
def test_changePassphrase(INSTANCE, cleartxpool):
logging.info('test change wallet phase')
INSTANCE.wallet.unlock(CFG['wallet']['test_wallet_pwd'])
INSTANCE.wallet.changePassphrase('654321')
INSTANCE.wallet.lock()
INSTANCE.wallet.unlock('654321')
assert not INSTANCE.wallet.locked()
INSTANCE.wallet.changePassphrase(CFG['wallet']['test_wallet_pwd'])
def test_getAccount(INSTANCE, cleartxpool):
logging.info('test get account from wallet')
reset_wallet(INSTANCE)
account = create_accounts(INSTANCE)[0]
name = account['account']
logging.info("account %s has been created", name)
activeKey = account['active']['wif_priv_key']
INSTANCE.wallet.addPrivateKey(activeKey)
pubKey = account['active']['pub_key']
acc = INSTANCE.wallet.getAccount(pubKey)
assert isinstance(acc, dict)
assert acc['name'] == name
def test_getActiveKeyForAccount(INSTANCE, cleartxpool):
logging.info('test add private key')
reset_wallet(INSTANCE)
account = create_accounts(INSTANCE)[0]
name = account['account']
logging.info("account %s has been created", name)
activeKey = account['active']['wif_priv_key']
INSTANCE.wallet.addPrivateKey(activeKey)
assert INSTANCE.wallet.getActiveKeyForAccount(name) == activeKey
def test_getPrivateKeyForPublicKey(INSTANCE, cleartxpool):
logging.info('test get private key from publick key')
reset_wallet(INSTANCE)
account = create_accounts(INSTANCE)[0]
name = account['account']
logging.info("account %s has been created", name)
activeKey = account['active']['wif_priv_key']
pubKey = account['active']['pub_key']
INSTANCE.wallet.addPrivateKey(activeKey)
assert INSTANCE.wallet.getPrivateKeyForPublicKey(pubKey) == activeKey
def test_encrypt_decrypt(INSTANCE, cleartxpool):
logging.info('test decrypt')
wif = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'
assert INSTANCE.wallet.decrypt_wif(INSTANCE.wallet.encrypt_wif(wif)) == wif