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

Commit

Permalink
Release/0.0.2 (#4)
Browse files Browse the repository at this point in the history
* Fix packaging (#1)

* use find packages

* bump version

* add test mocks to package

* bump version

* gsed -> sed

* fix scripts

* add mock utils

* add changelog notes
  • Loading branch information
camfairchild authored Jul 5, 2023
1 parent 14c89ec commit 27b0554
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.0.2 / 2023-07-05

## What's Changed
* Add mock module to package by @camfairchild in 60eec82d
* Fix packaging by @camfairchild in https://github.com/opentensor/bittensor-wallet/pull/1


**Full Changelog**: https://github.com/opentensor/bittensor-wallet/compare/v0.0.0...v0.0.2


## 0.0.1 / 2023-06-27

## What's Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BittensorWallet - v0.0.1
# BittensorWallet - v0.0.2

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

Expand All @@ -7,7 +7,7 @@ The purpose of this repo is to separate the concern of keyfile management from t
# Installation
This package can be installed from [PyPi.org](https://pypi.org/project/bittensor-wallet/):
```bash
pip install bittensor-wallet==0.0.1
pip install bittensor-wallet==0.0.2
```
or via this repo (using [gh-cli](https://cli.github.com/)):
```bash
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.1
v0.0.2
2 changes: 1 addition & 1 deletion bittensor_wallet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

__version__ = "0.0.1"
__version__ = "0.0.2"
__ss58_format__ = 42 # Bittensor ss58 format

import argparse
Expand Down
19 changes: 19 additions & 0 deletions bittensor_wallet/mock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Technologies

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from .wallet_mock import MockWallet as MockWallet
from .keyfile_mock import MockKeyfile as MockKeyfile
82 changes: 82 additions & 0 deletions bittensor_wallet/mock/keyfile_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# The MIT License (MIT)

# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from bittensor_wallet import serialized_keypair_to_keyfile_data, Keyfile
from bittensor_wallet import Keypair

class MockKeyfile( Keyfile ):
""" Defines an interface to a mocked keyfile object (nothing is created on device) keypair is treated as non encrypted and the data is just the string version.
"""
def __init__( self, path: str ):
super().__init__( path )

self._mock_keypair = Keypair.create_from_mnemonic( mnemonic = 'arrive produce someone view end scout bargain coil slight festival excess struggle' )
self._mock_data = serialized_keypair_to_keyfile_data( self._mock_keypair )

def __str__(self):
if not self.exists_on_device():
return "Keyfile (empty, {})>".format( self.path )
if self.is_encrypted():
return "Keyfile (encrypted, {})>".format( self.path )
else:
return "Keyfile (decrypted, {})>".format( self.path )

def __repr__(self):
return self.__str__()

@property
def keypair( self ) -> 'Keypair':
return self._mock_keypair

@property
def data( self ) -> bytes:
return bytes(self._mock_data)

@property
def keyfile_data( self ) -> bytes:
return bytes( self._mock_data)

def set_keypair ( self, keypair: 'Keypair', encrypt: bool = True, overwrite: bool = False, password:str = None):
self._mock_keypair = keypair
self._mock_data = serialized_keypair_to_keyfile_data( self._mock_keypair )

def get_keypair(self, password: str = None) -> 'Keypair':
return self._mock_keypair

def make_dirs( self ):
return

def exists_on_device( self ) -> bool:
return True

def is_readable( self ) -> bool:
return True

def is_writable( self ) -> bool:
return True

def is_encrypted ( self ) -> bool:
return False

def encrypt( self, password: str = None):
raise ValueError('Cannot encrypt a mock keyfile')

def decrypt( self, password: str = None):
return
16 changes: 16 additions & 0 deletions bittensor_wallet/mock/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Technologies

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
47 changes: 47 additions & 0 deletions bittensor_wallet/mock/utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Optional

from Crypto.Hash import keccak


from bittensor_wallet import __ss58_format__

from .. import MockWallet
from ...keypair_impl import Keypair


def get_mock_wallet(coldkey: "Keypair" = None, hotkey: "Keypair" = None):
wallet = MockWallet(
name = 'mock_wallet',
hotkey = 'mock',
path = '/tmp/mock_wallet',
)

if not coldkey:
coldkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
if not hotkey:
hotkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())

wallet.set_coldkey(coldkey, encrypt=False, overwrite=True)
wallet.set_coldkeypub(coldkey, encrypt=False, overwrite=True)
wallet.set_hotkey(hotkey, encrypt=False, overwrite=True)

return wallet

def get_mock_keypair( uid: int, test_name: Optional[str] = None ) -> Keypair:
"""
Returns a mock keypair from a uid and optional test_name.
If test_name is not provided, the uid is the only seed.
If test_name is provided, the uid is hashed with the test_name to create a unique seed for the test.
"""
if test_name is not None:
hashed_test_name: bytes = keccak.new(digest_bits=256, data=test_name.encode('utf-8')).digest()
hashed_test_name_as_int: int = int.from_bytes(hashed_test_name, byteorder='big', signed=False)
uid = uid + hashed_test_name_as_int

return Keypair.create_from_seed( seed_hex = int.to_bytes(uid, 32, 'big', signed=False), ss58_format = __ss58_format__)

def get_mock_hotkey( uid: int ) -> str:
return get_mock_keypair(uid).ss58_address

def get_mock_coldkey( uid: int ) -> str:
return get_mock_keypair(uid).ss58_address
79 changes: 79 additions & 0 deletions bittensor_wallet/mock/wallet_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# The MIT License (MIT)

# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import os
import bittensor
import bittensor_wallet

from .keyfile_mock import MockKeyfile

class MockWallet(bittensor_wallet.Wallet):
"""
Mocked Version of the bittensor wallet class, meant to be used for testing
"""
def __init__(
self,
**kwargs,
):
r""" Init bittensor wallet object containing a hot and coldkey.
Args:
_mock (required=True, default=False):
If true creates a mock wallet with random keys.
"""
super().__init__(**kwargs)
# For mocking.
self._is_mock = True
self._mocked_coldkey_keyfile = None
self._mocked_hotkey_keyfile = None

print("---- MOCKED WALLET INITIALIZED- ---")

@property
def hotkey_file(self) -> 'bittensor_wallet.Keyfile':
if self._is_mock:
if self._mocked_hotkey_keyfile == None:
self._mocked_hotkey_keyfile = MockKeyfile(path='MockedHotkey')
return self._mocked_hotkey_keyfile
else:
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
hotkey_path = os.path.join(wallet_path, "hotkeys", self.hotkey_str)
return bittensor.keyfile( path = hotkey_path )

@property
def coldkey_file(self) -> 'bittensor_wallet.Keyfile':
if self._is_mock:
if self._mocked_coldkey_keyfile == None:
self._mocked_coldkey_keyfile = MockKeyfile(path='MockedColdkey')
return self._mocked_coldkey_keyfile
else:
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
coldkey_path = os.path.join(wallet_path, "coldkey")
return bittensor.keyfile( path = coldkey_path )

@property
def coldkeypub_file(self) -> 'bittensor_wallet.Keyfile':
if self._is_mock:
if self._mocked_coldkey_keyfile == None:
self._mocked_coldkey_keyfile = MockKeyfile(path='MockedColdkeyPub')
return self._mocked_coldkey_keyfile
else:
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
coldkeypub_path = os.path.join(wallet_path, "coldkeypub.txt")
return bittensor_wallet.Keyfile( path = coldkeypub_path )
18 changes: 14 additions & 4 deletions scripts/release/add_notes_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ while [[ $# -gt 0 ]]; do
shift # past argument
shift # past value
;;
-B|--release-branch)
RELEASE_BRANCH="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
Expand All @@ -59,6 +64,11 @@ if [[ -z $VERSION ]]; then
exit 1
fi

if [[ -z $RELEASE_BRANCH ]]; then
echo_warning "Release branch not specified with (-B, --release-branch) assuming: release/$VERSION"
RELEASE_BRANCH=release/$VERSION
fi

DATE=$(date +"%Y-%m-%d")
RELEASE_NAME="$VERSION / $DATE"
TAG_NAME=v$VERSION
Expand All @@ -67,8 +77,8 @@ PREV_TAG_NAME=v$PREV_TAG_VERSION
# 2.2. Generate release notes
if [[ $APPLY == "true" ]]; then
echo_info "Generating Github release notes"
RESPONSE=$(generate_github_release_notes $GITHUB_TOKEN)
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | gsed "s/\"//g")
RESPONSE=$(generate_github_release_notes_for_changelog $GITHUB_TOKEN)
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | sed "s/\"//g")

if [ $(echo $RESPONSE | jq '.body' | wc -l) -eq 1 ]; then
if [ $(echo $RESPONSE | jq '.' | grep 'documentation_url' | wc -l) -gt 0 ]; then
Expand All @@ -89,8 +99,8 @@ fi

if [[ $APPLY == "true" ]]; then
echo_info "Adding release notes to CHANGELOG.md"
gsed -i "2 i\\\n## $RELEASE_NAME" CHANGELOG.md
gsed -i "4 i\\\n$DESCRIPTION\n" CHANGELOG.md
sed -i "2 i\\\n## $RELEASE_NAME" CHANGELOG.md
sed -i "4 i\\\n$DESCRIPTION\n" CHANGELOG.md
else
echo_warning "Dry run execution. Not adding release notes to CHANGELOG.md"
fi
2 changes: 1 addition & 1 deletion scripts/release/github_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fi
if [[ $APPLY == "true" ]]; then
echo_info "Generating Github release notes"
RESPONSE=$(generate_github_release_notes $GITHUB_TOKEN)
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | gsed "s/\"//g")
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | sed "s/\"//g")

if [ $(echo $RESPONSE | jq '.body' | wc -l) -eq 1 ]; then
if [ $(echo $RESPONSE | jq '.' | grep 'documentation_url' | wc -l) -gt 0 ]; then
Expand Down
Loading

0 comments on commit 27b0554

Please sign in to comment.