forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial version of acceptance test framework (hyperledger#347)
* Added an initial version of an acceptance test framework. * Test Automation: - Added a test for Acceptance Test Scenario 9 (Remove / Add Roles). - Removed example system tests. - Corrected setup.py file. - Updated python3-indy dependency.
- Loading branch information
Showing
8 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"data":{"alias":"Node1","client_ip":"127.0.0.1","client_port":9702,"node_ip":"127.0.0.1","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv","identifier":"Th7MpTaRZVRYnPiabds81Y","txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62","type":"0"} | ||
{"data":{"alias":"Node2","client_ip":"127.0.0.1","client_port":9704,"node_ip":"127.0.0.1","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb","identifier":"EbP4aYNeTHL6q385GuVpRV","txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc","type":"0"} | ||
{"data":{"alias":"Node3","client_ip":"127.0.0.1","client_port":9706,"node_ip":"127.0.0.1","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya","identifier":"4cU41vWW82ArfxJxHkzXPG","txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4","type":"0"} | ||
{"data":{"alias":"Node4","client_ip":"127.0.0.1","client_port":9708,"node_ip":"127.0.0.1","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA","identifier":"TWwCRQRZ2ZHMJFn9TzLp7W","txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008","type":"0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='indy-node-acceptance', | ||
version='0.0.1', | ||
description='Acceptance tests for Hyperledger Indy-Node', | ||
url='https://github.com/hyperledger/indy-node/tree/master/acceptance', | ||
author='Nikita Spivachuk', | ||
author_email='[email protected]', | ||
license='MIT/Apache-2.0', | ||
install_requires=['python3-indy==1.0.0-dev-177', 'pytest', 'pytest-asyncio', | ||
'pytest-runner'], | ||
setup_requires=['pytest-runner'] | ||
) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import json | ||
|
||
from indy import ledger, signus | ||
|
||
|
||
class Client: | ||
def __init__(self, pool_handle, wallet_handle): | ||
self._pool_handle = pool_handle | ||
self._wallet_handle = wallet_handle | ||
self._active_did = None | ||
|
||
async def use_did(self, did): | ||
self._active_did = did | ||
|
||
async def new_did(self, did=None, seed=None): | ||
did_params = {} | ||
if did: | ||
did_params['did'] = did | ||
if seed: | ||
did_params['seed'] = seed | ||
|
||
did, verkey, _ = \ | ||
await signus.create_and_store_my_did(self._wallet_handle, | ||
json.dumps(did_params)) | ||
|
||
await self.use_did(did) | ||
|
||
return did, verkey | ||
|
||
async def send_nym(self, dest, verkey=None, role=None): | ||
nym_req_json = await ledger.build_nym_request(self._active_did, | ||
dest, verkey, None, role) | ||
await self._sign_and_submit_request(nym_req_json) | ||
|
||
async def send_get_nym(self, dest): | ||
get_nym_req_json = await ledger.build_get_nym_request(self._active_did, | ||
dest) | ||
return await self._submit_request(get_nym_req_json) | ||
|
||
async def _sign_and_submit_request(self, request_json): | ||
response_json = \ | ||
await ledger.sign_and_submit_request(self._pool_handle, | ||
self._wallet_handle, | ||
self._active_did, | ||
request_json) | ||
return Client._extract_result(response_json) | ||
|
||
async def _submit_request(self, request_json): | ||
response_json = await ledger.submit_request(self._pool_handle, | ||
request_json) | ||
return Client._extract_result(response_json) | ||
|
||
@staticmethod | ||
def _extract_result(response_json): | ||
response = json.loads(response_json) | ||
|
||
if 'result' in response and 'data' in response['result']: | ||
return json.loads(response['result']['data']) | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import json | ||
import os | ||
from shutil import rmtree | ||
|
||
import pytest | ||
from indy import pool, wallet | ||
|
||
from sovrin_acceptance.test.client import Client | ||
|
||
|
||
@pytest.fixture | ||
def pool_name(): | ||
return 'acceptance' | ||
|
||
|
||
@pytest.fixture | ||
def wallet_name(): | ||
return 'default' | ||
|
||
|
||
@pytest.fixture | ||
def base_dir_created(): | ||
base_dir = os.path.join(os.path.expanduser('~'), '.indy') | ||
|
||
if os.path.isdir(base_dir): | ||
rmtree(base_dir) | ||
elif os.path.isfile(base_dir): | ||
os.remove(base_dir) | ||
|
||
os.makedirs(base_dir) | ||
yield | ||
rmtree(base_dir) | ||
|
||
|
||
@pytest.fixture | ||
def pool_genesis_txn_path(): | ||
test_dir = os.path.dirname(os.path.realpath(__file__)) | ||
acceptance_dir = os.path.join(test_dir, os.pardir, os.pardir) | ||
return os.path.join(acceptance_dir, 'pool.txn') | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
@pytest.fixture | ||
def pool_ledger_created(base_dir_created, pool_name, pool_genesis_txn_path, | ||
event_loop): | ||
event_loop.run_until_complete(pool.create_pool_ledger_config( | ||
pool_name, | ||
json.dumps({ | ||
'genesis_txn': str(pool_genesis_txn_path) | ||
}))) | ||
yield | ||
event_loop.run_until_complete(pool.delete_pool_ledger_config(pool_name)) | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
@pytest.fixture | ||
def pool_handle(pool_ledger_created, pool_name, event_loop): | ||
pool_handle = event_loop.run_until_complete( | ||
pool.open_pool_ledger(pool_name, None)) | ||
yield pool_handle | ||
event_loop.run_until_complete(pool.close_pool_ledger(pool_handle)) | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
@pytest.fixture | ||
def wallet_created(base_dir_created, pool_ledger_created, | ||
pool_name, wallet_name, event_loop): | ||
event_loop.run_until_complete( | ||
wallet.create_wallet(pool_name, wallet_name, 'default', None, None)) | ||
yield | ||
event_loop.run_until_complete(wallet.delete_wallet(wallet_name, None)) | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
@pytest.fixture | ||
def wallet_handle(wallet_created, wallet_name, event_loop): | ||
wallet_handle = event_loop.run_until_complete( | ||
wallet.open_wallet(wallet_name, None, None)) | ||
yield wallet_handle | ||
event_loop.run_until_complete(wallet.close_wallet(wallet_handle)) | ||
|
||
|
||
@pytest.fixture | ||
def client(pool_handle, wallet_handle): | ||
return Client(pool_handle, wallet_handle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NO_ROLE_CODE = '' | ||
TRUSTEE_CODE = '0' | ||
STEWARD_CODE = '2' | ||
TGB_CODE = '100' | ||
TRUST_ANCHOR_CODE = '101' |
223 changes: 223 additions & 0 deletions
223
acceptance/sovrin_acceptance/test/test_remove_add_roles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
import pytest | ||
from indy import IndyError | ||
from indy.error import ErrorCode | ||
from pytest import raises | ||
|
||
from sovrin_acceptance.test.constants import TRUSTEE_CODE, STEWARD_CODE,\ | ||
TGB_CODE, TRUST_ANCHOR_CODE, NO_ROLE_CODE | ||
|
||
|
||
@pytest.mark.skip(reason='IS-347') | ||
@pytest.mark.asyncio | ||
async def test_remove_add_roles(client): | ||
|
||
# GENERATE DIDS AND VERKEYS | ||
|
||
test_trustee1_did, test_trustee1_verkey = \ | ||
await client.new_did(seed='TestTrustee100000000000000000000') | ||
test_trustee2_did, test_trustee2_verkey = \ | ||
await client.new_did(seed='TestTrustee200000000000000000000') | ||
test_steward1_did, test_steward1_verkey = \ | ||
await client.new_did(seed='TestSteward100000000000000000000') | ||
test_steward2_did, test_steward2_verkey = \ | ||
await client.new_did(seed='TestSteward200000000000000000000') | ||
test_steward3_did, test_steward3_verkey = \ | ||
await client.new_did(seed='TestSteward300000000000000000000') | ||
test_tgb1_did, test_tgb1_verkey = \ | ||
await client.new_did(seed='TestTGB1000000000000000000000000') | ||
test_trust_anchor1_did, test_trust_anchor1_verkey = \ | ||
await client.new_did(seed='TestTrustAnchor10000000000000000') | ||
test_trust_anchor2_did, test_trust_anchor2_verkey = \ | ||
await client.new_did(seed='TestTrustAnchor20000000000000000') | ||
test_trust_anchor3_did, test_trust_anchor3_verkey = \ | ||
await client.new_did(seed='TestTrustAnchor30000000000000000') | ||
random_user1_did, random_user1_verkey = \ | ||
await client.new_did(seed='RandomUser1000000000000000000000') | ||
random_user2_did, random_user2_verkey = \ | ||
await client.new_did(seed='RandomUser2000000000000000000000') | ||
random_user3_did, random_user3_verkey = \ | ||
await client.new_did(seed='RandomUser3000000000000000000000') | ||
random_user4_did, random_user4_verkey = \ | ||
await client.new_did(seed='RandomUser4000000000000000000000') | ||
random_user5_did, random_user5_verkey = \ | ||
await client.new_did(seed='RandomUser5000000000000000000000') | ||
random_user6_did, random_user6_verkey = \ | ||
await client.new_did(seed='RandomUser6000000000000000000000') | ||
|
||
# TEST ROLE PERMISSIONS | ||
|
||
# ========================================================================== | ||
await client.new_did(seed='000000000000000000000000Trustee1') | ||
|
||
await client.send_nym(dest=test_trustee1_did, | ||
verkey=test_trustee1_verkey, | ||
role='TRUSTEE') | ||
test_trustee1_nym = await client.send_get_nym(test_trustee1_did) | ||
assert test_trustee1_nym['dest'] == test_trustee1_did | ||
assert test_trustee1_nym['verkey'] == test_trustee1_verkey | ||
assert test_trustee1_nym['role'] == TRUSTEE_CODE | ||
|
||
# ========================================================================== | ||
await client.use_did(test_trustee1_did) | ||
|
||
await client.send_nym(dest=test_steward1_did, | ||
verkey=test_steward1_verkey, | ||
role='STEWARD') | ||
test_steward1_nym = await client.send_get_nym(test_steward1_did) | ||
assert test_steward1_nym['dest'] == test_steward1_did | ||
assert test_steward1_nym['verkey'] == test_steward1_verkey | ||
assert test_steward1_nym['role'] == STEWARD_CODE | ||
|
||
await client.send_nym(dest=random_user3_did, | ||
verkey=random_user3_verkey) | ||
random_user3_nym = await client.send_get_nym(random_user3_did) | ||
assert random_user3_nym['dest'] == random_user3_did | ||
assert random_user3_nym['verkey'] == random_user3_verkey | ||
assert random_user3_nym['role'] == NO_ROLE_CODE | ||
|
||
await client.send_nym(dest=test_tgb1_did, | ||
verkey=test_tgb1_verkey, | ||
role='TGB') | ||
test_tgb1_nym = await client.send_get_nym(test_tgb1_did) | ||
assert test_tgb1_nym['dest'] == test_tgb1_did | ||
assert test_tgb1_nym['verkey'] == test_tgb1_verkey | ||
assert test_tgb1_nym['role'] == TGB_CODE | ||
|
||
# ========================================================================== | ||
await client.use_did(test_steward1_did) | ||
|
||
await client.send_nym(dest=test_trust_anchor1_did, | ||
verkey=test_trust_anchor1_verkey, | ||
role='TRUST_ANCHOR') | ||
test_trust_anchor1_nym = await client.send_get_nym(test_trust_anchor1_did) | ||
assert test_trust_anchor1_nym['dest'] == test_trust_anchor1_did | ||
assert test_trust_anchor1_nym['verkey'] == test_trust_anchor1_verkey | ||
assert test_trust_anchor1_nym['role'] == TRUST_ANCHOR_CODE | ||
|
||
await client.send_nym(dest=random_user4_did, | ||
verkey=random_user4_verkey) | ||
random_user4_nym = await client.send_get_nym(random_user4_did) | ||
assert random_user4_nym['dest'] == random_user4_did | ||
assert random_user4_nym['verkey'] == random_user4_verkey | ||
assert random_user4_nym['role'] == NO_ROLE_CODE | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_steward2_did, | ||
verkey=test_steward2_verkey, | ||
role='STEWARD') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trustee2_did, | ||
verkey=test_trustee2_verkey, | ||
role='TRUSTEE') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# ========================================================================== | ||
await client.use_did(test_trust_anchor1_did) | ||
|
||
await client.send_nym(dest=random_user1_did, | ||
verkey=random_user1_verkey) | ||
random_user1_nym = await client.send_get_nym(random_user1_did) | ||
assert random_user1_nym['dest'] == random_user1_did | ||
assert random_user1_nym['verkey'] == random_user1_verkey | ||
assert random_user1_nym['role'] == NO_ROLE_CODE | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trust_anchor2_did, | ||
verkey=test_trust_anchor2_verkey, | ||
role='TRUST_ANCHOR') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# TEST REMOVING ROLES | ||
|
||
# ========================================================================== | ||
await client.new_did(seed='000000000000000000000000Trustee1') | ||
|
||
await client.send_nym(dest=test_trustee1_did, | ||
role='') | ||
await client.send_nym(dest=test_steward1_did, | ||
role='') | ||
await client.send_nym(dest=test_tgb1_did, | ||
role='') | ||
await client.send_nym(dest=test_trust_anchor1_did, | ||
role='') | ||
|
||
# ========================================================================== | ||
await client.use_did(test_trustee1_did) | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trustee2_did, | ||
verkey=test_trustee2_verkey, | ||
role='TRUSTEE') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_steward2_did, | ||
verkey=test_steward2_verkey, | ||
role='STEWARD') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# ========================================================================== | ||
await client.use_did(test_steward1_did) | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trust_anchor2_did, | ||
verkey=test_trust_anchor2_verkey, | ||
role='TRUST_ANCHOR') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# TEST ADDING ROLES | ||
|
||
# ========================================================================== | ||
await client.new_did(seed='000000000000000000000000Trustee1') | ||
|
||
await client.send_nym(dest=test_trustee1_did, | ||
role='TRUSTEE') | ||
|
||
# ========================================================================== | ||
await client.use_did(test_trustee1_did) | ||
|
||
await client.send_nym(dest=test_steward1_did, | ||
role='STEWARD') | ||
await client.send_nym(dest=test_tgb1_did, | ||
role='TGB') | ||
|
||
# ========================================================================== | ||
await client.use_did(test_steward1_did) | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trust_anchor1_did, | ||
role='TRUST_ANCHOR') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_trustee1_did, | ||
role='') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# ========================================================================== | ||
await client.use_did(test_trustee1_did) | ||
|
||
await client.send_nym(dest=test_steward3_did, | ||
verkey=test_steward3_verkey, | ||
role='STEWARD') | ||
|
||
await client.send_nym(dest=test_steward2_did, | ||
verkey=test_steward2_verkey, | ||
role='STEWARD') | ||
|
||
# ========================================================================== | ||
await client.use_did(test_steward1_did) | ||
|
||
with raises(IndyError) as exInfo: | ||
await client.send_nym(dest=test_steward2_did, | ||
role='') | ||
assert exInfo.value.error_code == ErrorCode.LedgerInvalidTransaction | ||
|
||
# ========================================================================== | ||
await client.use_did(test_steward2_did) | ||
|
||
await client.send_nym(dest=test_trust_anchor3_did, | ||
verkey=test_trust_anchor3_verkey, | ||
role='TRUST_ANCHOR') |