Skip to content

Commit

Permalink
Merge pull request hyperledger#1552 from Toktar/task-2297-get-taa-digest
Browse files Browse the repository at this point in the history
INDY-2316: update test_recover_taa_from_ledger
  • Loading branch information
Toktar authored Dec 25, 2019
2 parents a517cb4 + 5fcfe4e commit 064e968
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
50 changes: 33 additions & 17 deletions indy_node/test/txn_author_agreement/test_recover_taa_from_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from plenum.common.util import randomString, get_utc_epoch
from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data
from plenum.test.pool_transactions.helper import disconnect_node_and_ensure_disconnected
from plenum.test.txn_author_agreement.helper import sdk_send_txn_author_agreement, sdk_get_txn_author_agreement
from plenum.test.txn_author_agreement.helper import sdk_send_txn_author_agreement, sdk_get_txn_author_agreement, \
sdk_send_txn_author_agreement_disable


def test_recover_taa_from_ledger(txnPoolNodeSet,
Expand Down Expand Up @@ -42,8 +43,13 @@ def test_recover_taa_from_ledger(txnPoolNodeSet,

# Step 3. Send TAA txn in old way
text = randomString(1024)
version_0 = randomString(16)
res = sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_0, text)[1]
taa_0_ratification_ts = get_txn_time(res['result'])

version_1 = randomString(16)
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_1, text)
res = sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_1, text)[1]
taa_1_ratification_ts = get_txn_time(res['result'])

# Step 4. return original TAA handlers back

Expand All @@ -67,6 +73,7 @@ def test_recover_taa_from_ledger(txnPoolNodeSet,

# Step 7. Send taa updating for the second taa transaction (for checking txn with optional parameter)
retired_time = int(time.time()) + 20
retired_time_in_past = int(time.time()) - 20
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_2, retired=retired_time)

# Step 8. Ensure, that all TAAs was written
Expand All @@ -76,17 +83,10 @@ def test_recover_taa_from_ledger(txnPoolNodeSet,
assert res_1['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_1

res_2 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_2)[1]

assert TXN_AUTHOR_AGREEMENT_DIGEST in res_2['result']['data']
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_2
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_RETIREMENT_TS] == retired_time
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_RATIFICATION_TS] == ratified_2
check_result_contains_expected_taa_data(res_2, version_2, ratified_2, retired_time)

res_3 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_3)[1]

assert TXN_AUTHOR_AGREEMENT_DIGEST in res_3['result']['data']
assert res_3['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_3
assert res_3['result']['data'][TXN_AUTHOR_AGREEMENT_RATIFICATION_TS] == ratified_3
check_result_contains_expected_taa_data(res_3, version_3, ratified_3)

# Step 9. Return previous disconnected node back
node_to_stop = start_stopped_node(node_to_stop, looper,
Expand All @@ -106,11 +106,27 @@ def test_recover_taa_from_ledger(txnPoolNodeSet,
ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)

# Step 13. Retire TAA written using old handler, make sure ratification date is not spoiled
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_1, retired=retired_time)
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version_1, retired=retired_time_in_past)
res_1 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_1)[1]
check_result_contains_expected_taa_data(res_1, version_1, taa_1_ratification_ts, retired_time_in_past)

# Step 14. Disable TAAs written using old handler, make sure ratification date is not spoiled
disable_res = sdk_send_txn_author_agreement_disable(looper, sdk_pool_handle, sdk_wallet_trustee)[1]

res_0 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_0)[1]
check_result_contains_expected_taa_data(res_0, version_0, taa_0_ratification_ts, get_txn_time(disable_res['result']))

res_1 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_1)[1]
check_result_contains_expected_taa_data(res_1, version_1, taa_1_ratification_ts, retired_time_in_past)


def check_result_contains_expected_taa_data(result, version, ratification_ts, retired_time=None):
assert TXN_AUTHOR_AGREEMENT_DIGEST in result['result']['data']
assert TXN_AUTHOR_AGREEMENT_RATIFICATION_TS in result['result']['data']
assert result['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version
assert result['result']['data'][TXN_AUTHOR_AGREEMENT_RATIFICATION_TS] == ratification_ts
if retired_time:
assert result['result']['data'][TXN_AUTHOR_AGREEMENT_RETIREMENT_TS] == retired_time
else:
assert TXN_AUTHOR_AGREEMENT_RETIREMENT_TS not in result['result']['data']

assert TXN_AUTHOR_AGREEMENT_DIGEST in res_1['result']['data']
assert TXN_AUTHOR_AGREEMENT_RATIFICATION_TS in res_1['result']['data']
assert res_1['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_1
assert res_1['result']['data'][TXN_AUTHOR_AGREEMENT_RETIREMENT_TS] == retired_time
assert res_1['result']['data'][TXN_AUTHOR_AGREEMENT_RATIFICATION_TS] == get_txn_time(res_0['result'])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
data_files=[(
(BASE_DIR, ['data/nssm_original.exe'])
)],
install_requires=['indy-plenum==1.12.1.dev989',
install_requires=['indy-plenum==1.12.1.dev990',
'timeout-decorator==0.4.0',
'distro==1.3.0'],
setup_requires=['pytest-runner'],
Expand Down

0 comments on commit 064e968

Please sign in to comment.