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 test_update_txn_author_agreement( config_req_handler: ConfigReqHandler, taa_input_data, taa_expected_state_data, taa_expected_digests ): """ `update_txn_author_agreement` updates state properly """ state = config_req_handler.state written = [] 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 for data in taa_input_data: config_req_handler.update_txn_author_agreement( data.text, data.version, data.seq_no, data.txn_time) written.append(data.version) digest = taa_expected_digests[data.version] assert state.get( ConfigReqHandler._state_path_taa_latest(), isCommitted=False ) == digest.encode() for version in taa_expected_state_data: _check_state(version)
def test_state_path_taa_latest(): assert ConfigReqHandler._state_path_taa_latest() == b'taa:v:latest'