예제 #1
0
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
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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()
예제 #5
0
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