forked from Consensys/teku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference tests for EIP-7594 + utils implementation (Consensys#36)
* eference tests 1.5.0.alpha.1 with EIP-7594 coverage activated * computeCustodyColumnIndexes implemented * verifyCellProofBatch implemented, it fails badly on some tests, so it's disabled. jc-kzg update should help I think
- Loading branch information
Showing
26 changed files
with
771 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...st/java/tech/pegasys/teku/reference/eip7594/networking/GetCustodyColumnsTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.eip7594.networking; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.teku.reference.TestDataUtils.loadYaml; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.apache.tuweni.units.bigints.UInt256; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.reference.TestExecutor; | ||
import tech.pegasys.teku.spec.SpecVersion; | ||
import tech.pegasys.teku.spec.logic.versions.eip7594.helpers.MiscHelpersEip7594; | ||
|
||
public class GetCustodyColumnsTestExecutor implements TestExecutor { | ||
|
||
@Override | ||
public void runTest(final TestDefinition testDefinition) throws Exception { | ||
final GetCustodyColumnsMetaData metaData = | ||
loadYaml(testDefinition, "meta.yaml", GetCustodyColumnsMetaData.class); | ||
final SpecVersion spec = testDefinition.getSpec().getGenesisSpec(); | ||
final Set<UInt64> actualResult = | ||
MiscHelpersEip7594.required(spec.miscHelpers()) | ||
.computeCustodyColumnIndexes(metaData.getNodeId(), metaData.getCustodySubnetCount()); | ||
assertThat(actualResult).isEqualTo(metaData.getResult()); | ||
} | ||
|
||
private static class GetCustodyColumnsMetaData { | ||
|
||
@JsonProperty(value = "node_id", required = true) | ||
private String nodeId; | ||
|
||
@JsonProperty(value = "custody_subnet_count", required = true) | ||
private int custodySubnetCount; | ||
|
||
@JsonProperty(value = "result", required = true) | ||
private List<Integer> result; | ||
|
||
public UInt256 getNodeId() { | ||
return UInt256.valueOf(new BigInteger(nodeId)); | ||
} | ||
|
||
public int getCustodySubnetCount() { | ||
return custodySubnetCount; | ||
} | ||
|
||
public Set<UInt64> getResult() { | ||
return result.stream().map(UInt64::valueOf).collect(Collectors.toUnmodifiableSet()); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/referenceTest/java/tech/pegasys/teku/reference/eip7594/networking/NetworkingTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2023 | ||
* | ||
* 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.eip7594.networking; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import tech.pegasys.teku.reference.TestExecutor; | ||
|
||
public class NetworkingTests { | ||
public static final ImmutableMap<String, TestExecutor> NETWORKING_TEST_TYPES = | ||
ImmutableMap.<String, TestExecutor>builder() | ||
.put("networking/get_custody_columns", new GetCustodyColumnsTestExecutor()) | ||
.build(); | ||
} |
75 changes: 75 additions & 0 deletions
75
.../java/tech/pegasys/teku/reference/phase0/kzg/KzgComputeCellsAndKzgProofsTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.kzg; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.Streams; | ||
import java.util.List; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.kzg.KZG; | ||
import tech.pegasys.teku.kzg.KZGCell; | ||
import tech.pegasys.teku.kzg.KZGCellAndProof; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
|
||
public class KzgComputeCellsAndKzgProofsTestExecutor extends KzgTestExecutor { | ||
|
||
@Override | ||
public void runTest(final TestDefinition testDefinition, final KZG kzg) throws Throwable { | ||
final Data data = loadDataFile(testDefinition, Data.class); | ||
final List<KZGCellAndProof> expectedKzgCellsAndProofs = data.getOutput(); | ||
List<KZGCellAndProof> actualKzgCellsAndProofs; | ||
try { | ||
final Bytes blob = data.getInput().getBlob(); | ||
actualKzgCellsAndProofs = kzg.computeCellsAndProofs(blob); | ||
} catch (final RuntimeException ex) { | ||
actualKzgCellsAndProofs = null; | ||
} | ||
assertThat(actualKzgCellsAndProofs).isEqualTo(expectedKzgCellsAndProofs); | ||
} | ||
|
||
private static class Data { | ||
@JsonProperty(value = "input", required = true) | ||
private Input input; | ||
|
||
@JsonProperty(value = "output", required = true) | ||
private List<String>[] output; | ||
|
||
public Input getInput() { | ||
return input; | ||
} | ||
|
||
public List<KZGCellAndProof> getOutput() { | ||
return output == null | ||
? null | ||
: Streams.zip( | ||
output[0].stream() | ||
.map(cellString -> new KZGCell(Bytes.fromHexString(cellString))), | ||
output[1].stream().map(KZGProof::fromHexString), | ||
KZGCellAndProof::new) | ||
.toList(); | ||
} | ||
|
||
private static class Input { | ||
@JsonProperty(value = "blob", required = true) | ||
private String blob; | ||
|
||
public Bytes getBlob() { | ||
return Bytes.fromHexString(blob); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.