def test_make_messages_builds_on_view( test_string, block_justification, test_weight, genesis_protocol ): state_lang = StateLanguage(test_weight, genesis_protocol, False) state_lang.parse(test_string) global_view = state_lang.network.global_view for b in block_justification: block = state_lang.messages[b] assert len(block.justification) == len(block_justification[b]) for validator_name in block_justification[b]: block_in_justification = block_justification[b][validator_name] validator = state_lang.validator_set.get_validator_by_name(validator_name) if block_in_justification: message_hash = block.justification[validator] justification_message = global_view.justified_messages[message_hash] if block_in_justification == "GEN": assert global_view.genesis_block == justification_message else: assert state_lang.messages[block_in_justification] == justification_message
def test_send_updates_val_view_genesis_protocols( test_string, test_weight, num_messages_per_view, message_keys, genesis_protocol ): state_lang = StateLanguage(test_weight, genesis_protocol, False) state_lang.parse(test_string) for validator_name in num_messages_per_view: validator = state_lang.validator_set.get_validator_by_name(validator_name) assert len(validator.view.justified_messages) == num_messages_per_view[validator_name] for message_name in message_keys[validator_name]: assert state_lang.messages[message_name] in validator.view.justified_messages.values()
def test_init(protocol, test_weight): state_lang = StateLanguage(test_weight, protocol, False) assert isinstance(state_lang.plot_tool, protocol.PlotTool) assert len(state_lang.validator_set) == len(test_weight) assert state_lang.validator_set.validator_weights() == set(test_weight.values()) assert state_lang.validator_set.weight() == sum(test_weight.values()) assert isinstance(state_lang.network, Network)
def test_parse_only_valid_tokens(test_string, test_weight, error, protocol): state_lang = StateLanguage(test_weight, protocol, False) if isinstance(error, type) and issubclass(error, Exception): with pytest.raises(error): state_lang.parse(test_string) return state_lang.parse(test_string)
def test_parse_only_valid_val_and_messages(test_string, test_weight, exception, protocol): state_lang = StateLanguage(test_weight, protocol, False) if exception: with pytest.raises(Exception): state_lang.parse(test_string) return state_lang.parse(test_string)
def test_allows_new_handlers_to_register(handler, error, protocol, test_weight, example_function): state_lang = StateLanguage(test_weight, protocol, False) if isinstance(error, type) and issubclass(error, Exception): with pytest.raises(error): state_lang.register_handler(handler, example_function) return state_lang.register_handler(handler, example_function) assert callable(state_lang.handlers[handler]) assert state_lang.handlers[handler] == example_function
def test_registers_handlers(protocol, test_weight): state_lang = StateLanguage(test_weight, protocol, False) assert callable(state_lang.make_message) assert callable(state_lang.make_invalid) assert callable(state_lang.send_message) assert callable(state_lang.plot) assert callable(state_lang.check_estimate) assert callable(state_lang.check_safe) assert callable(state_lang.check_unsafe) assert state_lang.make_message == state_lang.handlers['M'] assert state_lang.make_invalid == state_lang.handlers['I'] assert state_lang.send_message == state_lang.handlers['S'] assert state_lang.plot == state_lang.handlers['P'] assert state_lang.check_estimate == state_lang.handlers['CE'] assert state_lang.check_safe == state_lang.handlers['CS'] assert state_lang.check_unsafe == state_lang.handlers['CU']
def test_make_adds_to_global_view_( test_string, test_weight, num_blocks, exception, protocol ): state_lang = StateLanguage(test_weight, protocol, False) num_inital_blocks = len(state_lang.network.global_view.justified_messages) if exception: with pytest.raises(Exception, match=exception): state_lang.parse(test_string) return state_lang.parse(test_string) assert len(state_lang.network.global_view.justified_messages) == num_blocks + num_inital_blocks
def test_init_validators_have_only_inital_messages(protocol, test_weight): state_lang = StateLanguage(test_weight, protocol, False) for validator in state_lang.network.validator_set: assert len(validator.view.justified_messages) == 1