Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ allprojects {
}

def nightly = System.getenv("NIGHTLY") != null
def refTestVersion = nightly ? "nightly" : "v1.7.0-alpha.11"
def refTestVersion = nightly ? "nightly" : "v1.7.0-alpha.12"
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
def blsRefTestVersion = 'v0.1.2'
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-specs/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,10 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.nio.ByteOrder;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.opentest4j.TestAbortedException;
import tech.pegasys.teku.ethtests.finder.TestDefinition;
import tech.pegasys.teku.infrastructure.ssz.SszCollection;
import tech.pegasys.teku.infrastructure.ssz.SszContainer;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.infrastructure.ssz.collections.SszByteList;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes4;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.reference.TestDataUtils;
import tech.pegasys.teku.reference.phase0.ssz_generic.containers.BitsStructSchema;
Expand All @@ -46,19 +35,12 @@ public class SszGenericContainerTestExecutor extends AbstractSszGenericTestExecu
@Override
protected void assertValueCorrect(final TestDefinition testDefinition, final SszData result)
throws IOException {
final Map<String, String> expected = loadExpectedValues(testDefinition);
final SszContainer container = (SszContainer) result;
final Map<String, String> actual = formatSszContainer(container);
assertThat(actual).isEqualTo(expected);
}
final SszData yamlResult =
TestDataUtils.loadYaml(
testDefinition, "value.yaml", container.getSchema().getJsonTypeDefinition());

@SuppressWarnings("unchecked")
private Map<String, String> loadExpectedValues(final TestDefinition testDefinition)
throws IOException {
final Map<String, Object> objectMap =
TestDataUtils.loadYaml(testDefinition, "value.yaml", Map.class);
return objectMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().toString()));
assertThat(yamlResult.hashTreeRoot()).isEqualTo(container.hashTreeRoot());
}

@Override
Expand All @@ -85,26 +67,4 @@ protected SszSchema<?> getSchema(final TestDefinition testDefinition) {
protected Object parseString(final TestDefinition testDefinition, final String value) {
return null;
}

private Map<String, String> formatSszContainer(final SszContainer container) {
return container.getSchema().getFieldNames().stream()
.collect(
Collectors.toMap(
Function.identity(),
name -> format(container.get(container.getSchema().getFieldIndex(name)))));
}

private String format(final Object value) {
return switch (value) {
case SszByte sszByte -> Integer.toString(Byte.toUnsignedInt(sszByte.get()));
case SszBytes4 sszBytes4 ->
Long.toString(sszBytes4.get().getWrappedBytes().toLong(ByteOrder.LITTLE_ENDIAN));
case SszBitlist sszBits -> sszBits.sszSerialize().toHexString();
case SszByteList sszBytes -> sszBytes.sszSerialize().toHexString();
case SszBitvector bitvector -> bitvector.sszSerialize().toHexString();
case SszCollection<?> list -> list.stream().map(this::format).toList().toString();
case SszContainer sszContainer -> formatSszContainer(sszContainer).toString();
default -> Objects.toString(value, null);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszProgressiveBitlistSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszProgressiveListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.impl.AbstractSszContainerSchema.NamedSchema;
import tech.pegasys.teku.reference.TestDataUtils;
Expand Down Expand Up @@ -130,15 +129,15 @@ private static SszContainerSchema<?> createProgressiveComplexTestStructSchema()
NamedSchema.of("A", SszPrimitiveSchemas.BYTE_SCHEMA),
NamedSchema.of("B", SszListSchema.create(UINT16_SCHEMA, 123)),
NamedSchema.of("C", new SszProgressiveBitlistSchema()),
NamedSchema.of("D", SszProgressiveListSchema.create(SszPrimitiveSchemas.UINT64_SCHEMA)),
NamedSchema.of("E", SszProgressiveListSchema.create(new SmallTestStructSchema())),
NamedSchema.of("D", SszListSchema.createProgressive(SszPrimitiveSchemas.UINT64_SCHEMA)),
NamedSchema.of("E", SszListSchema.createProgressive(new SmallTestStructSchema())),
NamedSchema.of(
"F",
SszProgressiveListSchema.create(
SszProgressiveListSchema.create(new VarTestStructSchema()))),
SszListSchema.createProgressive(
SszListSchema.createProgressive(new VarTestStructSchema()))),
NamedSchema.of("G", SszListSchema.create(singleFieldSchema, 10)),
NamedSchema.of(
"H", SszProgressiveListSchema.create(createProgressiveVarTestStructSchema()))));
"H", SszListSchema.createProgressive(createProgressiveVarTestStructSchema()))));
}

private Map<String, String> formatSszContainer(final SszContainer container) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import tech.pegasys.teku.ethtests.finder.TestDefinition;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszProgressiveListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.reference.TestDataUtils;

Expand All @@ -46,7 +46,7 @@ protected void assertValueCorrect(final TestDefinition testDefinition, final Ssz
@Override
protected SszSchema<?> getSchema(final TestDefinition testDefinition) {
final SszSchema<?> elementSchema = getElementSchema(testDefinition);
return SszProgressiveListSchema.create(elementSchema);
return SszListSchema.createProgressive(elementSchema);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ComplexTestStructSchema() {
ComplexTestStruct.class.getSimpleName(),
NamedSchema.of("A", UINT16_SCHEMA),
NamedSchema.of("B", SszListSchema.create(UINT16_SCHEMA, 128)),
NamedSchema.of("C", SszPrimitiveSchemas.BYTE_SCHEMA),
NamedSchema.of("C", SszPrimitiveSchemas.UINT8_SCHEMA),
NamedSchema.of("D", SszByteListSchema.create(256)),
NamedSchema.of("E", new VarTestStructSchema()),
NamedSchema.of("F", SszVectorSchema.create(new FixedTestStructSchema(), 4)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
import tech.pegasys.teku.infrastructure.ssz.containers.Container3;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class FixedTestStruct extends Container3<FixedTestStruct, SszByte, SszUInt64, SszBytes4> {
public class FixedTestStruct extends Container3<FixedTestStruct, SszByte, SszUInt64, SszUInt32> {

protected FixedTestStruct(
final ContainerSchema3<FixedTestStruct, SszByte, SszUInt64, SszBytes4> schema,
final ContainerSchema3<FixedTestStruct, SszByte, SszUInt64, SszUInt32> schema,
final TreeNode backingNode) {
super(schema, backingNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@

package tech.pegasys.teku.reference.phase0.ssz_generic.containers;

import static tech.pegasys.teku.reference.phase0.ssz_generic.containers.UInt32PrimitiveSchema.UINT32_SCHEMA;

import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class FixedTestStructSchema
extends ContainerSchema3<FixedTestStruct, SszByte, SszUInt64, SszBytes4> {
extends ContainerSchema3<FixedTestStruct, SszByte, SszUInt64, SszUInt32> {

public FixedTestStructSchema() {
super(
FixedTestStruct.class.getSimpleName(),
NamedSchema.of("A", SszPrimitiveSchemas.BYTE_SCHEMA),
NamedSchema.of("A", SszPrimitiveSchemas.UINT8_SCHEMA),
NamedSchema.of("B", SszPrimitiveSchemas.UINT64_SCHEMA),
NamedSchema.of("C", SszPrimitiveSchemas.BYTES4_SCHEMA));
NamedSchema.of("C", UINT32_SCHEMA));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

package tech.pegasys.teku.reference.phase0.ssz_generic.containers;

import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszProgressiveListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

/**
Expand All @@ -43,17 +45,22 @@ public class ProgressiveTestStructSchema
public ProgressiveTestStructSchema() {
super(
ProgressiveTestStruct.class.getSimpleName(),
NamedSchema.of("A", SszProgressiveListSchema.create(SszPrimitiveSchemas.BYTE_SCHEMA)),
NamedSchema.of("B", SszProgressiveListSchema.create(SszPrimitiveSchemas.UINT64_SCHEMA)),
NamedSchema.of("C", SszProgressiveListSchema.create(new SmallTestStructSchema())),
NamedSchema.of("A", createProgressiveListSchema(SszPrimitiveSchemas.BYTE_SCHEMA)),
NamedSchema.of("B", createProgressiveListSchema(SszPrimitiveSchemas.UINT64_SCHEMA)),
NamedSchema.of("C", createProgressiveListSchema(new SmallTestStructSchema())),
NamedSchema.of(
"D",
SszProgressiveListSchema.create(
SszProgressiveListSchema.create(new VarTestStructSchema()))));
createProgressiveListSchema(createProgressiveListSchema(new VarTestStructSchema()))));
}

@Override
public ProgressiveTestStruct createFromBackingNode(final TreeNode node) {
return new ProgressiveTestStruct(this, node);
}

@SuppressWarnings("unchecked")
private static <T extends SszData> SszSchema<SszList<T>> createProgressiveListSchema(
final SszSchema<T> elementSchema) {
return (SszSchema<SszList<T>>) (SszSchema<?>) SszListSchema.createProgressive(elementSchema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SingleFieldTestStructSchema extends ContainerSchema1<SingleFieldTes
public SingleFieldTestStructSchema() {
super(
SingleFieldTestStructSchema.class.getSimpleName(),
NamedSchema.of("A", SszPrimitiveSchemas.BYTE_SCHEMA));
NamedSchema.of("A", SszPrimitiveSchemas.UINT8_SCHEMA));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Consensys Software Inc., 2026
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.reference.phase0.ssz_generic.containers;

import tech.pegasys.teku.infrastructure.ssz.impl.AbstractSszPrimitive;

public class SszUInt32 extends AbstractSszPrimitive<Long> {

public static SszUInt32 of(final Long val) {
return new SszUInt32(val);
}

private SszUInt32(final Long val) {
super(val, UInt32PrimitiveSchema.UINT32_SCHEMA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

package tech.pegasys.teku.reference.phase0.ssz_generic.containers;

import static com.google.common.base.Preconditions.checkArgument;

import java.nio.ByteOrder;
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.json.types.CoreTypes;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.schema.impl.AbstractSszPrimitiveSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.json.SszPrimitiveTypeDefinitions;
import tech.pegasys.teku.infrastructure.ssz.schema.json.SszTypeDefinitionWrapper;
import tech.pegasys.teku.infrastructure.ssz.tree.LeafDataNode;
import tech.pegasys.teku.infrastructure.ssz.tree.LeafNode;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
Expand Down Expand Up @@ -49,6 +52,8 @@ public TreeNode updateBackingNode(

@Override
public SszUInt16 boxed(final Integer rawValue) {
checkArgument(
0 <= rawValue && rawValue <= 0xFFFF, "Value %s is outside range for uint16", rawValue);
return SszUInt16.of(rawValue);
}

Expand All @@ -59,7 +64,8 @@ public TreeNode getDefaultTree() {

@Override
public DeserializableTypeDefinition<SszUInt16> getJsonTypeDefinition() {
return SszPrimitiveTypeDefinitions.sszSerializedType(this, "hex encoding");
return new SszTypeDefinitionWrapper<>(
this, CoreTypes.RAW_INTEGER_TYPE.withDescription("unsigned 16 bit integer"));
}

@Override
Expand Down
Loading
Loading