diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/versions/electra/PendingPartialWithdrawal.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/versions/electra/PendingPartialWithdrawal.java index b0dacfae215..cebf4492d19 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/versions/electra/PendingPartialWithdrawal.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/versions/electra/PendingPartialWithdrawal.java @@ -22,6 +22,18 @@ public class PendingPartialWithdrawal extends Container3 { + protected PendingPartialWithdrawal( + ContainerSchema3 schema) { + super(schema); + } + + public PendingPartialWithdrawal( + final PendingPartialWithdrawalSchema pendingPartialWithdrawalSchema, + final SszUInt64 index, + final SszUInt64 amount, + final SszUInt64 withdrawableEpoch) { + super(pendingPartialWithdrawalSchema, index, amount, withdrawableEpoch); + } public static class PendingPartialWithdrawalSchema extends ContainerSchema3 { @@ -52,16 +64,13 @@ public SszUInt64 getWithdrawableEpochSchema() { @Override public PendingPartialWithdrawal createFromBackingNode(TreeNode node) { - return null; + return new PendingPartialWithdrawal(this, node); } } private PendingPartialWithdrawal( - PendingPartialWithdrawal.PendingPartialWithdrawalSchema type, - final SszUInt64 index, - final SszUInt64 amount, - final SszUInt64 withdrawableEpoch) { - super(type, index, amount, withdrawableEpoch); + PendingPartialWithdrawal.PendingPartialWithdrawalSchema type, final TreeNode backingNode) { + super(type, backingNode); } public int getIndex() { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java index b241714e9f4..bf57b5eb35a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java @@ -79,7 +79,7 @@ public SchemaDefinitionsAltair(final SpecConfigAltair specConfig) { public static SchemaDefinitionsAltair required(final SchemaDefinitions schemaDefinitions) { Preconditions.checkArgument( schemaDefinitions instanceof SchemaDefinitionsAltair, - "Expected definitions of type %s by got %s", + "Expected definitions of type %s but got %s", SchemaDefinitionsAltair.class, schemaDefinitions.getClass()); return (SchemaDefinitionsAltair) schemaDefinitions; diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java index 9d55e5f1da0..6d5b5a51c23 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java @@ -81,7 +81,7 @@ public SchemaDefinitionsBellatrix(final SpecConfigBellatrix specConfig) { public static SchemaDefinitionsBellatrix required(final SchemaDefinitions schemaDefinitions) { checkArgument( schemaDefinitions instanceof SchemaDefinitionsBellatrix, - "Expected definitions of type %s by got %s", + "Expected definitions of type %s but got %s", SchemaDefinitionsBellatrix.class, schemaDefinitions.getClass()); return (SchemaDefinitionsBellatrix) schemaDefinitions; diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java index 277773762bf..18a765feecc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java @@ -109,7 +109,7 @@ public SchemaDefinitionsCapella(final SpecConfigCapella specConfig) { public static SchemaDefinitionsCapella required(final SchemaDefinitions schemaDefinitions) { checkArgument( schemaDefinitions instanceof SchemaDefinitionsCapella, - "Expected definitions of type %s by got %s", + "Expected definitions of type %s but got %s", SchemaDefinitionsCapella.class, schemaDefinitions.getClass()); return (SchemaDefinitionsCapella) schemaDefinitions; diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java index 16a4ec6e681..93c2ce04556 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java @@ -140,7 +140,7 @@ public SchemaDefinitionsDeneb(final SpecConfigDeneb specConfig) { public static SchemaDefinitionsDeneb required(final SchemaDefinitions schemaDefinitions) { checkArgument( schemaDefinitions instanceof SchemaDefinitionsDeneb, - "Expected definitions of type %s by got %s", + "Expected definitions of type %s but got %s", SchemaDefinitionsDeneb.class, schemaDefinitions.getClass()); return (SchemaDefinitionsDeneb) schemaDefinitions; diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java index 811c82bf3ac..cd006d9b3b3 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java @@ -144,7 +144,7 @@ public SchemaDefinitionsElectra(final SpecConfigElectra specConfig) { public static SchemaDefinitionsElectra required(final SchemaDefinitions schemaDefinitions) { checkArgument( schemaDefinitions instanceof SchemaDefinitionsElectra, - "Expected definitions of type %s by got %s", + "Expected definitions of type %s but got %s", SchemaDefinitionsElectra.class, schemaDefinitions.getClass()); return (SchemaDefinitionsElectra) schemaDefinitions; diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingBalanceDepositPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingBalanceDepositPropertyTest.java new file mode 100644 index 00000000000..a2d214b3d7b --- /dev/null +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingBalanceDepositPropertyTest.java @@ -0,0 +1,41 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.datastructures.state; + +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected; +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertRoundTrip; + +import com.fasterxml.jackson.core.JsonProcessingException; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit; +import tech.pegasys.teku.spec.propertytest.suppliers.state.PendingBalanceDepositSupplier; + +public class PendingBalanceDepositPropertyTest { + @Property + void roundTrip( + @ForAll(supplier = PendingBalanceDepositSupplier.class) + final PendingBalanceDeposit pendingBalanceDeposit) + throws JsonProcessingException { + assertRoundTrip(pendingBalanceDeposit); + } + + @Property + void deserializeMutated( + @ForAll(supplier = PendingBalanceDepositSupplier.class) + final PendingBalanceDeposit pendingBalanceDeposit, + @ForAll final int seed) { + assertDeserializeMutatedThrowsExpected(pendingBalanceDeposit, seed); + } +} diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingConsolidationPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingConsolidationPropertyTest.java new file mode 100644 index 00000000000..4c9018917a2 --- /dev/null +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingConsolidationPropertyTest.java @@ -0,0 +1,41 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.datastructures.state; + +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected; +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertRoundTrip; + +import com.fasterxml.jackson.core.JsonProcessingException; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation; +import tech.pegasys.teku.spec.propertytest.suppliers.state.PendingConsolidationSupplier; + +public class PendingConsolidationPropertyTest { + @Property + void roundTrip( + @ForAll(supplier = PendingConsolidationSupplier.class) + final PendingConsolidation pendingConsolidation) + throws JsonProcessingException { + assertRoundTrip(pendingConsolidation); + } + + @Property + void deserializeMutated( + @ForAll(supplier = PendingConsolidationSupplier.class) + final PendingConsolidation pendingConsolidation, + @ForAll final int seed) { + assertDeserializeMutatedThrowsExpected(pendingConsolidation, seed); + } +} diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingPartialWithdrawalPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingPartialWithdrawalPropertyTest.java new file mode 100644 index 00000000000..a8cad074c60 --- /dev/null +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/state/PendingPartialWithdrawalPropertyTest.java @@ -0,0 +1,41 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.datastructures.state; + +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected; +import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertRoundTrip; + +import com.fasterxml.jackson.core.JsonProcessingException; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal; +import tech.pegasys.teku.spec.propertytest.suppliers.state.PendingPartialWithdrawalSupplier; + +public class PendingPartialWithdrawalPropertyTest { + @Property + void roundTrip( + @ForAll(supplier = PendingPartialWithdrawalSupplier.class) + final PendingPartialWithdrawal pendingPartialWithdrawal) + throws JsonProcessingException { + assertRoundTrip(pendingPartialWithdrawal); + } + + @Property + void deserializeMutated( + @ForAll(supplier = PendingPartialWithdrawalSupplier.class) + final PendingPartialWithdrawal pendingPartialWithdrawal, + @ForAll final int seed) { + assertDeserializeMutatedThrowsExpected(pendingPartialWithdrawal, seed); + } +} diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingBalanceDepositSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingBalanceDepositSupplier.java new file mode 100644 index 00000000000..c414c62d15e --- /dev/null +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingBalanceDepositSupplier.java @@ -0,0 +1,26 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.propertytest.suppliers.state; + +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit; +import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; +import tech.pegasys.teku.spec.util.DataStructureUtil; + +public class PendingBalanceDepositSupplier + extends DataStructureUtilSupplier { + public PendingBalanceDepositSupplier() { + super(DataStructureUtil::randomPendingBalanceDeposit, SpecMilestone.ELECTRA); + } +} diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingConsolidationSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingConsolidationSupplier.java new file mode 100644 index 00000000000..e0b239deda0 --- /dev/null +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingConsolidationSupplier.java @@ -0,0 +1,25 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.propertytest.suppliers.state; + +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation; +import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; +import tech.pegasys.teku.spec.util.DataStructureUtil; + +public class PendingConsolidationSupplier extends DataStructureUtilSupplier { + public PendingConsolidationSupplier() { + super(DataStructureUtil::randomPendingConsolidation, SpecMilestone.ELECTRA); + } +} diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingPartialWithdrawalSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingPartialWithdrawalSupplier.java new file mode 100644 index 00000000000..4d74cfcf3cb --- /dev/null +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/state/PendingPartialWithdrawalSupplier.java @@ -0,0 +1,26 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * 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.spec.propertytest.suppliers.state; + +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal; +import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; +import tech.pegasys.teku.spec.util.DataStructureUtil; + +public class PendingPartialWithdrawalSupplier + extends DataStructureUtilSupplier { + public PendingPartialWithdrawalSupplier() { + super(DataStructureUtil::randomPendingPartialWithdrawal, SpecMilestone.ELECTRA); + } +} diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java index 72b5b57dca3..014c82b9746 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java @@ -175,6 +175,9 @@ import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStateSchemaPhase0; import tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingBalanceDeposit; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation; +import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal; import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; import tech.pegasys.teku.spec.datastructures.type.SszPublicKey; @@ -2461,6 +2464,27 @@ public ExecutionLayerExit executionLayerExit(final Validator validator) { .create(executionAddress, validator.getPublicKey()); } + public PendingBalanceDeposit randomPendingBalanceDeposit() { + return getElectraSchemaDefinitions(randomSlot()) + .getPendingBalanceDepositSchema() + .create(SszUInt64.of(randomUInt64()), SszUInt64.of(randomUInt64())); + } + + public PendingConsolidation randomPendingConsolidation() { + return getElectraSchemaDefinitions(randomSlot()) + .getPendingConsolidationSchema() + .create(SszUInt64.of(randomUInt64()), SszUInt64.of(randomUInt64())); + } + + public PendingPartialWithdrawal randomPendingPartialWithdrawal() { + return getElectraSchemaDefinitions(randomSlot()) + .getPendingPartialWithdrawalSchema() + .create( + SszUInt64.of(randomUInt64()), + SszUInt64.of(randomUInt64()), + SszUInt64.of(randomUInt64())); + } + public UInt64 randomBlobSidecarIndex() { return randomUInt64(spec.getMaxBlobsPerBlock().orElseThrow()); }