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 after req handlers integration #276

Merged
merged 16 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
2 changes: 1 addition & 1 deletion devops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ifeq ($(SRC_DIR_NAME),sovtoken)
# pypi: indy-plenum
# apt: indy-plenum (stable component)

FPM_P_DEPENDS := indy-node(=1.9.0~dev1014)
FPM_P_DEPENDS := indy-node(=1.9.0~dev1018)
FPM_ARGS := --no-python-dependencies $(FPM_ARGS)
endif

Expand Down
2 changes: 1 addition & 1 deletion sovtoken/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'*.css', '*.ico', '*.png', 'LICENSE', 'LEGAL', 'sovtoken']},
include_package_data=True,

install_requires=['indy-node==1.9.0.dev1014'],
install_requires=['indy-node==1.9.0.dev1018'],

setup_requires=['pytest-runner'],
extras_require={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sovtoken.types import Output
from sovtoken.util import SortedItems

from common.serializers.serialization import state_roots_serializer, proof_nodes_serializer
from sovtokenfees.serializers import state_roots_serializer, proof_nodes_serializer
from plenum.common.constants import MULTI_SIGNATURE, ROOT_HASH, PROOF_NODES, STATE_PROOF
from plenum.common.exceptions import InvalidClientRequest
from plenum.common.request import Request
Expand All @@ -34,6 +34,10 @@ def static_validation(self, request: Request):
request.reqId,
error)

@staticmethod
def create_state_key(address: str, seq_no: int) -> bytes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some consistency here.
We have already defined this method in https://github.com/sovrin-foundation/token-plugin/blob/master/sovtoken/sovtoken/request_handlers/token_utils.py#L30
We should either use the one in token_utils.py either delete it and use only the one here.
By the way, this is a utility method and don't see any reason to keep it in this class.

return ':'.join([address, str(seq_no)]).encode()

def get_result(self, request: Request):
address = request.operation[ADDRESS]
encoded_root_hash = state_roots_serializer.serialize(
Expand Down
6 changes: 3 additions & 3 deletions sovtoken/sovtoken/test/auth_map/test_auth_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from indy_common.authorize.auth_constraints import AuthConstraint
from sovtoken.sovtoken_auth_map import sovtoken_auth_map, add_mint

from indy_node.server.config_req_handler import ConfigReqHandler

from indy_common.constants import CONSTRAINT

from indy_common.authorize.auth_map import auth_map

from indy_node.server.request_handlers.config_req_handlers.auth_rule.static_auth_rule_helper import StaticAuthRuleHelper
from plenum.common.constants import STEWARD, TXN_TYPE, DATA
from plenum.common.exceptions import RequestRejectedException

Expand Down Expand Up @@ -90,7 +90,7 @@ def test_auth_mint(helpers,
result = resp[0][1]["result"][DATA]
for i, (auth_key, constraint) in enumerate(full_auth_map.items()):
rule = result[i]
assert auth_key == ConfigReqHandler.get_auth_key(rule)
assert auth_key == StaticAuthRuleHelper.get_auth_key(rule)
if constraint is None:
assert {} == rule[CONSTRAINT]
else:
Expand Down
2 changes: 1 addition & 1 deletion sovtoken/sovtoken/test/req_handlers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from base58 import b58decode
from sovtoken.constants import UTXO_CACHE_LABEL
from sovtokenfees.static_fee_req_handler import txn_root_serializer
from sovtokenfees.serializers import txn_root_serializer

from indy_node.test.request_handlers.helper import get_fake_ledger
from sovtoken import TOKEN_LEDGER_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from indy.did import create_and_store_my_did
from indy.ledger import multi_sign_request

from indy_node.test.conftest import write_auth_req_validator, constraint_serializer, config_state
from plenum.common.txn_util import append_txn_metadata
from plenum.test.helper import sdk_json_to_request_object

from indy_common.test.auth.conftest import write_auth_req_validator, constraint_serializer, config_state
from plenum.test.testing_utils import FakeSomething


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple
from base58 import b58decode
from sovtokenfees.static_fee_req_handler import txn_root_serializer
from sovtokenfees.serializers import txn_root_serializer


def test_token_batch_handler_commit_batch(utxo_batch_handler, utxo_cache):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from sovtoken.sovtoken_auth_map import sovtoken_auth_map
from base58 import b58encode_check
from indy.payment import build_payment_req
from indy_node.test.conftest import write_auth_req_validator, constraint_serializer, config_state, idr_cache
from sovtoken.test.helper import libsovtoken_address_to_address

from indy_common.test.auth.conftest import write_auth_req_validator, constraint_serializer, config_state, idr_cache
from plenum.common.txn_util import append_txn_metadata
from plenum.test.helper import sdk_json_to_request_object

Expand Down
7 changes: 4 additions & 3 deletions sovtoken/sovtoken/test/test_state_proof.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from sovtoken.request_handlers.token_utils import create_state_key
from sovtoken.request_handlers.write_request_handler.xfer_handler import XferHandler

from storage.kv_in_memory import KeyValueStorageInMemory

from state.db.persistent_db import PersistentDB

from sovtoken.token_req_handler import TokenReqHandler

from common.serializers.serialization import state_roots_serializer

from plenum.common.constants import STATE_PROOF, PROOF_NODES, ROOT_HASH
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_state_proof(public_minting, looper, # noqa
encoded = {}
outputs = res[OUTPUTS]
for out in outputs:
state_key = TokenReqHandler.create_state_key(out["address"], out["seqNo"])
state_key = create_state_key(out["address"], out["seqNo"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a method from GetUtxoHandler?

encoded[state_key] = rlp_encode([str(out["amount"])])
proof_nodes = decode_proof(res[STATE_PROOF][PROOF_NODES])
client_trie = Trie(PersistentDB(KeyValueStorageInMemory()))
Expand Down
4 changes: 2 additions & 2 deletions sovtoken/sovtoken/test/test_token_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import base58
import pytest
from sovtoken.request_handlers.read_req_handler.get_utxo_handler import GetUtxoHandler
from sovtoken.request_handlers.token_utils import commit_to_utxo_cache
from sovtoken.test.helper import libsovtoken_address_to_address
from sovtoken.test.helpers.helper_general import utxo_from_addr_and_seq_no
Expand All @@ -18,7 +19,6 @@
OUTPUTS, TOKEN_LEDGER_ID, UTXO_CACHE_LABEL, XFER_PUBLIC)
from sovtoken.exceptions import ExtraFundsError, InsufficientFundsError, TokenValueError
from sovtoken.test.txn_response import TxnResponse, get_sorted_signatures
from sovtoken.token_req_handler import TokenReqHandler
from sovtoken.types import Output

# Test Constants
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_token_req_handler_update_state_XFER_PUBLIC_success(
xfer_handler_a.dynamic_validation(request)
xfer_handler_a.update_state(txn, None, request)

state_key = TokenReqHandler.create_state_key(libsovtoken_address_to_address(address1), seq_no)
state_key = GetUtxoHandler.create_state_key(libsovtoken_address_to_address(address1), seq_no)
utxo_cache = xfer_handler_a.database_manager.get_store(UTXO_CACHE_LABEL)
key = utxo_cache._create_key(Output(libsovtoken_address_to_address(address1), seq_no, 60))
assert utxo_cache._store._has_key(key)
Expand Down
21 changes: 11 additions & 10 deletions sovtoken/sovtoken/test/unittests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import pytest
from sovtoken.request_handlers.token_utils import validate_given_inputs_outputs

from plenum.common.exceptions import InvalidClientMessageException

from sovtoken.exceptions import ExtraFundsError
from sovtoken.token_req_handler import TokenReqHandler


def test_xfer_public_txn_equal():
TokenReqHandler._validate_xfer_public_txn(None, 1, 1)
TokenReqHandler._validate_xfer_public_txn(None, 10, 10)
TokenReqHandler._validate_xfer_public_txn(None, 100, 100)
TokenReqHandler._validate_xfer_public_txn(None, 100000000000000, 100000000000000)
TokenReqHandler._validate_xfer_public_txn(None, 9223372036854775807, 9223372036854775807)
TokenReqHandler._validate_xfer_public_txn(None, 9223372036854775807000, 9223372036854775807000)
validate_given_inputs_outputs(1, 1, 1, None)
validate_given_inputs_outputs(10, 10, 10, None)
validate_given_inputs_outputs(100, 100, 100, None)
validate_given_inputs_outputs(100000000000000, 100000000000000, 100000000000000, None)
validate_given_inputs_outputs(9223372036854775807, 9223372036854775807, 9223372036854775807, None)
validate_given_inputs_outputs(9223372036854775807000, 9223372036854775807000, 9223372036854775807000, None)


def test_xfer_public_txn_inputs_not_greater():
with pytest.raises(ExtraFundsError):
TokenReqHandler._validate_xfer_public_txn(None, 2, 1)
validate_given_inputs_outputs(2, 1, 1, None)

with pytest.raises(InvalidClientMessageException):
TokenReqHandler._validate_xfer_public_txn(None, 1, 2)
validate_given_inputs_outputs(1, 2, 2, None)

with pytest.raises(InvalidClientMessageException):
TokenReqHandler._validate_xfer_public_txn(None, 100000000000000000000000, 100000000000000000000001)
validate_given_inputs_outputs(100000000000000000000000, 100000000000000000000001, 100000000000000000000001, None)
Loading