Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 595b9ff

Browse files
authored
Release/0.0.4 (#7)
* fix mock exports * bump version * add changelog * fix release script * add more changelog
1 parent 588931c commit 595b9ff

File tree

7 files changed

+66
-55
lines changed

7 files changed

+66
-55
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.0.4 / 2023-07-11
4+
5+
## What's Changed
6+
* Oops, fix mock exports by @camfairchild in e43ed72
7+
* Fix release script version check by @camfairchild in 312f41c
8+
9+
10+
**Full Changelog**: https://github.com/opentensor/bittensor-wallet/compare/v0.0.3...v0.0.4
11+
12+
313
## 0.0.3 / 2023-07-06
414

515
## What's Changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# BittensorWallet - v0.0.3
1+
# BittensorWallet - v0.0.4
22

33
BittensorWallet is a library for managing wallet keypairs, keyfiles, etc. for the [Bittensor Python API](https://github.com/opentensor/bittensor).
44

@@ -7,7 +7,7 @@ The purpose of this repo is to separate the concern of keyfile management from t
77
# Installation
88
This package can be installed from [PyPi.org](https://pypi.org/project/bittensor-wallet/):
99
```bash
10-
pip install bittensor-wallet==0.0.3
10+
pip install bittensor-wallet==0.0.4
1111
```
1212
or via this repo (using [gh-cli](https://cli.github.com/)):
1313
```bash

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.3
1+
0.0.4

bittensor_wallet/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1818
# DEALINGS IN THE SOFTWARE.
1919

20-
__version__ = "0.0.3"
20+
__version__ = "0.0.4"
2121
__ss58_format__ = 42 # Bittensor ss58 format
2222

2323
import argparse

bittensor_wallet/mock/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1515
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1616
# DEALINGS IN THE SOFTWARE.
17+
18+
from .utils import get_mock_coldkey, get_mock_hotkey, get_mock_keypair, get_mock_wallet

scripts/release/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ ! -f $VERSION_FILENAME ]]; then
5252
exit 1
5353
fi
5454

55-
CODE_VERSION=`grep '__version__\ \=\ ' $CODE_WITH_VERSION | awk '{print $3}' | sed "s/'//g"`
55+
CODE_VERSION=`grep '__version__\ \=\ ' $CODE_WITH_VERSION | awk '{print $3}' | sed "s/'//g" | sed 's/"//g'`
5656
VERSION=$(cat $VERSION_FILENAME)
5757

5858
if ! [[ "$CODE_VERSION" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]];then

tests/test.py

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
from bittensor_wallet.wallet_impl import Wallet
2929
from bittensor_wallet._keyfile import Keyfile, keyfile
3030
from bittensor_wallet._keyfile.keyfile_impl import validate_password, ask_password_to_encrypt, decrypt_keyfile_data, KeyFileError
31+
from bittensor_wallet.mock import MockKeyfile, MockWallet
3132

3233
class TestWallet(unittest.TestCase):
3334

3435
def test_regen_coldkeypub_from_ss58_addr(self):
3536
ss58_address = "5DD26kC2kxajmwfbbZmVmxhrY9VeeyR1Gpzy9i8wxLUg6zxm"
36-
mock_wallet = Wallet()
37+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
3738
with patch.object(mock_wallet, 'set_coldkeypub') as mock_set_coldkeypub:
3839
mock_wallet.regenerate_coldkeypub( ss58_address=ss58_address )
3940

@@ -43,12 +44,12 @@ def test_regen_coldkeypub_from_ss58_addr(self):
4344

4445
ss58_address_bad = "5DD26kC2kxajmwfbbZmVmxhrY9VeeyR1Gpzy9i8wxLUg6zx" # 1 character short
4546
with pytest.raises(ValueError):
46-
self.mock_wallet.regenerate_coldkeypub(ss58_address=ss58_address_bad)
47+
mock_wallet.regenerate_coldkeypub(ss58_address=ss58_address_bad)
4748

4849
def test_regen_coldkeypub_from_hex_pubkey_str(self):
4950
pubkey_str = "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f"
5051

51-
mock_wallet = Wallet()
52+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
5253
with patch.object(mock_wallet, 'set_coldkeypub') as mock_set_coldkeypub:
5354
mock_wallet.regenerate_coldkeypub(public_key=pubkey_str)
5455

@@ -58,13 +59,13 @@ def test_regen_coldkeypub_from_hex_pubkey_str(self):
5859

5960
pubkey_str_bad = "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512" # 1 character short
6061
with pytest.raises(ValueError):
61-
self.mock_wallet.regenerate_coldkeypub(ss58_address=pubkey_str_bad)
62+
mock_wallet.regenerate_coldkeypub(ss58_address=pubkey_str_bad)
6263

6364
def test_regen_coldkeypub_from_hex_pubkey_bytes(self):
6465
pubkey_str = "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f"
6566
pubkey_bytes = bytes.fromhex(pubkey_str[2:]) # Remove 0x from beginning
6667

67-
mock_wallet = Wallet()
68+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
6869
with patch.object(mock_wallet, 'set_coldkeypub') as mock_set_coldkeypub:
6970
mock_wallet.regenerate_coldkeypub(public_key=pubkey_bytes)
7071

@@ -73,7 +74,7 @@ def test_regen_coldkeypub_from_hex_pubkey_bytes(self):
7374
self.assertEqual(keypair.public_key, pubkey_bytes)
7475

7576
def test_regen_coldkeypub_no_pubkey(self):
76-
mock_wallet = Wallet()
77+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
7778

7879
with pytest.raises(ValueError):
7980
# Must provide either public_key or ss58_address
@@ -83,7 +84,7 @@ def test_regen_coldkey_from_hex_seed_str(self):
8384
ss58_addr = "5D5cwd8DX6ij7nouVcoxDuWtJfiR1BnzCkiBVTt7DU8ft5Ta"
8485
seed_str = "0x659c024d5be809000d0d93fe378cfde020846150b01c49a201fc2a02041f7636"
8586

86-
mock_wallet = Wallet()
87+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
8788
with patch.object(mock_wallet, 'set_coldkey') as mock_set_coldkey:
8889
mock_wallet.regenerate_coldkey(seed=seed_str)
8990

@@ -100,8 +101,8 @@ def test_regen_hotkey_from_hex_seed_str(self):
100101
ss58_addr = "5D5cwd8DX6ij7nouVcoxDuWtJfiR1BnzCkiBVTt7DU8ft5Ta"
101102
seed_str = "0x659c024d5be809000d0d93fe378cfde020846150b01c49a201fc2a02041f7636"
102103

103-
mock_wallet = Wallet()
104-
with patch.object(self.mock_wallet, 'set_hotkey') as mock_set_hotkey:
104+
mock_wallet = MockWallet( name=f"mock", hotkey="mock_hk", path=f"/tmp/mock-wallet-{self.id()}" )
105+
with patch.object(mock_wallet, 'set_hotkey') as mock_set_hotkey:
105106
mock_wallet.regenerate_hotkey(seed=seed_str)
106107

107108
mock_set_hotkey.assert_called_once()
@@ -126,60 +127,60 @@ def tearDown(self) -> None:
126127
shutil.rmtree(self.root_path)
127128

128129
def create_keyfile(self):
129-
keyfile = keyfile(path=os.path.join(self.root_path, "keyfile"))
130+
_keyfile = keyfile(path=os.path.join(self.root_path, "keyfile"))
130131

131132
mnemonic = Keypair.generate_mnemonic(12)
132133
alice = Keypair.create_from_mnemonic(mnemonic)
133-
keyfile.set_keypair(alice, encrypt=True, overwrite=True, password='thisisafakepassword')
134+
_keyfile.set_keypair(alice, encrypt=True, overwrite=True, password='thisisafakepassword')
134135

135136
bob = Keypair.create_from_uri('/Bob')
136-
keyfile.set_keypair(bob, encrypt=True, overwrite=True, password='thisisafakepassword')
137+
_keyfile.set_keypair(bob, encrypt=True, overwrite=True, password='thisisafakepassword')
137138

138139
return keyfile
139140

140141
def test_create(self):
141-
keyfile = keyfile(path=os.path.join(self.root_path, "keyfile"))
142+
_keyfile = keyfile(path=os.path.join(self.root_path, "keyfile"))
142143

143144
mnemonic = Keypair.generate_mnemonic( 12 )
144145
alice = Keypair.create_from_mnemonic(mnemonic)
145-
keyfile.set_keypair(alice, encrypt=True, overwrite=True, password = 'thisisafakepassword')
146-
assert keyfile.is_readable()
147-
assert keyfile.is_writable()
148-
assert keyfile.is_encrypted()
149-
keyfile.decrypt( password = 'thisisafakepassword' )
150-
assert not keyfile.is_encrypted()
151-
keyfile.encrypt( password = 'thisisafakepassword' )
152-
assert keyfile.is_encrypted()
146+
_keyfile.set_keypair(alice, encrypt=True, overwrite=True, password = 'thisisafakepassword')
147+
assert _keyfile.is_readable()
148+
assert _keyfile.is_writable()
149+
assert _keyfile.is_encrypted()
150+
_keyfile.decrypt( password = 'thisisafakepassword' )
151+
assert not _keyfile.is_encrypted()
152+
_keyfile.encrypt( password = 'thisisafakepassword' )
153+
assert _keyfile.is_encrypted()
153154
str(keyfile)
154-
keyfile.decrypt( password = 'thisisafakepassword' )
155-
assert not keyfile.is_encrypted()
155+
_keyfile.decrypt( password = 'thisisafakepassword' )
156+
assert not _keyfile.is_encrypted()
156157
str(keyfile)
157158

158-
assert keyfile.get_keypair( password = 'thisisafakepassword' ).ss58_address == alice.ss58_address
159-
assert keyfile.get_keypair( password = 'thisisafakepassword' ).private_key == alice.private_key
160-
assert keyfile.get_keypair( password = 'thisisafakepassword' ).public_key == alice.public_key
159+
assert _keyfile.get_keypair( password = 'thisisafakepassword' ).ss58_address == alice.ss58_address
160+
assert _keyfile.get_keypair( password = 'thisisafakepassword' ).private_key == alice.private_key
161+
assert _keyfile.get_keypair( password = 'thisisafakepassword' ).public_key == alice.public_key
161162

162163
bob = Keypair.create_from_uri ('/Bob')
163-
keyfile.set_keypair(bob, encrypt=True, overwrite=True, password = 'thisisafakepassword')
164-
assert keyfile.get_keypair( password = 'thisisafakepassword' ).ss58_address == bob.ss58_address
165-
assert keyfile.get_keypair( password = 'thisisafakepassword' ).public_key == bob.public_key
164+
_keyfile.set_keypair(bob, encrypt=True, overwrite=True, password = 'thisisafakepassword')
165+
assert _keyfile.get_keypair( password = 'thisisafakepassword' ).ss58_address == bob.ss58_address
166+
assert _keyfile.get_keypair( password = 'thisisafakepassword' ).public_key == bob.public_key
166167

167168
repr(keyfile)
168169

169170
def test_legacy_coldkey(self):
170171
legacy_filename = os.path.join(self.root_path, "coldlegacy_keyfile")
171-
keyfile = keyfile (path = legacy_filename)
172-
keyfile.make_dirs()
172+
_keyfile = keyfile (path = legacy_filename)
173+
_keyfile.make_dirs()
173174
keyfile_data = b'0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f'
174175
with open(legacy_filename, "wb") as keyfile_obj:
175176
keyfile_obj.write( keyfile_data )
176-
assert keyfile.keyfile_data == keyfile_data
177-
keyfile.encrypt( password = 'this is the fake password' )
178-
keyfile.decrypt( password = 'this is the fake password' )
177+
assert _keyfile.keyfile_data == keyfile_data
178+
_keyfile.encrypt( password = 'this is the fake password' )
179+
_keyfile.decrypt( password = 'this is the fake password' )
179180
keypair_bytes = b'{"accountId": "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f", "publicKey": "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f", "secretPhrase": null, "secretSeed": null, "ss58Address": "5DD26kC2kxajmwfbbZmVmxhrY9VeeyR1Gpzy9i8wxLUg6zxm"}'
180-
assert keyfile.keyfile_data == keypair_bytes
181-
assert keyfile.get_keypair().ss58_address == "5DD26kC2kxajmwfbbZmVmxhrY9VeeyR1Gpzy9i8wxLUg6zxm"
182-
assert "0x" + keyfile.get_keypair().public_key.hex() == "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f"
181+
assert _keyfile.keyfile_data == keypair_bytes
182+
assert _keyfile.get_keypair().ss58_address == "5DD26kC2kxajmwfbbZmVmxhrY9VeeyR1Gpzy9i8wxLUg6zxm"
183+
assert "0x" + _keyfile.get_keypair().public_key.hex() == "0x32939b6abc4d81f02dff04d2b8d1d01cc8e71c5e4c7492e4fa6a238cdca3512f"
183184

184185
def test_validate_password(self):
185186
assert validate_password(None) == False
@@ -219,23 +220,21 @@ def test_user_interface(self):
219220
assert ask_password_to_encrypt() == 'asdury3294y'
220221

221222
def test_overwriting(self):
222-
keyfile = keyfile (path = os.path.join(self.root_path, "keyfile"))
223+
_keyfile = keyfile (path = os.path.join(self.root_path, "keyfile"))
223224
alice = Keypair.create_from_uri ('/Alice')
224-
keyfile.set_keypair(alice, encrypt=True, overwrite=True, password = 'thisisafakepassword')
225+
_keyfile.set_keypair(alice, encrypt=True, overwrite=True, password = 'thisisafakepassword')
225226
bob = Keypair.create_from_uri ('/Bob')
226227

227228
with pytest.raises(KeyFileError) as pytest_wrapped_e:
228229
with patch('builtins.input', return_value = 'n'):
229-
keyfile.set_keypair(bob, encrypt=True, overwrite=False, password = 'thisisafakepassword')
230+
_keyfile.set_keypair(bob, encrypt=True, overwrite=False, password = 'thisisafakepassword')
230231

231232
def test_keyfile_mock(self):
232-
file = keyfile( _mock = True )
233-
assert file.exists_on_device()
234-
assert not file.is_encrypted()
235-
assert file.is_readable()
236-
assert file.data
237-
assert file.keypair
238-
file.set_keypair( keypair = Keypair.create_from_mnemonic( mnemonic = Keypair.generate_mnemonic() ))
239-
240-
def test_keyfile_mock_func(self):
241-
file = keyfile.mock()
233+
with patch('bittensor_wallet._keyfile.keyfile.__new__', return_value=MockKeyfile(path='/tmp/test-wallet/keyfile')):
234+
file = keyfile( )
235+
assert file.exists_on_device()
236+
assert not file.is_encrypted()
237+
assert file.is_readable()
238+
assert file.data
239+
assert file.keypair
240+
file.set_keypair( keypair = Keypair.create_from_mnemonic( mnemonic = Keypair.generate_mnemonic() ))

0 commit comments

Comments
 (0)