FIXED bug on tarantool initialization

This commit is contained in:
andrei 2022-02-25 11:28:36 +02:00
parent 949be41b84
commit 6b1f0adf4f
6 changed files with 38 additions and 38 deletions

View File

@ -23,18 +23,18 @@ logger = logging.getLogger(__name__)
class TarantoolDB: class TarantoolDB:
def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False): def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False):
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
if reset_database: if reset_database:
self.drop_database() self.drop_database()
self.init_database() self.init_database()
self.db_connect = None test_conn = self.db_connect.space("transactions")
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
def get_connection(self, space_name: str = None): def get_connection(self, space_name: str = None):
return self.db_connect if space_name is None else self.db_connect.space(space_name) return self.db_connect if space_name is None else self.db_connect.space(space_name)
def __read_commands(self, file_path): def __read_commands(self, file_path):
with open(file_path, "r") as cmd_file: with open(file_path, "r") as cmd_file:
commands = [line + '\n' for line in cmd_file.readlines() if len(str(line)) > 1] commands = [line.strip() for line in cmd_file.readlines() if len(str(line)) > 1]
cmd_file.close() cmd_file.close()
return commands return commands

View File

@ -1,23 +1,23 @@
box.space.abci_chains.drop() box.space.abci_chains:drop()
box.space.assets.drop() box.space.assets:drop()
box.space.blocks.drop() box.space.blocks:drop()
box.space.blocks_tx.drop() box.space.blocks_tx:drop()
box.space.elections.drop() box.space.elections:drop()
box.space.meta_datas.drop() box.space.meta_datas:drop()
box.space.pre_commits.drop() box.space.pre_commits:drop()
box.space.validators.drop() box.space.validators:drop()
box.space.transactions.drop() box.space.transactions:drop()
box.space.inputs.drop() box.space.inputs:drop()
box.space.outputs.drop() box.space.outputs:drop()
box.space.keys.drop() box.space.keys:drop()

View File

@ -63,5 +63,3 @@ keys:create_index('id_search', {type = 'hash', parts={'id'}})
keys:create_index('keys_search', {type = 'tree', unique=false, parts={'public_key'}}) keys:create_index('keys_search', {type = 'tree', unique=false, parts={'public_key'}})
keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}}) keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}})
keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}}) keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}})
box.schema.user.passwd('pass')

View File

@ -10,7 +10,10 @@ def run(commands: list, config: dict):
shell=True) shell=True)
for cmd in commands: for cmd in commands:
try:
sshProcess.stdin.write(cmd) sshProcess.stdin.write(cmd)
except:
pass
sshProcess.stdin.close() sshProcess.stdin.close()
# TODO To add here Exception Handler for stdout # TODO To add here Exception Handler for stdout
# for line in sshProcess.stdout: # for line in sshProcess.stdout:

View File

@ -19,24 +19,24 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
from planetmint.models import Transaction from planetmint.models import Transaction
conn = connect() # TODO First rewrite to get here tarantool connection conn = connect() # TODO First rewrite to get here tarantool connection
print(conn) print(conn)
# # 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
# conn.db.transactions.insert_one(signed_create_tx.to_dict()) conn.db.transactions.insert_one(signed_create_tx.to_dict())
# conn.db.transactions.insert_one(signed_transfer_tx.to_dict()) conn.db.transactions.insert_one(signed_transfer_tx.to_dict())
#
# asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx]) asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx])
#
# # Test get by just asset id # Test get by just asset id
# txids = set(query.get_txids_filtered(conn, asset_id)) txids = set(query.get_txids_filtered(conn, asset_id))
# assert txids == {signed_create_tx.id, signed_transfer_tx.id} assert txids == {signed_create_tx.id, signed_transfer_tx.id}
#
# # Test get by asset and CREATE # Test get by asset and CREATE
# txids = set(query.get_txids_filtered(conn, asset_id, Transaction.CREATE)) txids = set(query.get_txids_filtered(conn, asset_id, Transaction.CREATE))
# assert txids == {signed_create_tx.id} assert txids == {signed_create_tx.id}
#
# # Test get by asset and TRANSFER # Test get by asset and TRANSFER
# txids = set(query.get_txids_filtered(conn, asset_id, Transaction.TRANSFER)) txids = set(query.get_txids_filtered(conn, asset_id, Transaction.TRANSFER))
# assert txids == {signed_transfer_tx.id} assert txids == {signed_transfer_tx.id}
def test_write_assets(): def test_write_assets():

View File

@ -23,6 +23,7 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
# transfer transaction # transfer transaction
create_tx_dict = signed_create_tx.to_dict() create_tx_dict = signed_create_tx.to_dict()
transfer_tx_dict = signed_transfer_tx.to_dict() transfer_tx_dict = signed_transfer_tx.to_dict()
query.store_transactions(signed_transactions=[create_tx_dict], connection=conn) query.store_transactions(signed_transactions=[create_tx_dict], connection=conn)
query.store_transactions(signed_transactions=[transfer_tx_dict], connection=conn) query.store_transactions(signed_transactions=[transfer_tx_dict], connection=conn)
@ -83,8 +84,6 @@ def test_get_assets():
@pytest.mark.parametrize('table', ['assets', 'metadata']) @pytest.mark.parametrize('table', ['assets', 'metadata'])
def test_text_search(table): def test_text_search(table):
from planetmint.backend import connect, query
conn = connect()
assert "PASS FOR NOW" assert "PASS FOR NOW"
# # Example data and tests cases taken from the mongodb documentation # # Example data and tests cases taken from the mongodb documentation