def test_send_valid_txn_athr_agrmt_succeeds(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_trustee): req = looper.loop.run_until_complete( prepare_txn_author_agreement(sdk_wallet_trustee[1])) rep = sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, req) sdk_get_and_check_replies(looper, [rep]) req = json.loads(req) version = req[OPERATION][TXN_AUTHOR_AGREEMENT_VERSION] text = req[OPERATION][TXN_AUTHOR_AGREEMENT_TEXT] digest = ConfigReqHandler._taa_digest(version, text) # TODO: Replace this with get transaction ensure_all_nodes_have_same_data(looper, txnPoolNodeSet) for node in txnPoolNodeSet: config_req_handler = get_config_req_handler(node) assert config_req_handler.get_taa_digest() == digest.encode() assert config_req_handler.get_taa_digest(version) == digest.encode() taa = config_req_handler.state.get( ConfigReqHandler._state_path_taa_digest(digest)) assert taa is not None taa = json.loads(taa.decode()) assert taa[TXN_AUTHOR_AGREEMENT_VERSION] == version assert taa[TXN_AUTHOR_AGREEMENT_TEXT] == text
def test_multiple_update_txn_author_agreement(config_req_handler: ConfigReqHandler): text_v1 = 'Some agreement' agreement_v1 = {TXN_AUTHOR_AGREEMENT_VERSION: 'v1', TXN_AUTHOR_AGREEMENT_TEXT: text_v1} digest_v1 = ConfigReqHandler._taa_digest('v1', text_v1).encode() config_req_handler.update_txn_author_agreement(agreement_v1) assert config_req_handler.get_taa_digest(isCommitted=False) == digest_v1 assert config_req_handler.get_taa_digest(version='v1', isCommitted=False) == digest_v1 assert config_req_handler.get_taa_digest(version='v2', isCommitted=False) is None text_v2 = 'New agreement' agreement_v2 = {TXN_AUTHOR_AGREEMENT_VERSION: 'v2', TXN_AUTHOR_AGREEMENT_TEXT: text_v2} digest_v2 = ConfigReqHandler._taa_digest('v2', text_v2).encode() config_req_handler.update_txn_author_agreement(agreement_v2) assert config_req_handler.get_taa_digest(isCommitted=False) == digest_v2 assert config_req_handler.get_taa_digest(version='v1', isCommitted=False) == digest_v1 assert config_req_handler.get_taa_digest(version='v2', isCommitted=False) == digest_v2
def test_update_txn_author_agreement(config_req_handler: ConfigReqHandler): version = 'Some version' text = 'Some agreement' agreement = {TXN_AUTHOR_AGREEMENT_VERSION: version, TXN_AUTHOR_AGREEMENT_TEXT: text} digest = ConfigReqHandler._taa_digest(version, text) config_req_handler.update_txn_author_agreement(agreement) state = config_req_handler.state assert state.get(ConfigReqHandler._state_path_taa_latest(), isCommitted=False) == digest.encode() assert state.get(ConfigReqHandler._state_path_taa_version(version), isCommitted=False) == digest.encode() taa = state.get(ConfigReqHandler._state_path_taa_digest(digest), isCommitted=False) assert taa is not None taa = json.loads(taa.decode()) assert taa.get(TXN_AUTHOR_AGREEMENT_VERSION) == version assert taa.get(TXN_AUTHOR_AGREEMENT_TEXT) == text
def test_get_taa_digest(config_req_handler: ConfigReqHandler): agreements = [{TXN_AUTHOR_AGREEMENT_VERSION: randomString(8), TXN_AUTHOR_AGREEMENT_TEXT: randomString(32)} for _ in range(10)] agreements = [(payload, ConfigReqHandler._taa_digest(payload[TXN_AUTHOR_AGREEMENT_VERSION], payload[TXN_AUTHOR_AGREEMENT_TEXT])) for payload in agreements] versions = [payload.get(TXN_AUTHOR_AGREEMENT_VERSION) for payload, _ in agreements] state = config_req_handler.state for payload, digest in agreements: config_req_handler.update_txn_author_agreement(payload) assert config_req_handler.get_taa_digest(isCommitted=False) == \ state.get(ConfigReqHandler._state_path_taa_latest(), isCommitted=False) for version in versions: assert config_req_handler.get_taa_digest(version=version, isCommitted=False) == \ state.get(ConfigReqHandler._state_path_taa_version(version), isCommitted=False)
def calc_taa_digest(text, version): return ConfigReqHandler._taa_digest(text, version)
def test_taa_digest(): assert ConfigReqHandler._taa_digest('some_version', 'some_text') == \ "fb2ea9d28380a021ec747c442d62a68952b4b5813b45671098ad2b684b2f4646"