Пример #1
0
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
Пример #2
0
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)
Пример #3
0
def test_get_taa_digest(
        config_req_handler: ConfigReqHandler, taa_input_data,
        taa_expected_data, taa_expected_digests
):
    """ `get_taa_digest` returns expected value """
    written = []
    for data in taa_input_data:
        config_req_handler.update_txn_author_agreement(*data)
        written.append(data.version)

        assert (
            config_req_handler.get_taa_digest(isCommitted=False) ==
            taa_expected_digests[data.version]
        )

        for version in taa_expected_data:
            digest = config_req_handler.get_taa_digest(
                version=version, isCommitted=False)
            assert (
                digest ==
                (taa_expected_digests[version] if version in written else None)
            )