forked from bitshares/python-bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wallet.py
More file actions
73 lines (66 loc) · 2.04 KB
/
test_wallet.py
File metadata and controls
73 lines (66 loc) · 2.04 KB
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
import unittest
from bitshares import storage
from bitshares.wallet import Wallet
from bitshares.exceptions import KeyNotFound
from bitsharesbase.account import PrivateKey
from .fixtures import fixture_data
class Testcases(unittest.TestCase):
def setUp(self):
fixture_data()
def test_init(self):
config = storage.InRamConfigurationStore()
key_store = storage.InRamPlainKeyStore(config=config)
wallet = Wallet(key_store=key_store)
# InRamStore does not come with a default key
self.assertFalse(wallet.created())
self.assertTrue(bool(wallet.rpc))
self.assertEqual(wallet.prefix, "BTS")
wif1 = PrivateKey()
wif2 = PrivateKey()
wallet.setKeys([
wif1, wif2
])
self.assertIn(
str(wif1.pubkey),
wallet.store.getPublicKeys()
)
self.assertIn(
str(wif2.pubkey),
wallet.store.getPublicKeys()
)
self.assertEqual(
wallet.getPrivateKeyForPublicKey(
wif1.pubkey
),
str(wif1)
)
self.assertEqual(
wallet.getPrivateKeyForPublicKey(
wif2.pubkey
),
str(wif2)
)
# wallet.unlock("")
# wallet.lock()
# is unlocked because InRamKeyStore and not encrypted
self.assertFalse(wallet.store.is_encrypted())
self.assertFalse(wallet.is_encrypted())
self.assertTrue(wallet.unlocked())
self.assertFalse(wallet.locked())
wif3 = PrivateKey()
wallet.addPrivateKey(wif3)
self.assertIn(
str(wif3.pubkey),
wallet.store.getPublicKeys()
)
self.assertEqual(
wallet.getPrivateKeyForPublicKey(
wif3.pubkey
),
str(wif3)
)
wallet.removePrivateKeyFromPublicKey(wif3.pubkey)
with self.assertRaises(KeyNotFound):
wallet.getPrivateKeyForPublicKey(
wif3.pubkey
)