Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INDY-2154: Cleanup #259

Merged
merged 24 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base58
from sovtoken.constants import UTXO_CACHE_LABEL, TOKEN_LEDGER_ID
from sovtoken.exceptions import TokenValueError
from sovtoken.request_handlers.token_utils import commit_to_utxo_cache

from plenum.server.database_manager import DatabaseManager

Expand All @@ -23,13 +24,4 @@ def post_batch_applied(self, three_pc_batch, prev_handler_result=None):
self.utxo_cache.create_batch_from_current(three_pc_batch.state_root)

def commit_batch(self, three_pc_batch, prev_handler_result=None):
state_root = three_pc_batch.state_root
state_root = base58.b58decode(state_root.encode()) if isinstance(
state_root, str) else state_root
if self.utxo_cache.first_batch_idr != state_root:
raise TokenValueError(
'state_root', state_root,
("equal to utxo_cache.first_batch_idr hash {}"
.format(self.utxo_cache.first_batch_idr))
)
self.utxo_cache.commit_batch()
commit_to_utxo_cache(self.utxo_cache, three_pc_batch.state_root)
3 changes: 2 additions & 1 deletion sovtoken/sovtoken/test/helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pytest
from sovtoken.request_handlers.write_request_handler.xfer_handler import XferHandler

from common.serializers.serialization import proof_nodes_serializer

Expand Down Expand Up @@ -39,7 +40,7 @@ def send_xfer(looper, inputs, outputs, sdk_pool_handle, extra_data=None):

def check_output_val_on_all_nodes(nodes, address, amount):
for node in nodes:
handler = node.write_manager.request_handlers[XFER_PUBLIC][0]
handler = next(h for h in node.write_manager.request_handlers[XFER_PUBLIC] if isinstance(h, XferHandler))
ArtObr marked this conversation as resolved.
Show resolved Hide resolved
assert int(amount) in [out.amount for out in
handler.utxo_cache.get_unspent_outputs(
address, is_committed=True)]
Expand Down
10 changes: 7 additions & 3 deletions sovtoken/sovtoken/test/helpers/helper_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from indy_common.constants import NYM, AUTH_RULE
from sovtoken.request_handlers.write_request_handler.mint_handler import MintHandler
from sovtoken.request_handlers.write_request_handler.xfer_handler import XferHandler

from indy_node.server.request_handlers.domain_req_handlers.nym_handler import NymHandler
from plenum.common.constants import DOMAIN_LEDGER_ID, CONFIG_LEDGER_ID
from sovtoken.constants import TOKEN_LEDGER_ID, XFER_PUBLIC, GET_UTXO, MINT_PUBLIC

Expand Down Expand Up @@ -33,17 +37,17 @@ def get_last_ledger_transaction_on_nodes(self, ledger_id):
@property
def xfer_handler(self):
""" Get the xfer request handler of the first node. """
return self._nodes[0].write_manager.request_handlers[XFER_PUBLIC][0]
return next(h for h in self._nodes[0].write_manager.request_handlers[XFER_PUBLIC] if isinstance(h, XferHandler))
ArtObr marked this conversation as resolved.
Show resolved Hide resolved

@property
def mint_handler(self):
""" Get the xfer request handler of the first node. """
return self._nodes[0].write_manager.request_handlers[MINT_PUBLIC][0]
return next(h for h in self._nodes[0].write_manager.request_handlers[MINT_PUBLIC] if isinstance(h, MintHandler))
ArtObr marked this conversation as resolved.
Show resolved Hide resolved

@property
def nym_handler(self):
""" Get the NYM request handler of the first node. """
return self._nodes[0].write_manager.request_handlers[NYM][0]
return next(h for h in self._nodes[0].write_manager.request_handlers[NYM] if isinstance(h, NymHandler))
ArtObr marked this conversation as resolved.
Show resolved Hide resolved

@property
def get_utxo_handler(self):
Expand Down
13 changes: 9 additions & 4 deletions sovtoken/sovtoken/test/req_handlers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ def bls_store(db_manager):

@pytest.fixture(scope="module")
def db_manager(tconf):
db_manager = DatabaseManager()
_db_manager = DatabaseManager()
storage = initKeyValueStorage(KeyValueStorageType.Memory,
None,
"tokenInMemoryStore",
txn_serializer=serialization.multi_sig_store_serializer)
ledger = get_fake_ledger()
ledger.commitTxns = lambda x: (None, [1])

def commit_txns(count):
ledger.committed_root_hash = ledger.uncommitted_root_hash
return None, [1]

ledger.commitTxns = commit_txns
ledger.root_hash = txn_root_serializer.serialize("1")
ledger.uncommitted_root_hash = "1"
ledger.uncommitted_size = 1
Expand All @@ -51,8 +56,8 @@ def db_manager(tconf):
ledger.committed_root_hash = "-1"
ledger.append_txns_metadata = lambda txns, txn_time: [append_txn_metadata(txn, 2, txn_time, 2) for txn in txns]
ledger.appendTxns = lambda x: (None, x)
db_manager.register_new_database(TOKEN_LEDGER_ID, ledger, PruningState(storage))
return db_manager
_db_manager.register_new_database(TOKEN_LEDGER_ID, ledger, PruningState(storage))
return _db_manager


@pytest.yield_fixture(scope="module")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sovtokenfees.static_fee_req_handler import txn_root_serializer


def test_token_batch_handler_commit_batch(utxo_batch_handler, utxo_cache):
def test_utxo_batch_handler_commit_batch(utxo_batch_handler, utxo_cache):
utxo_cache.set('1', '2')
ThreePcBatch = namedtuple("ThreePcBatch", "state_root valid_digests txn_root")
three_ps_batch = ThreePcBatch(state_root=b58decode("1".encode()), valid_digests=["1"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import namedtuple


def test_token_batch_handler_post_batch_applied(utxo_batch_handler, utxo_cache):
def test_utxo_batch_handler_post_batch_applied(utxo_batch_handler, utxo_cache):
utxo_cache.set('1', '2')
ThreePcBatch = namedtuple("ThreePcBatch", "state_root")
three_ps_batch = ThreePcBatch(state_root="1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sovtoken import TOKEN_LEDGER_ID


def test_token_batch_handler_post_batch_rejected(utxo_batch_handler, utxo_cache):
def test_utxo_batch_handler_post_batch_rejected(utxo_batch_handler, utxo_cache):
utxo_cache.set('1', '2')
ThreePcBatch = namedtuple("ThreePcBatch", "state_root")
three_ps_batch = ThreePcBatch(state_root="1")
Expand Down
39 changes: 17 additions & 22 deletions sovtokenfees/sovtokenfees/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from plenum.common.constants import NYM, STEWARD, TARGET_NYM, TRUSTEE_STRING
from sovtoken.test.helpers import libloader


import pytest
from enum import Enum, unique

Expand All @@ -23,7 +22,6 @@
)
from sovtoken.main import integrate_plugin_in_node as enable_token


from sovtokenfees.main import integrate_plugin_in_node as enable_fees
from sovtokenfees.constants import MAX_FEE_OUTPUTS
from sovtokenfees import CLIENT_REQUEST_FIELDS
Expand All @@ -44,10 +42,6 @@
from plenum.test.conftest import get_data_for_role


from stp_core.common.log import Logger
Logger().enableStdLogging()


@unique
class MintStrategy(Enum):
first_only = 1 # mint only for the first address
Expand Down Expand Up @@ -94,6 +88,7 @@ def __call__(self, *args, **kwargs):
# ######################
8


@pytest.fixture(scope="module")
def fees(request):
default_fees = {
Expand Down Expand Up @@ -184,17 +179,17 @@ def sdk_wallet_steward(sdk_wallet_handle, sdk_stewards):

@pytest.fixture(scope="module")
def helpers(
nodeSetWithIntegratedTokenPlugin,
looper,
sdk_pool_handle,
trustee_wallets,
steward_wallets,
sdk_wallet_client,
sdk_wallet_steward,
libsovtoken,
sdk_wallet_handle,
sdk_trustees,
sdk_stewards
nodeSetWithIntegratedTokenPlugin,
looper,
sdk_pool_handle,
trustee_wallets,
steward_wallets,
sdk_wallet_client,
sdk_wallet_steward,
libsovtoken,
sdk_wallet_handle,
sdk_trustees,
sdk_stewards
):
return form_helpers(
nodeSetWithIntegratedTokenPlugin,
Expand Down Expand Up @@ -225,7 +220,6 @@ def address_main_inner(helpers, libsovtoken):
return helpers.inner.wallet.create_address()



@pytest.fixture(scope="module")
def trustee_wallets(trustee_data, looper, sdk_pool_data):
return build_wallets_from_data(trustee_data)
Expand Down Expand Up @@ -275,6 +269,7 @@ def xfer_addresses(helpers, libsovtoken):
def addresses(helpers, addresses_num):
return helpers.wallet.create_new_addresses(addresses_num)


@pytest.fixture
def mint_amount_spec(request, addresses, mint_strategy, mint_amount):
amounts = {addr: 0 for addr in addresses}
Expand Down Expand Up @@ -341,8 +336,8 @@ def wrapped(addresses=None, inputs_strategy=None, txn_type=None):

@pytest.fixture
def prepare_outputs(
helpers, outputs_strategy, transfer_amount,
io_addresses, prepare_inputs, fees
helpers, outputs_strategy, transfer_amount,
io_addresses, prepare_inputs, fees
):
_outputs_strategy = outputs_strategy

Expand All @@ -366,7 +361,7 @@ def wrapped(fee=None, txn_type=None, inputs=None, addresses=None, outputs_strate

@pytest.fixture
def send_and_check_xfer(
looper, helpers, prepare_inputs, prepare_outputs, fees,
looper, helpers, prepare_inputs, prepare_outputs, fees,
):
def wrapped(inputs=None, outputs=None):
inputs = prepare_inputs(txn_type=XFER_PUBLIC) if inputs is None else inputs
Expand All @@ -379,7 +374,7 @@ def wrapped(inputs=None, outputs=None):

@pytest.fixture
def send_and_check_nym(
looper, helpers, prepare_inputs, prepare_outputs, fees,
looper, helpers, prepare_inputs, prepare_outputs, fees,
):
def wrapped(inputs=None, outputs=None):
inputs = prepare_inputs(txn_type=NYM) if inputs is None else inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ def test_fee_batch_handler_commit_batch(fee_batch_handler, fees_tracker):
fee_batch_handler.commit_batch(three_pc_batch, prev_res)
assert not len(utxo_cache.current_batch_ops)
assert not len(utxo_cache.un_committed)
assert fee_batch_handler.token_ledger.committed_root_hash == fee_batch_handler.token_ledger.uncommitted_root_hash
assert fee_batch_handler.token_state.headHash == fee_batch_handler.token_state.committedHeadHash