Giter Club home page Giter Club logo

eth2-testgen's Introduction

Eth 2.0 test vectors generators

** Status: Deprecated **

Functionality has been upstreamed. Head over to https://github.com/ethereum/eth2.0-tests for the test vectors or https://github.com/ethereum/eth2.0-test-generators for their generators.

Test vectors generators based on the specifications at https://github.com/ethereum/eth2.0-specs.

Getting Started

make

Implementation

As much as possible the generators copy-paste the specifications. If an example implementation is not available in the specifications, the generator will be implemented using one of the Ethereum Foundation library instead.

License

Similar to Eth 2.0 specifications, all code and generated test vectors are public domain under CC0

eth2-testgen's People

Contributors

chihchengliang avatar mratsim avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eth2-testgen's Issues

Prettify the test format

The YAML file is pretty long now and it's hard to read and review.

I've tried to minimize the length of validators' input by only reporting validators' status in YAML, as the following example shows.

fork: tchaikovsky
summary: Test vectors for shuffling a list based upon a seed using `shuffle`
test_suite: shuffle
title: Shuffling Algorithm Tests
version: 1.0
test_cases:
- input:
    crosslinking_start_shard: 210
    validators: [2, 4, 0, 0, 2, 2, 4, 2, 3, 1, 0, 3,
      3, 4, 4, 4, 1, 1, 1, 1, 3, 2, 3, 0, 2, 4, 0, 2,
      4, 0, 0, 4, 2, 1, 4, 1, 4, 2, 2, 1, 2, 4, 0, 4,
      0, 3, 0, 4, 4, 0, 0, 1, 3, 3, 0, 4, 3, 1, 1, 3,
      1, 0, 0, 1, 0, 0, 4, 1, 2, 0, 1, 4, 2, 1, 1, 4,
      1, 1, 1, 1, 0, 4, 4, 0, 1, 3, 4, 2, 0, 1, 4, 3,
      1, 2, 4, 2, 2, 2, 3, 3, 3, 0, 2, 0, 4, 1, 1, 3,
      0, 3, 1, 3, 4, 3, 3, 4, 0, 1, 0, 3, 3, 1, 4, 2,
      0, 3, 2, 3, 0, 4, 3, 1, 3, 3, 4, 3, 0, 0, 1, 0,
      2, 4, 1, 3, 1, 3, 2, 4, 2, 2, 0, 3, 2, 3, 1, 3,
      0, 2, 1, 3, 2, 2, 1, 3, 0, 2, 1, 3, 2, 2, 2, 0,
      0, 0, 3, 4, 1, 4, 4, 3, 3, 0, 1, 2, 4, 1, 4, 0,
      0, 4, 3, 2, 4, 3, 1, 2, 0, 4, 4, 2, 0, 4, 4, 4,
      4, 0, 1, 4, 4, 3, 0, 3, 2, 1, 4, 3, 0, 3, 0, 3,
      1, 3, 3, 2, 3, 2, 2, 2, 1, 0, 4, 2, 0, 4, 2, 2,
      0, 1, 0, 0, 2, 0, 3, 3, 2, 4, 0, 3, 1, 0, 3, 4,
      2, 4, 0, 1, 4, 1, 0, 0, 4, 3, 3, 1, 1, 4, 1, 3,
      1, 0, 4, 3, 3, 0, 2, 1, 3, 4, 1, 3, 3, 3, 0, 4,
      2, 3, 0, 0, 0, 1, 4, 3, 1, 4, 2, 0, 4, 2, 3, 0,
      1, 2, 0, 4, 0, 4, 4, 2, 1, 3, 4, 3, 2, 3, 3, 4,
      3, 2, 2, 1, 3, 0, 3, 2, 1, 0, 1, 3, 2, 0, 0, 0,
      1, 1, 2, 2, 0, 3, 1, 0, 3, 2, 0, 0, 2, 3, 0, 0,
      4, 4, 2, 0, 1, 1, 3, 0, 1, 0, 1, 1, 3, 4, 0, 0,
      3, 4, 4, 4, 0, 2, 4, 4, 1, 0, 2, 2, 3, 4, 4, 0,
      1, 3, 2, 4, 0, 1, 2, 1, 3, 3, 0, 3, 4, 1, 3, 1,
      0, 1, 0, 4, 4, 3, 4, 1, 0, 3, 1, 3]

This does look less lengthy but comes with a downside that it's hard to pin down a certain validator, say 123, from the list. With the original format, you can search the validator 123 with ctrl+f.

Another alternative is to break test cases in different YAML files. An index.yaml can include the summary of the test suite and valid tests, it can also leave the WIP tests away.

01_shuffle/
├── index.yaml
├── test_case_1.yaml
├── test_case_2.yaml
└── test_case_3.yaml

Test failed due to diff in ValidatorStatus.

Run the test with the py-evm helpers and failed to reproduce expected output. The root cause is the ValidatorStatus is outdated in tgen_shuffling.py and is the latest in py-evm. When it's updated the test passes.

To reproduce the script, can run python test.py or pytest test.py. The later shows diff in assert.

#./test.py
import yaml
from eth.beacon.helpers import get_new_shuffling
from eth.beacon.types.validator_records import ValidatorRecord
from eth_utils import decode_hex

with open("test_vectors/test_vector_shuffling.yml") as f:
    d = yaml.load(f)

test_case = d["test_cases"][0]


def test_a_case(_input, expected_output, seed):

    validators = [
        ValidatorRecord(
            pubkey=0,
            withdrawal_credentials=b'\x55'*32,
            randao_commitment=b'\x55'*32,
            randao_layers=5,
            balance=5566,
            status=validator['status'],
            latest_status_change_slot=5,
            exit_count=5
        )
        for validator in _input['validators']
    ]

    real_output = get_new_shuffling(
        seed=seed,
        validators=validators,
        crosslinking_start_shard=_input['crosslinking_start_shard'],
        epoch_length=64,
        target_committee_size=256,
        shard_count=1024)

    for sc_real, sc_expected in zip(real_output, expected_output):
        assert sc_real[0].committee == tuple(sc_expected[0]['committee'])
        assert sc_real[0].shard == sc_expected[0]['shard']
        assert sc_real[0].total_validator_count == sc_expected[0]['total_validator_count']


test_a_case(
    test_case["input"],
    test_case["output"],
    decode_hex(test_case["seed"])
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.