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-2171: Test for off_ledger_signature #283

Merged
merged 7 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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.1~dev1040)
FPM_P_DEPENDS := indy-node(=1.9.1~dev1042)
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.1.dev1040'],
install_requires=['indy-node==1.9.1.dev1042'],

setup_requires=['pytest-runner'],
extras_require={
Expand Down
10 changes: 5 additions & 5 deletions sovtoken/sovtoken/client_authnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from base58 import b58decode

from common.serializers.serialization import serialize_msg_for_signing
from plenum.common.constants import TXN_TYPE
from plenum.common.constants import TXN_TYPE, IDENTIFIER
from plenum.common.exceptions import (CouldNotAuthenticate,
InsufficientCorrectSignatures,
InvalidSignatureFormat)
Expand Down Expand Up @@ -63,13 +63,13 @@ def authenticate_xfer(self, req_data, verifier):
# ------------------------------------------------------------------------------------
# Gets verkey from payment address
# Raises UnknownIdentifier if it is not a valid base58 value
def getVerkey(self, identifier):
if len(identifier) not in (21, 22):
vk = address_to_verkey(identifier)
def getVerkey(self, ident, request):
if len(ident) not in (21, 22):
vk = address_to_verkey(ident)
if len(vk) in (43, 44):
# Address is the 32 byte verkey
return vk
return super().getVerkey(identifier)
return super().getVerkey(ident, request)

@staticmethod
def verify_signtures_on_payments(inputs, outputs, signatures, verifier,
Expand Down
7 changes: 4 additions & 3 deletions sovtoken/sovtoken/test/test_client_authnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sovtoken.test.helpers.helper_general import utxo_from_addr_and_seq_no
from sovtoken.test.helpers.helper_request import SEC_PER_DAY

from indy_common.types import Request
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.exceptions import UnknownIdentifier, InvalidSignatureFormat, InsufficientCorrectSignatures, \
CouldNotAuthenticate
Expand Down Expand Up @@ -333,7 +334,7 @@ def test_getVerkey_success(node):
ACCEPTABLE_QUERY_TYPES,
ACCEPTABLE_ACTION_TYPES,
node[0].states[DOMAIN_LEDGER_ID])
ver_key = token_authnr.getVerkey(VALID_IDENTIFIER)
ver_key = token_authnr.getVerkey(VALID_IDENTIFIER, Request())
assert len(ver_key) == 23
assert ver_key[0] == '~'

Expand All @@ -346,7 +347,7 @@ def test_getVerkey_pay_address_success(node):
node[0].states[DOMAIN_LEDGER_ID])
# TODO change these to indicate they are addresses
identifier_43 = 'sjw1ceG7wtym3VcnyaYtf1xo37gCUQHDR5VWcKWNPLRZ1X8eC'
ver_key = token_authnr.getVerkey(identifier_43)
ver_key = token_authnr.getVerkey(identifier_43, Request())
assert ver_key == '8kjqqnF3m6agp9auU7k4TWAhuGygFAgPzbNH3shp4HFL'


Expand All @@ -358,7 +359,7 @@ def test_getVerkey_invalid_identifier(node):
node[0].states[DOMAIN_LEDGER_ID])
identifier_invalid = 'INVALID_IDENTIFIER'
with pytest.raises(UnknownIdentifier):
token_authnr.getVerkey(identifier_invalid)
token_authnr.getVerkey(identifier_invalid, Request())


# -------------------------Test get_xfer_ser_data method----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json

import pytest
from indy.did import create_and_store_my_did
from indy.ledger import build_nym_request

from indy_common.authorize.auth_actions import ADD_PREFIX
from indy_common.authorize.auth_constraints import AuthConstraint, OFF_LEDGER_SIGNATURE, AuthConstraintOr
from indy_common.constants import CONSTRAINT
from indy_node.test.helper import build_auth_rule_request_json, sdk_send_and_check_req_json
from sovtoken.constants import AMOUNT
from sovtoken.test.helpers.helper_general import utxo_from_addr_and_seq_no
from sovtokenfees.constants import FEES_FIELD_NAME
from sovtokenfees.test.constants import txn_type_to_alias
from sovtokenfees.test.helper import get_amount_from_token_txn, add_fees_request_with_address

from indy_common.types import Request
from plenum.common.constants import ROLE, VERKEY, NYM, TRUSTEE
from plenum.common.types import OPERATION
from plenum.common.util import randomString
from plenum.server.request_handlers.utils import get_nym_details
from plenum.test.pool_transactions.helper import sdk_add_new_nym

NEW_ROLE = None


@pytest.fixture(scope='function')
def nym_txn_data(looper, sdk_wallet_client):
seed = randomString(32)

wh, _ = sdk_wallet_client
sender_did, sender_verkey = \
looper.loop.run_until_complete(create_and_store_my_did(wh, json.dumps({'seed': seed})))
return wh, randomString(5), sender_did, sender_verkey


@pytest.fixture(scope='function')
def changed_auth_rule(looper, sdk_pool_handle, sdk_wallet_trustee, fees_set):
constraint = AuthConstraintOr(auth_constraints=[AuthConstraint(role='*',
sig_count=1,
off_ledger_signature=True,
metadata={FEES_FIELD_NAME: txn_type_to_alias[NYM]}),
AuthConstraint(role=TRUSTEE, sig_count=1)
])

req = build_auth_rule_request_json(
looper, sdk_wallet_trustee[1],
auth_action=ADD_PREFIX,
auth_type=NYM,
field=ROLE,
old_value=None,
new_value=NEW_ROLE,
constraint=constraint.as_dict
)

req = json.loads(req)
req[OPERATION][CONSTRAINT]['auth_constraints'][0][OFF_LEDGER_SIGNATURE] = True
req = json.dumps(req)

sdk_send_and_check_req_json(looper, sdk_pool_handle, sdk_wallet_trustee, req)


def test_create_did_without_endorser_payment(looper, nodeSetWithIntegratedTokenPlugin, nym_txn_data, sdk_pool_handle,
fees_set, address_main, mint_tokens, changed_auth_rule,
sdk_wallet_trustee, helpers):
sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee)

wh, alias, sender_did, sender_verkey = nym_txn_data
req = looper.loop.run_until_complete(
build_nym_request(sender_did, sender_did, sender_verkey, alias, NEW_ROLE))

amount = get_amount_from_token_txn(mint_tokens)
init_seq_no = 1
utxos = [{"source": utxo_from_addr_and_seq_no(address_main, init_seq_no),
AMOUNT: amount}]
req = Request(**json.loads(req))
req = add_fees_request_with_address(
helpers,
fees_set,
req,
address_main,
utxos=utxos
)

rep = helpers.sdk.send_and_check_request_objects([req], wallet=(wh, sender_did))

details = get_nym_details(nodeSetWithIntegratedTokenPlugin[0].states[1], sender_did, is_committed=True)
assert details[ROLE] == NEW_ROLE
assert details[VERKEY] == sender_verkey