Skip to content

Commit

Permalink
Merge branch 'release/v0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Nov 26, 2018
2 parents d9d28f6 + 9fbfd57 commit c20251d
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
before_install:
- pip install poetry
install:
- poetry develop
- poetry install

script:
- flake8 .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you are using macOS, make sure that the user python3 path is in your `$PATH`.

They are in `~/Library/Python/[python version number]/bin`.

For example, with python `3.6` and `bash`, add `PATH=$PATH:~/Library/Python/3.6/bin` to your `~/.bashrc`.
For example, with python `3.6` and `bash`, add `PATH=$PATH:$HOME/Library/Python/3.6/bin` to your `$HOME/.bashrc`.

## Update

Expand Down
208 changes: 154 additions & 54 deletions pyproject.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tmn"
version = "0.2.5"
version = "0.3.0"
description = "Quickstart your masternode"
readme = "README.md"
license = "GPL-3.0+"
Expand All @@ -19,6 +19,8 @@ pastel = "^0.1.0"
clint = "^0.5.1"
python-slugify = "^1.2"
click = "^7.0"
eth-keys = "^0.1.0-beta.1"
eth-hash = {version = "^0.2.0", extras = ["pycryptodome"]}

[tool.poetry.dev-dependencies]

Expand Down
29 changes: 28 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _clean(tmn):


def test_version(runner, tmn):
version = '0.2.5'
version = '0.3.0'
result = runner.invoke(tmn.main, ['--version'])
assert result.output[-6:-1] == version
assert package.__version__ == version
Expand Down Expand Up @@ -116,6 +116,19 @@ def test_command_start_init_testnet(runner, tmn):
_clean(tmn)


def test_command_start_init_mainnet(runner, tmn):
result = runner.invoke(tmn.main, [
'start', '--name', 'test1', '--net',
'mainnet', '--pkey',
'0123456789012345678901234567890123456789012345678901234567890123'
])
lines = result.output.splitlines()
assert 'Starting masternode test1:' in lines
for line in lines:
assert '✗' not in line
_clean(tmn)


def test_command_start_init_invalid_name(runner, tmn):
result = runner.invoke(tmn.main, [
'start', '--name', 'tes', '--net', 'devnet', '--pkey', '1234'])
Expand Down Expand Up @@ -238,3 +251,17 @@ def test_command_update(runner, tmn):
for line in lines:
assert '✗' not in line
_clean(tmn)


def test_command_remove(runner, tmn):
runner.invoke(tmn.main, [
'start', '--name', 'test1', '--net',
'devnet', '--pkey',
'0123456789012345678901234567890123456789012345678901234567890123'
])
result = runner.invoke(tmn.main, ['remove', '--confirm'])
lines = result.output.splitlines()
assert 'Removing masternode test1:' in lines
for line in lines:
assert '✗' not in line
_clean(tmn)
2 changes: 1 addition & 1 deletion tmn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

__version__ = '0.2.5'
__version__ = '0.3.0'

handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
Expand Down
28 changes: 20 additions & 8 deletions tmn/configuration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import sys
import uuid

import docker
from clint import resources
from eth_keys import keys
from slugify import slugify
import docker

from tmn import display
from tmn.elements.network import Network
Expand Down Expand Up @@ -49,8 +49,9 @@ def __init__(self, name: str = None, net: str = None,
sys.exit('\n')
self._compose()

def _new_id(self) -> str:
return uuid.uuid4().hex[:6]
def _get_address(self) -> str:
pk = keys.PrivateKey(bytes.fromhex(self.pkey))
return pk.public_key.to_address()[2:]

def _load(self) -> None:
if self.name or self.net or self.pkey:
Expand Down Expand Up @@ -81,7 +82,7 @@ def _write(self) -> None:
display.error_start_option_required('--pkey')
sys.exit('\n')
self._validate()
self.id = self._new_id()
self.id = self._get_address()
resources.user.write('id', self.id)
resources.user.write('name', self.name)
resources.user.write('net', self.net)
Expand All @@ -95,10 +96,15 @@ def _compose(self) -> None:
name='{}_chaindata'.format(self.name),
client=self.client
)
tag = 'testnet' if self.net == 'testnet' else 'latest'
if self.net == 'mainnet':
tag = 'stable'
elif self.net == 'testnet':
tag = 'testnet'
else:
tag = 'latest'
self.services['metrics'] = Service(
name='{}_metrics'.format(self.name),
hostname='{}_{}'.format(self.name, self.id),
hostname='{}'.format(self.id),
image='tomochain/telegraf:{}'.format(tag),
network=self.networks['tmn'].name,
volumes={
Expand All @@ -116,7 +122,7 @@ def _compose(self) -> None:
image='tomochain/node:{}'.format(tag),
network=self.networks['tmn'].name,
environment={
'IDENTITY': '{}_{}'.format(self.name, self.id),
'IDENTITY': '{}'.format(self.name),
'PRIVATE_KEY': '{}'.format(self.pkey)
},
volumes={
Expand Down Expand Up @@ -144,6 +150,12 @@ def _validate(self) -> None:
display.error_validation_option('--pkey', '64 characters hex '
'string')
sys.exit('\n')
try:
bytes.fromhex(self.pkey)
except ValueError:
display.error_validation_option('--pkey', '64 characters hex '
'string')
sys.exit('\n')

def remove(self) -> None:
resources.user.delete('id')
Expand Down
23 changes: 23 additions & 0 deletions tmn/environments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
environments = {
'mainnet': {
'tomochain': {
'BOOTNODES': (
'enode://97f0ca95a653e3c44d5df2674e19e9324ea4bf4d47a46b1d8560f'
'3ed4ea328f725acec3fcfcb37eb11706cf07da669e9688b091f1543f89b24'
'25700a68bc8876@104.248.98.78:30301,enode://b72927f349f3a27b78'
'9d0ca615ffe3526f361665b496c80e7cc19dace78bd94785fdadc270054ab'
'727dbb172d9e3113694600dd31b2558dd77ad85a869032dea@188.166.207'
'.189:30301,enode://c8f2f0643527d4efffb8cb10ef9b6da4310c5ac9f2'
'e988a7f85363e81d42f1793f64a9aa127dbaff56b1e8011f90fe9ff57fa02'
'a36f73220da5ff81d8b8df351@104.248.98.60:30301'
),
'NETSTATS_HOST': 'stats.tomochain.com',
'NETSTATS_PORT': '443',
'NETWORK_ID': '88',
'WS_SECRET': (
'getty-site-pablo-auger-room-sos-blair-shin-whiz-delhi'
)
},
'metrics': {
'METRICS_ENDPOINT': 'https://metrics.tomochain.com'
}
},
'testnet': {
'tomochain': {
'BOOTNODES': (
Expand Down
2 changes: 1 addition & 1 deletion tmn/tmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def docs() -> None:

@click.command(help='Start your TomoChain masternode')
@click.option('--name', metavar='NAME', help='Your masternode\'s name')
@click.option('--net', type=click.Choice(['testnet', 'devnet']),
@click.option('--net', type=click.Choice(['mainnet', 'testnet', 'devnet']),
help='The environment your masternode will connect to')
@click.option('--pkey', metavar='KEY', help=('Private key of the account your '
'masternode will collect rewards '
Expand Down

0 comments on commit c20251d

Please sign in to comment.