mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
in this commit, tarantool queries and abstract connection is working
This commit is contained in:
parent
3a3f977fc3
commit
ee045a5df0
@ -22,7 +22,7 @@ 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 = "localhost", port: int = 3301, user: str = "admin", password: str = "pass", reset_database: bool = False):
|
||||||
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
|
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()
|
||||||
|
|||||||
@ -12,8 +12,8 @@ def run(commands: list, config: dict):
|
|||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
try:
|
try:
|
||||||
sshProcess.stdin.write(cmd)
|
sshProcess.stdin.write(cmd)
|
||||||
except:
|
except Exception as cmd_err:
|
||||||
pass
|
print(str(cmd_err))
|
||||||
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:
|
||||||
|
|||||||
@ -6,18 +6,18 @@
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
# import pymongo
|
import pymongo
|
||||||
|
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.bdb
|
pytestmark = pytest.mark.bdb
|
||||||
|
|
||||||
|
|
||||||
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
conn = connect() # TODO First rewrite to get here tarantool connection
|
conn = Connection() # 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
|
||||||
@ -40,8 +40,8 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
|||||||
|
|
||||||
|
|
||||||
def test_write_assets():
|
def test_write_assets():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
assets = [
|
assets = [
|
||||||
{'id': 1, 'data': '1'},
|
{'id': 1, 'data': '1'},
|
||||||
@ -64,8 +64,8 @@ def test_write_assets():
|
|||||||
|
|
||||||
|
|
||||||
def test_get_assets():
|
def test_get_assets():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
assets = [
|
assets = [
|
||||||
{'id': 1, 'data': '1'},
|
{'id': 1, 'data': '1'},
|
||||||
@ -81,8 +81,8 @@ 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
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
# Example data and tests cases taken from the mongodb documentation
|
# Example data and tests cases taken from the mongodb documentation
|
||||||
# https://docs.mongodb.com/manual/reference/operator/query/text/
|
# https://docs.mongodb.com/manual/reference/operator/query/text/
|
||||||
@ -165,8 +165,8 @@ def test_text_search(table):
|
|||||||
|
|
||||||
|
|
||||||
def test_write_metadata():
|
def test_write_metadata():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
metadata = [
|
metadata = [
|
||||||
{'id': 1, 'data': '1'},
|
{'id': 1, 'data': '1'},
|
||||||
@ -180,14 +180,13 @@ def test_write_metadata():
|
|||||||
# check that 3 assets were written to the database
|
# check that 3 assets were written to the database
|
||||||
cursor = conn.db.metadata.find({}, projection={'_id': False})\
|
cursor = conn.db.metadata.find({}, projection={'_id': False})\
|
||||||
.sort('id', pymongo.ASCENDING)
|
.sort('id', pymongo.ASCENDING)
|
||||||
TarantoolDB
|
|
||||||
assert cursor.collection.count_documents({}) == 3
|
assert cursor.collection.count_documents({}) == 3
|
||||||
assert list(cursor) == metadata
|
assert list(cursor) == metadata
|
||||||
|
|
||||||
|
|
||||||
def test_get_metadata():
|
def test_get_metadata():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
metadata = [
|
metadata = [
|
||||||
{'id': 1, 'metadata': None},
|
{'id': 1, 'metadata': None},
|
||||||
@ -202,8 +201,8 @@ def test_get_metadata():
|
|||||||
|
|
||||||
|
|
||||||
def test_get_owned_ids(signed_create_tx, user_pk):
|
def test_get_owned_ids(signed_create_tx, user_pk):
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
# insert a transaction
|
# insert a transaction
|
||||||
conn.db.transactions.insert_one(deepcopy(signed_create_tx.to_dict()))
|
conn.db.transactions.insert_one(deepcopy(signed_create_tx.to_dict()))
|
||||||
@ -214,9 +213,9 @@ def test_get_owned_ids(signed_create_tx, user_pk):
|
|||||||
|
|
||||||
|
|
||||||
def test_get_spending_transactions(user_pk, user_sk):
|
def test_get_spending_transactions(user_pk, user_sk):
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
out = [([user_pk], 1)]
|
out = [([user_pk], 1)]
|
||||||
tx1 = Transaction.create([user_pk], out * 3)
|
tx1 = Transaction.create([user_pk], out * 3)
|
||||||
@ -236,10 +235,10 @@ def test_get_spending_transactions(user_pk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
def test_get_spending_transactions_multiple_inputs():
|
def test_get_spending_transactions_multiple_inputs():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
from planetmint.common.crypto import generate_key_pair
|
from planetmint.common.crypto import generate_key_pair
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
(alice_sk, alice_pk) = generate_key_pair()
|
(alice_sk, alice_pk) = generate_key_pair()
|
||||||
(bob_sk, bob_pk) = generate_key_pair()
|
(bob_sk, bob_pk) = generate_key_pair()
|
||||||
(carol_sk, carol_pk) = generate_key_pair()
|
(carol_sk, carol_pk) = generate_key_pair()
|
||||||
@ -279,9 +278,9 @@ def test_get_spending_transactions_multiple_inputs():
|
|||||||
|
|
||||||
|
|
||||||
def test_store_block():
|
def test_store_block():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
from planetmint.lib import Block
|
from planetmint.lib import Block
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
block = Block(app_hash='random_utxo',
|
block = Block(app_hash='random_utxo',
|
||||||
height=3,
|
height=3,
|
||||||
@ -292,9 +291,9 @@ def test_store_block():
|
|||||||
|
|
||||||
|
|
||||||
def test_get_block():
|
def test_get_block():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
from planetmint.lib import Block
|
from planetmint.lib import Block
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
block = Block(app_hash='random_utxo',
|
block = Block(app_hash='random_utxo',
|
||||||
height=3,
|
height=3,
|
||||||
@ -415,9 +414,9 @@ def test_get_pre_commit_state(db_context):
|
|||||||
|
|
||||||
|
|
||||||
def test_validator_update():
|
def test_validator_update():
|
||||||
from planetmint.backend import connect, query
|
from planetmint.backend import Connection, query
|
||||||
|
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
def gen_validator_update(height):
|
def gen_validator_update(height):
|
||||||
return {'data': 'somedata', 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
return {'data': 'somedata', 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
||||||
@ -475,7 +474,7 @@ def test_validator_update():
|
|||||||
),
|
),
|
||||||
])
|
])
|
||||||
def test_store_abci_chain(description, stores, expected):
|
def test_store_abci_chain(description, stores, expected):
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
|
|
||||||
for store in stores:
|
for store in stores:
|
||||||
query.store_abci_chain(conn, **store)
|
query.store_abci_chain(conn, **store)
|
||||||
|
|||||||
@ -18,7 +18,7 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
|||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
from planetmint.backend.tarantool import query
|
from planetmint.backend.tarantool import query
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
conn = Connection(reset_database=True).get_connection()
|
conn = Connection().get_connection()
|
||||||
# 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()
|
||||||
|
|||||||
@ -127,10 +127,10 @@ def _setup_database(_configure_planetmint): # TODO Here is located setup databa
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def _bdb(_setup_database, _configure_planetmint):
|
def _bdb(_setup_database, _configure_planetmint):
|
||||||
from planetmint.backend import connect
|
from planetmint.backend import Connection
|
||||||
from planetmint.common.memoize import to_dict, from_dict
|
from planetmint.common.memoize import to_dict, from_dict
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
conn = connect()
|
conn = Connection()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
to_dict.cache_clear()
|
to_dict.cache_clear()
|
||||||
@ -363,8 +363,8 @@ def db_name(db_config):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def db_conn():
|
def db_conn():
|
||||||
from planetmint.backend import connect
|
from planetmint.backend import Connection
|
||||||
return connect()
|
return Connection()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user