예제 #1
0
class Attestation(HashableContainer):

    fields = [
        ("aggregation_bits", Bitlist(1)),
        ("data", AttestationData),
        ("signature", bytes96),
    ]

    @classmethod
    def create(
        cls: Type[TAttestation],
        aggregation_bits: Bitfield = default_bitfield,
        data: AttestationData = default_attestation_data,
        signature: BLSSignature = EMPTY_SIGNATURE,
    ) -> TAttestation:
        return super().create(
            aggregation_bits=aggregation_bits, data=data, signature=signature
        )

    def __str__(self) -> str:
        return (
            f"aggregation_bits={self.aggregation_bits},"
            f" data=({self.data}),"
            f" signature={humanize_hash(self.signature)}"
        )
예제 #2
0
class PendingAttestation(ssz.Serializable):

    fields = [
        ("aggregation_bits", Bitlist(1)),
        ("data", AttestationData),
        ("inclusion_delay", uint64),
        ("proposer_index", uint64),
    ]

    def __init__(
        self,
        aggregation_bits: Bitfield = default_bitfield,
        data: AttestationData = default_attestation_data,
        inclusion_delay: int = 0,
        proposer_index: ValidatorIndex = default_validator_index,
    ) -> None:
        super().__init__(
            aggregation_bits=aggregation_bits,
            data=data,
            inclusion_delay=inclusion_delay,
            proposer_index=proposer_index,
        )

    def __repr__(self) -> str:
        return f"<PendingAttestation inclusion_delay={self.inclusion_delay} data={self.data}>"
예제 #3
0
def bitlist_sedes_and_values_st(draw):
    max_size = draw(
        st.one_of(
            st.integers(1, 10),
            st.just(300),  # choose at least one sample exceeding one chunk
        ))
    return Bitlist(max_size), bitlist_value_st(max_size)
예제 #4
0
class ClockInRecords(SignedHashableContainer):
    fields = [
        ("epoch", uint64),
        ("bio_id_scan", bytes32),
        ("poo_log_bits", Bitlist(32)),
        ("wash_log_bits", Bitvector(32)),
        ("signature", bytes96),
    ]
예제 #5
0
class Attestation(ssz.Serializable):

    fields = [
        ("aggregation_bits", Bitlist(1)),
        ("data", AttestationData),
        ("custody_bits", Bitlist(1)),
        ("signature", bytes96),
    ]

    def __init__(
        self,
        aggregation_bits: Bitfield = default_bitfield,
        data: AttestationData = default_attestation_data,
        custody_bits: Bitfield = default_bitfield,
        signature: BLSSignature = EMPTY_SIGNATURE,
    ) -> None:
        super().__init__(aggregation_bits, data, custody_bits, signature)

    def __repr__(self) -> str:
        return f"<Attestation {self.data} >"
예제 #6
0
class Attestation(ssz.Serializable):

    fields = [
        ("aggregation_bits", Bitlist(1)),
        ("data", AttestationData),
        ("custody_bits", Bitlist(1)),
        ("signature", bytes96),
    ]

    def __init__(
        self,
        aggregation_bits: Bitfield = default_bitfield,
        data: AttestationData = default_attestation_data,
        custody_bits: Bitfield = default_bitfield,
        signature: BLSSignature = EMPTY_SIGNATURE,
    ) -> None:
        super().__init__(aggregation_bits, data, custody_bits, signature)

    def __str__(self) -> str:
        return (f"aggregation_bits={self.aggregation_bits},"
                f" data=({self.data}),"
                f" custody_bits={self.custody_bits},"
                f" signature={humanize_hash(self.signature)}")
예제 #7
0
def test_bitlist(size, value, result):
    foo = Bitlist(size)
    assert ssz.get_hash_tree_root(value, foo) == result
예제 #8
0
def test_bitlist_round_trip_no_sedes(size, value):
    foo = Bitlist(size)
    assert decode(encode(value, foo), foo) == value
예제 #9
0
def test_bitlist_deserialize_illegal_values(size, illegal_value):
    foo = Bitlist(size)
    with pytest.raises(DeserializationError):
        foo.deserialize(illegal_value)
예제 #10
0
def test_bitlist_deserialize_values(size, value, expected):
    foo = Bitlist(size)
    assert foo.deserialize(value) == expected
예제 #11
0
def test_bitlist_serialize_values(size, value, expected):
    foo = Bitlist(size)
    assert encode(value, foo) == expected
    assert foo.serialize(bytearray(value)) == expected
예제 #12
0
)
#   Test that exception is raised when trying to deserialise illegal seq of bytes into bitlists.
def test_bitlist_deserialize_illegal_values(size, illegal_value):
    foo = Bitlist(size)
    with pytest.raises(DeserializationError):
        foo.deserialize(illegal_value)


@pytest.mark.parametrize("size, value", ((16, (True, False)),
                                         (16, (True, ) + (False, ) * 15)))
def test_bitlist_round_trip_no_sedes(size, value):
    foo = Bitlist(size)
    assert decode(encode(value, foo), foo) == value


@pytest.mark.parametrize(("sedes", "id"), ((Bitlist(64), "Bitlist64"), ))
def test_get_sedes_id(sedes, id):
    assert sedes.get_sedes_id() == id


@pytest.mark.parametrize(("sedes1", "sedes2"), ((Bitlist(2), Bitlist(2)), ))
def test_eq(sedes1, sedes2):
    assert sedes1 == sedes1
    assert sedes2 == sedes2
    assert sedes1 == sedes2
    assert hash(sedes1) == hash(sedes2)


@pytest.mark.parametrize(
    ("sedes1", "sedes2"),
    (
def test_bitvector_round_trip_no_sedes(size, value):
    foo = Bitvector(size)
    assert decode(encode(value, foo), foo) == value

    @pytest.mark.parametrize(("sedes", "id"),
                             ((Bitvector(64), "Bitvector64"), ))
    def test_get_sedes_id(sedes, id):
        assert sedes.get_sedes_id() == id


@pytest.mark.parametrize(("sedes1", "sedes2"),
                         ((Bitvector(2), Bitvector(2)), ))
def test_eq(sedes1, sedes2):
    assert sedes1 == sedes1
    assert sedes2 == sedes2
    assert sedes1 == sedes2
    assert hash(sedes1) == hash(sedes2)


@pytest.mark.parametrize(
    ("sedes1", "sedes2"),
    (
        (Bitvector(2), Bitvector(3)),
        (Bitvector(2), Bitlist(2)),
        (Bitvector(2), Vector(boolean, 2)),
    ),
)
def test_neq(sedes1, sedes2):
    assert sedes1 != sedes2
    assert hash(sedes1) != hash(sedes2)
예제 #14
0
    List,
    Vector,
    boolean,
    bytes32,
    bytes48,
    bytes96,
    uint64,
)

import sys
import argparse

if __name__ == "__main__":
    # Setup argument parser
    # The only requires command line argument is the bitlist limit
    # The bitlist content is supplied via stdin
    parser = argparse.ArgumentParser()
    parser.add_argument('limit', type=int)
    args = parser.parse_args()

    # Binary read from stdin
    stdin = sys.stdin.buffer.read()

    bl = tuple(False if b == 0 else True for b in stdin)

    # Execute function/method to test
    hash = Bitlist(args.limit).get_hash_tree_root(bl)

    # Write result to stdout in binary
    sys.stdout.buffer.write(hash)