Beispiel #1
0
def create_provider(handler_name: str, suite_name: str,
                    case_maker) -> gen_typing.TestProvider:
    def prepare_fn(configs_path: str) -> str:
        return "general"

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        for (case_name, case_fn) in case_maker():
            yield gen_typing.TestCase(fork_name=PHASE0,
                                      runner_name='ssz_generic',
                                      handler_name=handler_name,
                                      suite_name=suite_name,
                                      case_name=case_name,
                                      case_fn=case_fn)

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #2
0
def create_provider(tests_src, preset_name: str, pre_fork_name: str,
                    post_fork_name: str) -> gen_typing.TestProvider:
    def prepare_fn() -> None:
        return

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        return generate_from_tests(
            runner_name='transition',
            handler_name='core',
            src=tests_src,
            fork_name=post_fork_name,
            phase=pre_fork_name,
            preset_name=preset_name,
        )

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #3
0
def create_provider(fork_name, preset_name: str, seed: int,
                    mode: random_value.RandomizationMode, chaos: bool,
                    cases_if_random: int) -> gen_typing.TestProvider:
    def prepare_fn() -> None:
        return

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        count = cases_if_random if chaos or mode.is_changing() else 1
        spec = spec_targets[preset_name][fork_name]

        for (i, (name, ssz_type)) in enumerate(get_spec_ssz_types(spec)):
            yield from ssz_static_cases(fork_name, preset_name,
                                        seed * 1000 + i, name, ssz_type, mode,
                                        chaos, count)

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #4
0
def create_provider(config_name: str) -> gen_typing.TestProvider:
    def prepare_fn(configs_path: str) -> str:
        config_util.prepare_config(configs_path, config_name)
        reload(spec)
        return config_name

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        for (case_name, case_fn) in shuffling_test_cases():
            yield gen_typing.TestCase(fork_name=PHASE0,
                                      runner_name='shuffling',
                                      handler_name='core',
                                      suite_name='shuffle',
                                      case_name=case_name,
                                      case_fn=case_fn)

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #5
0
def create_provider(tests_src, preset_name: PresetBaseName,
                    phase: SpecForkName,
                    fork_name: SpecForkName) -> gen_typing.TestProvider:
    def prepare_fn() -> None:
        return

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        return generate_from_tests(
            runner_name='fork',
            handler_name='fork',
            src=tests_src,
            fork_name=fork_name,
            preset_name=preset_name,
            phase=phase,
        )

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #6
0
def create_provider(tests_src, config_name: str, pre_fork_name: str,
                    post_fork_name: str) -> gen_typing.TestProvider:
    def prepare_fn(configs_path: str) -> str:
        config_util.prepare_config(configs_path, config_name)
        reload(spec_phase0)
        reload(spec_altair)
        return config_name

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        return generate_from_tests(
            runner_name='transition',
            handler_name='core',
            src=tests_src,
            fork_name=post_fork_name,
            phase=pre_fork_name,
        )

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #7
0
def create_provider(fork_name, config_name: str, seed: int,
                    mode: random_value.RandomizationMode, chaos: bool,
                    cases_if_random: int) -> gen_typing.TestProvider:
    def prepare_fn(configs_path: str) -> str:
        # Apply changes to presets, this affects some of the vector types.
        config_util.prepare_config(configs_path, config_name)
        reload(spec_phase0)
        reload(spec_altair)
        return config_name

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        count = cases_if_random if chaos or mode.is_changing() else 1
        spec = spec_phase0
        if fork_name == ALTAIR:
            spec = spec_altair

        for (i, (name, ssz_type)) in enumerate(get_spec_ssz_types(spec)):
            yield from ssz_static_cases(fork_name, seed * 1000 + i, name,
                                        ssz_type, mode, chaos, count)

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #8
0
def create_provider(preset_name: PresetBaseName) -> gen_typing.TestProvider:
    def prepare_fn() -> None:
        return

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        if preset_name == MAINNET:
            spec = spec_mainnet
        elif preset_name == MINIMAL:
            spec = spec_minimal
        else:
            raise Exception(f"unrecognized preset: {preset_name}")
        for (case_name, case_fn) in shuffling_test_cases(spec):
            yield gen_typing.TestCase(fork_name=PHASE0,
                                      preset_name=preset_name,
                                      runner_name='shuffling',
                                      handler_name='core',
                                      suite_name='shuffle',
                                      case_name=case_name,
                                      case_fn=case_fn)

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
Beispiel #9
0
def create_provider(
    handler_name: str, test_case_fn: Callable[[], Iterable[Tuple[str,
                                                                 Dict[str,
                                                                      Any]]]]
) -> gen_typing.TestProvider:
    def prepare_fn(configs_path: str) -> str:
        # Nothing to load / change in spec. Maybe in future forks.
        # Put the tests into the general config category, to not require any particular configuration.
        return 'general'

    def cases_fn() -> Iterable[gen_typing.TestCase]:
        for data in test_case_fn():
            print(data)
            (case_name, case_content) = data
            yield gen_typing.TestCase(
                fork_name=PHASE0,
                runner_name='bls',
                handler_name=handler_name,
                suite_name='small',
                case_name=case_name,
                case_fn=lambda: [('data', 'data', case_content)])

    return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)