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 _check_state(version): digest = taa_expected_digests[version] _digest = state.get( ConfigReqHandler._state_path_taa_version(version), isCommitted=False ) _data = state.get( ConfigReqHandler._state_path_taa_digest(digest), isCommitted=False ) if version in written: assert _digest == digest.encode() assert ( config_state_serializer.deserialize(_data) == taa_expected_state_data[version] ) else: assert _digest is None assert _data is None
def test_state_path_taa_version(): assert ConfigReqHandler._state_path_taa_version('some_version') == b'taa:v:some_version'