mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +00:00
created flush_db for tarantool connection type
This commit is contained in:
parent
bf3ece309e
commit
cc6f8eea16
@ -20,6 +20,10 @@ logger = logging.getLogger(__name__)
|
|||||||
TABLES = ('transactions', 'blocks', 'assets', 'metadata',
|
TABLES = ('transactions', 'blocks', 'assets', 'metadata',
|
||||||
'validators', 'elections', 'pre_commit', 'utxos', 'abci_chains')
|
'validators', 'elections', 'pre_commit', 'utxos', 'abci_chains')
|
||||||
|
|
||||||
|
SPACE_NAMES = ("abci_chains", "assets", "blocks", "blocks_tx",
|
||||||
|
"elections", "meta_data", "pre_commits", "validators",
|
||||||
|
"transactions", "inputs", "outputs", "keys")
|
||||||
|
|
||||||
VALID_LANGUAGES = ('danish', 'dutch', 'english', 'finnish', 'french', 'german',
|
VALID_LANGUAGES = ('danish', 'dutch', 'english', 'finnish', 'french', 'german',
|
||||||
'hungarian', 'italian', 'norwegian', 'portuguese', 'romanian',
|
'hungarian', 'italian', 'norwegian', 'portuguese', 'romanian',
|
||||||
'russian', 'spanish', 'swedish', 'turkish', 'none',
|
'russian', 'spanish', 'swedish', 'turkish', 'none',
|
||||||
|
|||||||
@ -126,19 +126,6 @@ def _setup_database(_configure_planetmint): # TODO Here is located setup databa
|
|||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
|
|
||||||
# print('Deleting `{}` database')
|
|
||||||
# db_conn = Connection()
|
|
||||||
# db_conn.drop_database()
|
|
||||||
# db_conn.init_database()
|
|
||||||
# print('Finished deleting ``')
|
|
||||||
#
|
|
||||||
# yield
|
|
||||||
#
|
|
||||||
# print('Initializing test db')
|
|
||||||
# db_conn2 = Connection()
|
|
||||||
# db_conn2.drop_database()
|
|
||||||
# print('Finishing init database')
|
|
||||||
|
|
||||||
print('Initializing test db')
|
print('Initializing test db')
|
||||||
dbname = Config().get()['database']['name']
|
dbname = Config().get()['database']['name']
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
@ -161,8 +148,12 @@ def _bdb(_setup_database):
|
|||||||
from planetmint.backend import Connection
|
from planetmint.backend import Connection
|
||||||
from planetmint.transactions.common.memoize import to_dict, from_dict
|
from planetmint.transactions.common.memoize import to_dict, from_dict
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
|
from .utils import flush_db
|
||||||
|
from planetmint.config import Config
|
||||||
conn = Connection()
|
conn = Connection()
|
||||||
yield
|
yield
|
||||||
|
dbname = Config().get()['database']['name']
|
||||||
|
flush_db(conn, dbname)
|
||||||
|
|
||||||
to_dict.cache_clear()
|
to_dict.cache_clear()
|
||||||
from_dict.cache_clear()
|
from_dict.cache_clear()
|
||||||
@ -372,7 +363,6 @@ def inputs(user_pk, b, alice):
|
|||||||
|
|
||||||
def _drop_db(conn, dbname):
|
def _drop_db(conn, dbname):
|
||||||
try:
|
try:
|
||||||
conn.drop_database()
|
|
||||||
schema.drop_database(conn, dbname)
|
schema.drop_database(conn, dbname)
|
||||||
except DatabaseDoesNotExist:
|
except DatabaseDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -10,7 +10,8 @@ import random
|
|||||||
from functools import singledispatch
|
from functools import singledispatch
|
||||||
|
|
||||||
from planetmint.backend.localmongodb.connection import LocalMongoDBConnection
|
from planetmint.backend.localmongodb.connection import LocalMongoDBConnection
|
||||||
from planetmint.backend.schema import TABLES
|
from planetmint.backend.tarantool.connection import TarantoolDB
|
||||||
|
from planetmint.backend.schema import TABLES, SPACE_NAMES
|
||||||
from planetmint.transactions.common import crypto
|
from planetmint.transactions.common import crypto
|
||||||
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||||
from planetmint.transactions.types.assets.create import Create
|
from planetmint.transactions.types.assets.create import Create
|
||||||
@ -29,14 +30,23 @@ def flush_localmongo_db(connection, dbname):
|
|||||||
getattr(connection.conn[dbname], t).delete_many({})
|
getattr(connection.conn[dbname], t).delete_many({})
|
||||||
|
|
||||||
|
|
||||||
|
@flush_db.register(TarantoolDB)
|
||||||
|
def flush_tarantool_db(connection, dbname):
|
||||||
|
for s in SPACE_NAMES:
|
||||||
|
_space = connection.space(space_name=s)
|
||||||
|
_all_data = _space.select([]).data
|
||||||
|
for _id in _all_data:
|
||||||
|
_space.delete(_id[0])
|
||||||
|
|
||||||
|
|
||||||
def generate_block(planet):
|
def generate_block(planet):
|
||||||
from planetmint.transactions.common.crypto import generate_key_pair
|
from planetmint.transactions.common.crypto import generate_key_pair
|
||||||
|
|
||||||
alice = generate_key_pair()
|
alice = generate_key_pair()
|
||||||
tx = Create.generate([alice.public_key],
|
tx = Create.generate([alice.public_key],
|
||||||
[([alice.public_key], 1)],
|
[([alice.public_key], 1)],
|
||||||
asset=None)\
|
asset=None) \
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
code, message = planet.write_transaction(tx, BROADCAST_TX_COMMIT)
|
code, message = planet.write_transaction(tx, BROADCAST_TX_COMMIT)
|
||||||
assert code == 202
|
assert code == 202
|
||||||
@ -55,7 +65,7 @@ def gen_vote(election, i, ed25519_node_keys):
|
|||||||
election_pub_key = Election.to_public_key(election.id)
|
election_pub_key = Election.to_public_key(election.id)
|
||||||
return Vote.generate([input_i],
|
return Vote.generate([input_i],
|
||||||
[([election_pub_key], votes_i)],
|
[([election_pub_key], votes_i)],
|
||||||
election_id=election.id)\
|
election_id=election.id) \
|
||||||
.sign([key_i.private_key])
|
.sign([key_i.private_key])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user