mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
blackified python files
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
5d63e2945a
commit
58977b5280
@ -81,7 +81,6 @@ def zenroom_script_input():
|
|||||||
return SCRIPT_INPUT
|
return SCRIPT_INPUT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def zenroom_data():
|
def zenroom_data():
|
||||||
return ZENROOM_DATA
|
return ZENROOM_DATA
|
||||||
|
|||||||
@ -38,25 +38,33 @@ def test_zenroom_signing(
|
|||||||
zenroomscpt = ZenroomSha256(script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys)
|
zenroomscpt = ZenroomSha256(script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys)
|
||||||
print(f"zenroom is: {zenroomscpt.script}")
|
print(f"zenroom is: {zenroomscpt.script}")
|
||||||
|
|
||||||
def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
|
||||||
fulfill_script_zencode, zenroom_data, zenroom_house_assets,
|
def test_zenroom_signing(
|
||||||
condition_script_zencode):
|
gen_key_zencode,
|
||||||
|
secret_key_to_private_key_zencode,
|
||||||
|
fulfill_script_zencode,
|
||||||
|
zenroom_data,
|
||||||
|
zenroom_house_assets,
|
||||||
|
condition_script_zencode,
|
||||||
|
):
|
||||||
|
|
||||||
biolabs = generate_keypair()
|
biolabs = generate_keypair()
|
||||||
version = '2.0'
|
version = "2.0"
|
||||||
|
|
||||||
alice = json.loads(zencode_exec(gen_key_zencode).output)['keyring']
|
|
||||||
bob = json.loads(zencode_exec(gen_key_zencode).output)['keyring']
|
|
||||||
|
|
||||||
zen_public_keys = json.loads(zencode_exec(secret_key_to_private_key_zencode.format('Alice'),
|
|
||||||
keys=json.dumps({'keyring': alice})).output)
|
|
||||||
zen_public_keys.update(json.loads(zencode_exec(secret_key_to_private_key_zencode.format('Bob'),
|
|
||||||
keys=json.dumps({'keyring': bob})).output))
|
|
||||||
|
|
||||||
|
alice = json.loads(zencode_exec(gen_key_zencode).output)["keyring"]
|
||||||
|
bob = json.loads(zencode_exec(gen_key_zencode).output)["keyring"]
|
||||||
|
|
||||||
|
zen_public_keys = json.loads(
|
||||||
|
zencode_exec(secret_key_to_private_key_zencode.format("Alice"), keys=json.dumps({"keyring": alice})).output
|
||||||
|
)
|
||||||
|
zen_public_keys.update(
|
||||||
|
json.loads(
|
||||||
|
zencode_exec(secret_key_to_private_key_zencode.format("Bob"), keys=json.dumps({"keyring": bob})).output
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
zenroomscpt = ZenroomSha256(script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys)
|
zenroomscpt = ZenroomSha256(script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys)
|
||||||
print(F'zenroom is: {zenroomscpt.script}')
|
print(f"zenroom is: {zenroomscpt.script}")
|
||||||
|
|
||||||
# CRYPTO-CONDITIONS: generate the condition uri
|
# CRYPTO-CONDITIONS: generate the condition uri
|
||||||
condition_uri_zen = zenroomscpt.condition.serialize_uri()
|
condition_uri_zen = zenroomscpt.condition.serialize_uri()
|
||||||
@ -93,11 +101,7 @@ def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
|||||||
"output": ["ok"],
|
"output": ["ok"],
|
||||||
"policies": {},
|
"policies": {},
|
||||||
}
|
}
|
||||||
metadata = {
|
metadata = {"result": {"output": ["ok"]}}
|
||||||
"result": {
|
|
||||||
"output": ["ok"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
token_creation_tx = {
|
token_creation_tx = {
|
||||||
"operation": "CREATE",
|
"operation": "CREATE",
|
||||||
|
|||||||
@ -42,7 +42,7 @@ This Code of Conduct applies both within project spaces and in public spaces
|
|||||||
when an individual is representing the project or its community.
|
when an individual is representing the project or its community.
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior directed at yourself or another community member may be
|
Instances of abusive, harassing, or otherwise unacceptable behavior directed at yourself or another community member may be
|
||||||
reported by contacting a project maintainer at [mail@planetmint.io](mailto:mail@planetmint.io). All
|
reported by contacting a project maintainer at [mail@planetmint.io](mailto:contact@planetmint.io). All
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
is appropriate to the circumstances. Maintainers are
|
is appropriate to the circumstances. Maintainers are
|
||||||
obligated to maintain confidentiality with regard to the reporter of an
|
obligated to maintain confidentiality with regard to the reporter of an
|
||||||
|
|||||||
@ -20,11 +20,13 @@ BACKENDS = {
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _kwargs_parser(key, kwargs):
|
def _kwargs_parser(key, kwargs):
|
||||||
if kwargs.get(key):
|
if kwargs.get(key):
|
||||||
return kwargs[key]
|
return kwargs[key]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class DBSingleton(type):
|
class DBSingleton(type):
|
||||||
_instances = {}
|
_instances = {}
|
||||||
|
|
||||||
@ -39,24 +41,34 @@ class DBSingleton(type):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logger.info("Backend {} not supported".format(backend))
|
logger.info("Backend {} not supported".format(backend))
|
||||||
raise ConfigurationError
|
raise ConfigurationError
|
||||||
modulepath, _, class_name = BACKENDS[backend].rpartition('.')
|
modulepath, _, class_name = BACKENDS[backend].rpartition(".")
|
||||||
Class = getattr(import_module(modulepath), class_name)
|
Class = getattr(import_module(modulepath), class_name)
|
||||||
cls._instances[cls] = super(DBSingleton, Class).__call__(*args, **kwargs)
|
cls._instances[cls] = super(DBSingleton, Class).__call__(*args, **kwargs)
|
||||||
return cls._instances[cls]
|
return cls._instances[cls]
|
||||||
|
|
||||||
class Connection(metaclass=DBSingleton):
|
|
||||||
|
|
||||||
|
class Connection(metaclass=DBSingleton):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DBConnection(metaclass=DBSingleton):
|
class DBConnection(metaclass=DBSingleton):
|
||||||
"""Connection class interface.
|
"""Connection class interface.
|
||||||
All backend implementations should provide a connection class that inherits
|
All backend implementations should provide a connection class that inherits
|
||||||
from and implements this class.
|
from and implements this class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host: str =None, port: int = None, login: str = None, password: str = None, backend: str = None,
|
def __init__(
|
||||||
connection_timeout: int = None, max_tries: int = None, **kwargs):
|
self,
|
||||||
|
host: str = None,
|
||||||
|
port: int = None,
|
||||||
|
login: str = None,
|
||||||
|
password: str = None,
|
||||||
|
backend: str = None,
|
||||||
|
connection_timeout: int = None,
|
||||||
|
max_tries: int = None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
"""Create a new :class:`~.Connection` instance.
|
"""Create a new :class:`~.Connection` instance.
|
||||||
Args:
|
Args:
|
||||||
host (str): the host to connect to.
|
host (str): the host to connect to.
|
||||||
@ -70,15 +82,15 @@ class DBConnection(metaclass=DBSingleton):
|
|||||||
**kwargs: arbitrary keyword arguments provided by the
|
**kwargs: arbitrary keyword arguments provided by the
|
||||||
configuration's ``database`` settings
|
configuration's ``database`` settings
|
||||||
"""
|
"""
|
||||||
dbconf = Config().get()['database']
|
dbconf = Config().get()["database"]
|
||||||
|
|
||||||
self.host = host or dbconf["host"] if not kwargs.get("host") else kwargs["host"]
|
self.host = host or dbconf["host"] if not kwargs.get("host") else kwargs["host"]
|
||||||
self.port = port or dbconf['port'] if not kwargs.get("port") else kwargs["port"]
|
self.port = port or dbconf["port"] if not kwargs.get("port") else kwargs["port"]
|
||||||
self.login = login or dbconf['login'] if not kwargs.get("login") else kwargs["login"]
|
self.login = login or dbconf["login"] if not kwargs.get("login") else kwargs["login"]
|
||||||
self.password = password or dbconf['password'] if not kwargs.get("password") else kwargs["password"]
|
self.password = password or dbconf["password"] if not kwargs.get("password") else kwargs["password"]
|
||||||
|
|
||||||
self.connection_timeout = connection_timeout if connection_timeout is not None else Config().get()["database"]
|
self.connection_timeout = connection_timeout if connection_timeout is not None else Config().get()["database"]
|
||||||
self.max_tries = max_tries if max_tries is not None else dbconf['max_tries']
|
self.max_tries = max_tries if max_tries is not None else dbconf["max_tries"]
|
||||||
self.max_tries_counter = range(self.max_tries) if self.max_tries != 0 else repeat(0)
|
self.max_tries_counter = range(self.max_tries) if self.max_tries != 0 else repeat(0)
|
||||||
|
|
||||||
def run(self, query):
|
def run(self, query):
|
||||||
|
|||||||
@ -8,17 +8,15 @@ from ssl import CERT_REQUIRED
|
|||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
from planetmint.backend.exceptions import (DuplicateKeyError,
|
from planetmint.backend.exceptions import DuplicateKeyError, OperationError, ConnectionError
|
||||||
OperationError,
|
|
||||||
ConnectionError)
|
|
||||||
from planetmint.transactions.common.exceptions import ConfigurationError
|
from planetmint.transactions.common.exceptions import ConfigurationError
|
||||||
from planetmint.utils import Lazy
|
from planetmint.utils import Lazy
|
||||||
from planetmint.backend.connection import DBConnection, _kwargs_parser
|
from planetmint.backend.connection import DBConnection, _kwargs_parser
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class LocalMongoDBConnection(DBConnection):
|
|
||||||
|
|
||||||
|
class LocalMongoDBConnection(DBConnection):
|
||||||
def __init__(self, host: str = None, port: int = None, login: str = None, password: str = None, **kwargs):
|
def __init__(self, host: str = None, port: int = None, login: str = None, password: str = None, **kwargs):
|
||||||
"""Create a new Connection instance.
|
"""Create a new Connection instance.
|
||||||
|
|
||||||
@ -31,17 +29,18 @@ class LocalMongoDBConnection(DBConnection):
|
|||||||
|
|
||||||
super().__init__(host=host, port=port, login=login, password=password, **kwargs)
|
super().__init__(host=host, port=port, login=login, password=password, **kwargs)
|
||||||
|
|
||||||
dbconf = Config().get()['database']
|
dbconf = Config().get()["database"]
|
||||||
self.dbname = _kwargs_parser(key="name", kwargs=kwargs) or dbconf['name']
|
self.dbname = _kwargs_parser(key="name", kwargs=kwargs) or dbconf["name"]
|
||||||
self.replicaset = _kwargs_parser(key="replicaset", kwargs=kwargs) or dbconf['replicaset']
|
self.replicaset = _kwargs_parser(key="replicaset", kwargs=kwargs) or dbconf["replicaset"]
|
||||||
self.ssl = _kwargs_parser(key="ssl", kwargs=kwargs) or dbconf['ssl']
|
self.ssl = _kwargs_parser(key="ssl", kwargs=kwargs) or dbconf["ssl"]
|
||||||
|
|
||||||
self.ca_cert = _kwargs_parser(key="ca_cert", kwargs=kwargs) or dbconf['ca_cert']
|
self.ca_cert = _kwargs_parser(key="ca_cert", kwargs=kwargs) or dbconf["ca_cert"]
|
||||||
self.certfile = _kwargs_parser(key="certfile", kwargs=kwargs) or dbconf['certfile']
|
self.certfile = _kwargs_parser(key="certfile", kwargs=kwargs) or dbconf["certfile"]
|
||||||
self.keyfile = _kwargs_parser(key="keyfile", kwargs=kwargs) or dbconf['keyfile']
|
self.keyfile = _kwargs_parser(key="keyfile", kwargs=kwargs) or dbconf["keyfile"]
|
||||||
self.keyfile_passphrase = _kwargs_parser(key="keyfile_passphrase", kwargs=kwargs) or dbconf[
|
self.keyfile_passphrase = (
|
||||||
'keyfile_passphrase']
|
_kwargs_parser(key="keyfile_passphrase", kwargs=kwargs) or dbconf["keyfile_passphrase"]
|
||||||
self.crlfile = _kwargs_parser(key="crlfile", kwargs=kwargs) or dbconf['crlfile']
|
)
|
||||||
|
self.crlfile = _kwargs_parser(key="crlfile", kwargs=kwargs) or dbconf["crlfile"]
|
||||||
self.max_tries = _kwargs_parser(key="max_tries", kwargs=kwargs)
|
self.max_tries = _kwargs_parser(key="max_tries", kwargs=kwargs)
|
||||||
self.connection_timeout = _kwargs_parser(key="connection_timeout", kwargs=kwargs)
|
self.connection_timeout = _kwargs_parser(key="connection_timeout", kwargs=kwargs)
|
||||||
self.__conn = None
|
self.__conn = None
|
||||||
@ -72,8 +71,7 @@ class LocalMongoDBConnection(DBConnection):
|
|||||||
try:
|
try:
|
||||||
return query.run(self.connect())
|
return query.run(self.connect())
|
||||||
except pymongo.errors.AutoReconnect:
|
except pymongo.errors.AutoReconnect:
|
||||||
logger.warning('Lost connection to the database, '
|
logger.warning("Lost connection to the database, " "retrying query.")
|
||||||
'retrying query.')
|
|
||||||
return query.run(self.connect())
|
return query.run(self.connect())
|
||||||
except pymongo.errors.AutoReconnect as exc:
|
except pymongo.errors.AutoReconnect as exc:
|
||||||
raise ConnectionError from exc
|
raise ConnectionError from exc
|
||||||
@ -130,14 +128,12 @@ class LocalMongoDBConnection(DBConnection):
|
|||||||
**MONGO_OPTS,
|
**MONGO_OPTS,
|
||||||
)
|
)
|
||||||
if self.login is not None:
|
if self.login is not None:
|
||||||
client[self.dbname].authenticate(self.login,
|
client[self.dbname].authenticate(self.login, mechanism="MONGODB-X509")
|
||||||
mechanism='MONGODB-X509')
|
|
||||||
self.__conn = client
|
self.__conn = client
|
||||||
return client
|
return client
|
||||||
|
|
||||||
except (pymongo.errors.ConnectionFailure,
|
except (pymongo.errors.ConnectionFailure, pymongo.errors.OperationFailure) as exc:
|
||||||
pymongo.errors.OperationFailure) as exc:
|
logger.info("Exception in connect(): {}".format(exc))
|
||||||
logger.info('Exception in connect(): {}'.format(exc))
|
|
||||||
raise ConnectionError(str(exc)) from exc
|
raise ConnectionError(str(exc)) from exc
|
||||||
except pymongo.errors.ConfigurationError as exc:
|
except pymongo.errors.ConfigurationError as exc:
|
||||||
raise ConfigurationError from exc
|
raise ConfigurationError from exc
|
||||||
@ -147,9 +143,10 @@ class LocalMongoDBConnection(DBConnection):
|
|||||||
self.__conn.close()
|
self.__conn.close()
|
||||||
self.__conn = None
|
self.__conn = None
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.info('Exception in planetmint.backend.localmongodb.close(): {}'.format(exc))
|
logger.info("Exception in planetmint.backend.localmongodb.close(): {}".format(exc))
|
||||||
raise ConnectionError(str(exc)) from exc
|
raise ConnectionError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
MONGO_OPTS = {
|
MONGO_OPTS = {
|
||||||
"socketTimeoutMS": 20000,
|
"socketTimeoutMS": 20000,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from functools import singledispatch
|
from functools import singledispatch
|
||||||
|
|
||||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
# Planetmint and IPDB software contributors.
|
# Planetmint and IPDB software contributors.
|
||||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
|||||||
@ -135,8 +135,12 @@ def init_database(connection=None, dbname=None):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
connection = connection or Connection()
|
connection = connection or Connection()
|
||||||
print("=========================================", connection.__class__, "=========================================================")
|
print(
|
||||||
dbname = dbname or Config().get()['database']['name']
|
"=========================================",
|
||||||
|
connection.__class__,
|
||||||
|
"=========================================================",
|
||||||
|
)
|
||||||
|
dbname = dbname or Config().get()["database"]["name"]
|
||||||
|
|
||||||
create_database(connection, dbname)
|
create_database(connection, dbname)
|
||||||
create_tables(connection, dbname)
|
create_tables(connection, dbname)
|
||||||
|
|||||||
@ -71,7 +71,7 @@ class TarantoolDBConnection(DBConnection):
|
|||||||
self.__conn.close()
|
self.__conn.close()
|
||||||
self.__conn = None
|
self.__conn = None
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.info('Exception in planetmint.backend.tarantool.close(): {}'.format(exc))
|
logger.info("Exception in planetmint.backend.tarantool.close(): {}".format(exc))
|
||||||
raise ConnectionError(str(exc)) from exc
|
raise ConnectionError(str(exc)) from exc
|
||||||
|
|
||||||
def get_space(self, space_name: str):
|
def get_space(self, space_name: str):
|
||||||
|
|||||||
@ -16,7 +16,7 @@ register_query = module_dispatch_registrar(convert)
|
|||||||
def prepare_asset(connection, transaction_type, transaction_id, filter_operation, asset):
|
def prepare_asset(connection, transaction_type, transaction_id, filter_operation, asset):
|
||||||
asset_id = transaction_id
|
asset_id = transaction_id
|
||||||
if transaction_type not in filter_operation:
|
if transaction_type not in filter_operation:
|
||||||
asset_id = asset['id']
|
asset_id = asset["id"]
|
||||||
return tuple([asset, transaction_id, asset_id])
|
return tuple([asset, transaction_id, asset_id])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config
|
# from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||||
from planetmint.version import __version__ # noqa
|
from planetmint.version import __version__ # noqa
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ from logging.config import dictConfig as set_logging_config
|
|||||||
from planetmint.config import Config, DEFAULT_LOGGING_CONFIG
|
from planetmint.config import Config, DEFAULT_LOGGING_CONFIG
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def _normalize_log_level(level):
|
def _normalize_log_level(level):
|
||||||
try:
|
try:
|
||||||
return level.upper()
|
return level.upper()
|
||||||
|
|||||||
@ -11,6 +11,7 @@ from planetmint.exceptions import BigchainDBError
|
|||||||
class ConfigurationError(BigchainDBError):
|
class ConfigurationError(BigchainDBError):
|
||||||
"""Raised when there is a problem with server configuration"""
|
"""Raised when there is a problem with server configuration"""
|
||||||
|
|
||||||
|
|
||||||
class ConnectionError(BigchainDBError):
|
class ConnectionError(BigchainDBError):
|
||||||
"""Raised when there is a problem with server connection"""
|
"""Raised when there is a problem with server connection"""
|
||||||
|
|
||||||
|
|||||||
@ -904,12 +904,8 @@ class Transaction(object):
|
|||||||
if asset_id != self.asset["id"]:
|
if asset_id != self.asset["id"]:
|
||||||
raise AssetIdMismatch(("The asset id of the input does not" " match the asset id of the" " transaction"))
|
raise AssetIdMismatch(("The asset id of the input does not" " match the asset id of the" " transaction"))
|
||||||
|
|
||||||
input_amount = sum(
|
input_amount = sum([input_condition.amount for input_condition in input_conditions])
|
||||||
[input_condition.amount for input_condition in input_conditions]
|
output_amount = sum([output_condition.amount for output_condition in self.outputs])
|
||||||
)
|
|
||||||
output_amount = sum(
|
|
||||||
[output_condition.amount for output_condition in self.outputs]
|
|
||||||
)
|
|
||||||
|
|
||||||
if output_amount != input_amount:
|
if output_amount != input_amount:
|
||||||
raise AmountError(
|
raise AmountError(
|
||||||
|
|||||||
10
setup.py
10
setup.py
@ -89,15 +89,7 @@ docs_require = [
|
|||||||
|
|
||||||
check_setuptools_features()
|
check_setuptools_features()
|
||||||
|
|
||||||
dev_require = [
|
dev_require = ["ipdb", "ipython", "watchdog", "logging_tree", "pre-commit", "twine", "ptvsd"]
|
||||||
"ipdb",
|
|
||||||
"ipython",
|
|
||||||
"watchdog",
|
|
||||||
"logging_tree",
|
|
||||||
"pre-commit",
|
|
||||||
"twine",
|
|
||||||
"ptvsd"
|
|
||||||
]
|
|
||||||
|
|
||||||
tests_require = [
|
tests_require = [
|
||||||
"coverage",
|
"coverage",
|
||||||
|
|||||||
@ -16,6 +16,7 @@ pytestmark = pytest.mark.bdb
|
|||||||
|
|
||||||
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn):
|
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn):
|
||||||
from planetmint.backend.tarantool import query
|
from planetmint.backend.tarantool import query
|
||||||
|
|
||||||
# create and insert two blocks, one for the create and one for the
|
# create and insert two blocks, one for the create and one for the
|
||||||
# transfer transaction
|
# transfer transaction
|
||||||
create_tx_dict = signed_create_tx.to_dict()
|
create_tx_dict = signed_create_tx.to_dict()
|
||||||
|
|||||||
@ -13,6 +13,6 @@ def test_get_connection_raises_a_configuration_error(monkeypatch):
|
|||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
with pytest.raises(ConnectionError):
|
with pytest.raises(ConnectionError):
|
||||||
LocalMongoDBConnection('localhost', '1337', 'mydb', 'password')
|
LocalMongoDBConnection("localhost", "1337", "mydb", "password")
|
||||||
with pytest.raises(ConnectionError):
|
with pytest.raises(ConnectionError):
|
||||||
TarantoolDBConnection('localhost', '1337', 'mydb', 'password')
|
TarantoolDBConnection("localhost", "1337", "mydb", "password")
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import pytest
|
|||||||
|
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_run_configure(monkeypatch):
|
def mock_run_configure(monkeypatch):
|
||||||
from planetmint.commands import planetmint
|
from planetmint.commands import planetmint
|
||||||
|
|||||||
@ -21,6 +21,7 @@ from planetmint.transactions.types.elections.chain_migration_election import Cha
|
|||||||
|
|
||||||
from tests.utils import generate_election, generate_validators
|
from tests.utils import generate_election, generate_validators
|
||||||
|
|
||||||
|
|
||||||
def test_make_sure_we_dont_remove_any_command():
|
def test_make_sure_we_dont_remove_any_command():
|
||||||
# thanks to: http://stackoverflow.com/a/18161115/597097
|
# thanks to: http://stackoverflow.com/a/18161115/597097
|
||||||
from planetmint.commands.planetmint import create_parser
|
from planetmint.commands.planetmint import create_parser
|
||||||
@ -95,6 +96,7 @@ def test_bigchain_show_config(capsys):
|
|||||||
# dict returned is different that what is expected after run_show_config
|
# dict returned is different that what is expected after run_show_config
|
||||||
# and run_show_config updates the planetmint.config
|
# and run_show_config updates the planetmint.config
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
_config = Config().get()
|
_config = Config().get()
|
||||||
sorted_config = json.dumps(_config, indent=4, sort_keys=True)
|
sorted_config = json.dumps(_config, indent=4, sort_keys=True)
|
||||||
print(f"_config : {sorted_config}")
|
print(f"_config : {sorted_config}")
|
||||||
@ -103,8 +105,7 @@ def test_bigchain_show_config(capsys):
|
|||||||
|
|
||||||
|
|
||||||
def test__run_init(mocker):
|
def test__run_init(mocker):
|
||||||
init_db_mock = mocker.patch(
|
init_db_mock = mocker.patch("planetmint.backend.tarantool.connection.TarantoolDBConnection.init_database")
|
||||||
'planetmint.backend.tarantool.connection.TarantoolDBConnection.init_database')
|
|
||||||
|
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
conn.init_database()
|
conn.init_database()
|
||||||
|
|||||||
@ -23,6 +23,7 @@ from planetmint.backend.connection import Connection
|
|||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# from pymongo import MongoClient
|
# from pymongo import MongoClient
|
||||||
|
|
||||||
from planetmint import ValidatorElection
|
from planetmint import ValidatorElection
|
||||||
@ -117,21 +118,21 @@ def _configure_planetmint(request):
|
|||||||
config_utils.set_config(config)
|
config_utils.set_config(config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope="session")
|
||||||
def _setup_database(_configure_planetmint): # TODO Here is located setup database
|
def _setup_database(_configure_planetmint): # TODO Here is located setup database
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
print('Initializing test db')
|
print("Initializing test db")
|
||||||
dbname = Config().get()['database']['name']
|
dbname = Config().get()["database"]["name"]
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
|
|
||||||
_drop_db(conn, dbname)
|
_drop_db(conn, dbname)
|
||||||
schema.init_database(conn, dbname)
|
schema.init_database(conn, dbname)
|
||||||
print('Finishing init database')
|
print("Finishing init database")
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
print('Deleting `{}` database'.format(dbname))
|
print("Deleting `{}` database".format(dbname))
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
_drop_db(conn, dbname)
|
_drop_db(conn, dbname)
|
||||||
|
|
||||||
@ -144,9 +145,10 @@ def _bdb(_setup_database, _configure_planetmint):
|
|||||||
from planetmint.transactions.common.transaction import Transaction
|
from planetmint.transactions.common.transaction import Transaction
|
||||||
from .utils import flush_db
|
from .utils import flush_db
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
yield
|
yield
|
||||||
dbname = Config().get()['database']['name']
|
dbname = Config().get()["database"]["name"]
|
||||||
flush_db(conn, dbname)
|
flush_db(conn, dbname)
|
||||||
|
|
||||||
to_dict.cache_clear()
|
to_dict.cache_clear()
|
||||||
@ -250,6 +252,7 @@ def abci_fixture():
|
|||||||
|
|
||||||
return types_pb2
|
return types_pb2
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def b():
|
def b():
|
||||||
from planetmint import Planetmint
|
from planetmint import Planetmint
|
||||||
@ -547,6 +550,7 @@ def tarantool_client(db_context): # TODO Here add TarantoolConnectionClass
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def utxo_collection(tarantool_client, _setup_database):
|
def utxo_collection(tarantool_client, _setup_database):
|
||||||
return tarantool_client.get_space("utxos")
|
return tarantool_client.get_space("utxos")
|
||||||
@ -564,6 +568,7 @@ def dummy_unspent_outputs():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def utxoset(dummy_unspent_outputs, utxo_collection):
|
def utxoset(dummy_unspent_outputs, utxo_collection):
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
num_rows_before_operation = utxo_collection.select().rowcount
|
num_rows_before_operation = utxo_collection.select().rowcount
|
||||||
for utxo in dummy_unspent_outputs:
|
for utxo in dummy_unspent_outputs:
|
||||||
res = utxo_collection.insert((utxo["transaction_id"], utxo["output_index"], dumps(utxo)))
|
res = utxo_collection.insert((utxo["transaction_id"], utxo["output_index"], dumps(utxo)))
|
||||||
@ -619,6 +624,7 @@ def node_keys():
|
|||||||
"PecJ58SaNRsWJZodDmqjpCWqG6btdwXFHLyE40RYlYM=": "uz8bYgoL4rHErWT1gjjrnA+W7bgD/uDQWSRKDmC8otc95wnnxJo1GxYlmh0OaqOkJaobpu13BcUcvITjRFiVgw==",
|
"PecJ58SaNRsWJZodDmqjpCWqG6btdwXFHLyE40RYlYM=": "uz8bYgoL4rHErWT1gjjrnA+W7bgD/uDQWSRKDmC8otc95wnnxJo1GxYlmh0OaqOkJaobpu13BcUcvITjRFiVgw==",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def priv_validator_path(node_keys):
|
def priv_validator_path(node_keys):
|
||||||
(public_key, private_key) = list(node_keys.items())[0]
|
(public_key, private_key) = list(node_keys.items())[0]
|
||||||
|
|||||||
@ -290,6 +290,7 @@ def test_delete_zero_unspent_outputs(b, utxoset):
|
|||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
def test_delete_one_unspent_outputs(b, utxoset):
|
def test_delete_one_unspent_outputs(b, utxoset):
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
unspent_outputs, utxo_collection = utxoset
|
unspent_outputs, utxo_collection = utxoset
|
||||||
delete_res = b.delete_unspent_outputs(unspent_outputs[0])
|
delete_res = b.delete_unspent_outputs(unspent_outputs[0])
|
||||||
if not isinstance(b.connection, TarantoolDBConnection):
|
if not isinstance(b.connection, TarantoolDBConnection):
|
||||||
@ -318,6 +319,7 @@ def test_delete_one_unspent_outputs(b, utxoset):
|
|||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
def test_delete_many_unspent_outputs(b, utxoset):
|
def test_delete_many_unspent_outputs(b, utxoset):
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
unspent_outputs, utxo_collection = utxoset
|
unspent_outputs, utxo_collection = utxoset
|
||||||
delete_res = b.delete_unspent_outputs(*unspent_outputs[::2])
|
delete_res = b.delete_unspent_outputs(*unspent_outputs[::2])
|
||||||
if not isinstance(b.connection, TarantoolDBConnection):
|
if not isinstance(b.connection, TarantoolDBConnection):
|
||||||
@ -355,6 +357,7 @@ def test_store_zero_unspent_output(b, utxo_collection):
|
|||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
def test_store_one_unspent_output(b, unspent_output_1, utxo_collection):
|
def test_store_one_unspent_output(b, unspent_output_1, utxo_collection):
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
res = b.store_unspent_outputs(unspent_output_1)
|
res = b.store_unspent_outputs(unspent_output_1)
|
||||||
if not isinstance(b.connection, TarantoolDBConnection):
|
if not isinstance(b.connection, TarantoolDBConnection):
|
||||||
assert res.acknowledged
|
assert res.acknowledged
|
||||||
@ -379,6 +382,7 @@ def test_store_one_unspent_output(b, unspent_output_1, utxo_collection):
|
|||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
def test_store_many_unspent_outputs(b, unspent_outputs, utxo_collection):
|
def test_store_many_unspent_outputs(b, unspent_outputs, utxo_collection):
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
res = b.store_unspent_outputs(*unspent_outputs)
|
res = b.store_unspent_outputs(*unspent_outputs)
|
||||||
if not isinstance(b.connection, TarantoolDBConnection):
|
if not isinstance(b.connection, TarantoolDBConnection):
|
||||||
assert res.acknowledged
|
assert res.acknowledged
|
||||||
|
|||||||
@ -55,25 +55,28 @@ def config(request, monkeypatch):
|
|||||||
monkeypatch.setattr("planetmint.config", config)
|
monkeypatch.setattr("planetmint.config", config)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def test_bigchain_class_initialization_with_parameters():
|
def test_bigchain_class_initialization_with_parameters():
|
||||||
from planetmint.backend.localmongodb.connection import LocalMongoDBConnection
|
from planetmint.backend.localmongodb.connection import LocalMongoDBConnection
|
||||||
from planetmint.transactions.common.exceptions import ConfigurationError
|
from planetmint.transactions.common.exceptions import ConfigurationError
|
||||||
|
|
||||||
init_db_kwargs = {
|
init_db_kwargs = {
|
||||||
'backend': 'localmongodb',
|
"backend": "localmongodb",
|
||||||
'host': 'this_is_the_db_host',
|
"host": "this_is_the_db_host",
|
||||||
'port': 12345,
|
"port": 12345,
|
||||||
'name': 'this_is_the_db_name',
|
"name": "this_is_the_db_name",
|
||||||
}
|
}
|
||||||
with pytest.raises(ConfigurationError):
|
with pytest.raises(ConfigurationError):
|
||||||
LocalMongoDBConnection(**init_db_kwargs)
|
LocalMongoDBConnection(**init_db_kwargs)
|
||||||
|
|
||||||
|
|
||||||
def test_bigchain_class_default_initialization(config):
|
def test_bigchain_class_default_initialization(config):
|
||||||
from planetmint import Planetmint
|
from planetmint import Planetmint
|
||||||
from planetmint.validation import BaseValidationRules
|
from planetmint.validation import BaseValidationRules
|
||||||
|
|
||||||
planet = Planetmint()
|
planet = Planetmint()
|
||||||
assert planet.connection.host == config['database']['host']
|
assert planet.connection.host == config["database"]["host"]
|
||||||
assert planet.connection.port == config['database']['port']
|
assert planet.connection.port == config["database"]["port"]
|
||||||
assert planet.validation == BaseValidationRules
|
assert planet.validation == BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -348,9 +348,7 @@ def test_post_transfer_transaction_endpoint(client, user_pk, user_sk, posted_cre
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.abci
|
@pytest.mark.abci
|
||||||
def test_post_invalid_transfer_transaction_returns_400(
|
def test_post_invalid_transfer_transaction_returns_400(client, user_pk, posted_create_tx):
|
||||||
client, user_pk, posted_create_tx
|
|
||||||
):
|
|
||||||
from planetmint.transactions.common.exceptions import InvalidSignature
|
from planetmint.transactions.common.exceptions import InvalidSignature
|
||||||
|
|
||||||
transfer_tx = Transfer.generate(posted_create_tx.to_inputs(), [([user_pk], 1)], asset_id=posted_create_tx.id)
|
transfer_tx = Transfer.generate(posted_create_tx.to_inputs(), [([user_pk], 1)], asset_id=posted_create_tx.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user