Skip to content

Commit

Permalink
[INDY-2302] add test for checking revoery with various TXN versions
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Nikitin <[email protected]>
  • Loading branch information
Andrew Nikitin committed Dec 17, 2019
1 parent 5fd4e75 commit e224523
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class TxnAuthorAgreementHandlerV1(TxnAuthorAgreementHandler):

def _update_txn_author_agreement(self, text, version, seq_no, txn_time, retired=False):
def _update_txn_author_agreement(self, digest, seq_no, txn_time, text, version, retired=False):
digest = StaticTAAHelper.taa_digest(text, version)
data = encode_state_value({
TXN_AUTHOR_AGREEMENT_TEXT: text,
Expand Down
23 changes: 23 additions & 0 deletions indy_node/test/txn_author_agreement/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json

import pytest
from indy.ledger import build_acceptance_mechanisms_request

from plenum.common.util import randomString
from plenum.test.helper import sdk_get_and_check_replies
from plenum.test.pool_transactions.helper import sdk_sign_and_send_prepared_request


@pytest.fixture(scope="module")
def setup_aml(looper, txnPoolNodeSet, taa_aml_request_module, sdk_pool_handle, sdk_wallet_trustee):
req = sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, taa_aml_request_module)
sdk_get_and_check_replies(looper, [req])


@pytest.fixture(scope="module")
def taa_aml_request_module(looper, sdk_pool_handle, sdk_wallet_trustee):
return looper.loop.run_until_complete(build_acceptance_mechanisms_request(
sdk_wallet_trustee[1],
json.dumps({
'Nice way': 'very good way to accept agreement'}),
randomString(), randomString()))
15 changes: 0 additions & 15 deletions indy_node/test/txn_author_agreement/test_node_taa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
from plenum.test.txn_author_agreement.helper import sdk_send_txn_author_agreement, sdk_get_txn_author_agreement


@pytest.fixture(scope="module")
def taa_aml_request_module(looper, sdk_pool_handle, sdk_wallet_trustee):
return looper.loop.run_until_complete(build_acceptance_mechanisms_request(
sdk_wallet_trustee[1],
json.dumps({
'Nice way': 'very good way to accept agreement'}),
randomString(), randomString()))


@pytest.fixture(scope="module")
def setup_aml(looper, txnPoolNodeSet, taa_aml_request_module, sdk_pool_handle, sdk_wallet_trustee):
req = sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, taa_aml_request_module)
sdk_get_and_check_replies(looper, [req])


def test_send_valid_txn_author_agreement_succeeds(looper, setup_aml, txnPoolNodeSet, sdk_pool_handle,
sdk_wallet_trustee, sdk_wallet_client):
text = randomString(1024)
Expand Down
104 changes: 104 additions & 0 deletions indy_node/test/txn_author_agreement/test_recover_taa_from_ledger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from plenum.common.constants import TXN_AUTHOR_AGREEMENT, TXN_AUTHOR_AGREEMENT_DIGEST, \
TXN_AUTHOR_AGREEMENT_VERSION, TXN_AUTHOR_AGREEMENT_TIMESTAMP, TXN_AUTHOR_AGREEMENT_RETIRED
import time

from indy_node.test.helper import start_stopped_node
from plenum.common.util import randomString
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


def test_recover_taa_from_ledger(txnPoolNodeSet,
sdk_pool_handle,
sdk_wallet_trustee,
looper,
monkeypatch,
setup_aml,
tconf,
tdir,
allPluginsPath):
orig_handlers = {}

# Step 1. Stop one node
node_to_stop = txnPoolNodeSet[-1]
rest_pool = txnPoolNodeSet[:-1]
disconnect_node_and_ensure_disconnected(looper,
txnPoolNodeSet,
node_to_stop.name,
stopNode=True)
looper.removeProdable(name=node_to_stop.name)

# Step 2. Path all the rest nodes for using old version TAA handler

# it's ugly but it works
globals()['CURRENT_TXN_VERSIONS'][TXN_AUTHOR_AGREEMENT] = '1'
for node in rest_pool:
handler = node.write_manager.request_handlers.get(TXN_AUTHOR_AGREEMENT)[0]
orig_handlers[node.name] = handler
handler_for_v_1 = node.write_manager._request_handlers_with_version.get((TXN_AUTHOR_AGREEMENT, "1"))[0]
node.write_manager.request_handlers[TXN_AUTHOR_AGREEMENT] = [handler_for_v_1]

# Step 3. Send TAA txn in old way
text = randomString(1024)
version_1 = randomString(16)

sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, text, version_1)

# Step 4. return original TAA handlers back

# it's ugly but it works
globals()['CURRENT_TXN_VERSIONS'][TXN_AUTHOR_AGREEMENT] = '2'
for node in rest_pool:
node.write_manager.request_handlers[TXN_AUTHOR_AGREEMENT] = [orig_handlers[node.name]]

# Step 5. Send another TAA txn in new way without optional parameters
text_2 = randomString(1024)
version_2 = randomString(16)
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, text_2, version_2)

# Step 6. Send another TAA txn in new way without optional parameter
text = randomString(1024)
version_3 = randomString(16)
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, text, version_3)

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

# Step 8. Ensure, that all TAAs was written
res_1 = sdk_get_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, version=version_1)[1]
assert TXN_AUTHOR_AGREEMENT_DIGEST not in res_1['result']['data']
assert TXN_AUTHOR_AGREEMENT_TIMESTAMP not in res_1['result']['data']
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 TXN_AUTHOR_AGREEMENT_TIMESTAMP in res_2['result']['data']
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_2
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_RETIRED] == retired_time
assert res_2['result']['data'][TXN_AUTHOR_AGREEMENT_TIMESTAMP] == retired_time - 20

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 TXN_AUTHOR_AGREEMENT_TIMESTAMP in res_3['result']['data']
assert res_3['result']['data'][TXN_AUTHOR_AGREEMENT_VERSION] == version_3

# Step 9. Return previous disconnected node back
node_to_stop = start_stopped_node(node_to_stop, looper,
tconf, tdir, allPluginsPath)
txnPoolNodeSet = rest_pool + [node_to_stop]

# Step 10. Ensure that all nodes have the same data
ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)

# Step 11. Send another taa txns for checking pool writability
text = randomString(1024)
version_4 = randomString(16)
sdk_send_txn_author_agreement(looper, sdk_pool_handle, sdk_wallet_trustee, text, version_4)

# Step 12. Ensure that all nodes have the same data
ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)

0 comments on commit e224523

Please sign in to comment.