Skip to content

Commit a11e4c5

Browse files
Add Electra milestone in few tests (Consensys#8173)
1 parent 489168b commit a11e4c5

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed

Diff for: ethereum/executionclient/src/integration-test/java/tech/pegasys/teku/ethereum/executionclient/web3j/Web3JExecutionEngineClientTest.java

+64-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.mockito.Mockito.mock;
2424
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
2525
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
26+
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
2627

2728
import com.fasterxml.jackson.annotation.JsonProperty;
2829
import com.fasterxml.jackson.core.JsonFactory;
@@ -43,12 +44,14 @@
4344
import okhttp3.mockwebserver.RecordedRequest;
4445
import org.apache.tuweni.bytes.Bytes;
4546
import org.apache.tuweni.bytes.Bytes32;
47+
import org.assertj.core.api.InstanceOfAssertFactories;
4648
import org.junit.jupiter.api.AfterEach;
4749
import org.junit.jupiter.api.BeforeEach;
4850
import org.junit.jupiter.api.TestTemplate;
4951
import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel;
5052
import tech.pegasys.teku.ethereum.executionclient.schema.ClientVersionV1;
5153
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV3;
54+
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
5255
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
5356
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
5457
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
@@ -69,7 +72,7 @@
6972
import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash;
7073
import tech.pegasys.teku.spec.util.DataStructureUtil;
7174

72-
@TestSpecContext(milestone = {CAPELLA, DENEB})
75+
@TestSpecContext(milestone = {CAPELLA, DENEB, ELECTRA})
7376
public class Web3JExecutionEngineClientTest {
7477

7578
private static final Duration DEFAULT_TIMEOUT = Duration.ofMinutes(1);
@@ -298,6 +301,66 @@ public void newPayloadV3_shouldBuildRequestAndResponseSuccessfully() {
298301
.isEqualTo(parentBeaconBlockRoot.toHexString());
299302
}
300303

304+
@TestTemplate
305+
@SuppressWarnings("unchecked")
306+
public void newPayloadV4_shouldBuildRequestAndResponseSuccessfully() {
307+
assumeThat(specMilestone).isGreaterThanOrEqualTo(ELECTRA);
308+
final Bytes32 latestValidHash = dataStructureUtil.randomBytes32();
309+
final PayloadStatus payloadStatusResponse =
310+
PayloadStatus.valid(Optional.of(latestValidHash), Optional.empty());
311+
312+
final String bodyResponse =
313+
"{\"jsonrpc\": \"2.0\", \"id\": 0, \"result\":"
314+
+ "{ \"status\": \"VALID\", \"latestValidHash\": \""
315+
+ latestValidHash
316+
+ "\", \"validationError\": null}}";
317+
318+
mockSuccessfulResponse(bodyResponse);
319+
320+
final ExecutionPayload executionPayload = dataStructureUtil.randomExecutionPayload();
321+
final ExecutionPayloadV4 executionPayloadV4 =
322+
ExecutionPayloadV4.fromInternalExecutionPayload(executionPayload);
323+
324+
final List<VersionedHash> blobVersionedHashes = dataStructureUtil.randomVersionedHashes(3);
325+
final Bytes32 parentBeaconBlockRoot = dataStructureUtil.randomBytes32();
326+
327+
final SafeFuture<Response<PayloadStatusV1>> futureResponse =
328+
eeClient.newPayloadV4(executionPayloadV4, blobVersionedHashes, parentBeaconBlockRoot);
329+
330+
assertThat(futureResponse)
331+
.succeedsWithin(1, TimeUnit.SECONDS)
332+
.matches(
333+
response ->
334+
response.getPayload().asInternalExecutionPayload().equals(payloadStatusResponse));
335+
336+
final Map<String, Object> requestData = takeRequest();
337+
verifyJsonRpcMethodCall(requestData, "engine_newPayloadV4");
338+
339+
final Map<String, Object> executionPayloadV4Parameter =
340+
(Map<String, Object>) ((List<Object>) requestData.get("params")).get(0);
341+
// 19 fields in ExecutionPayloadV4
342+
assertThat(executionPayloadV4Parameter).hasSize(19);
343+
// sanity check
344+
assertThat(executionPayloadV4Parameter.get("parentHash"))
345+
.isEqualTo(executionPayloadV4.parentHash.toHexString());
346+
347+
assertThat(executionPayloadV4Parameter.get("depositReceipts"))
348+
.asInstanceOf(InstanceOfAssertFactories.LIST)
349+
.hasSameSizeAs(executionPayloadV4.depositReceipts);
350+
assertThat(executionPayloadV4Parameter.get("exits"))
351+
.asInstanceOf(InstanceOfAssertFactories.LIST)
352+
.hasSameSizeAs(executionPayloadV4.exits);
353+
assertThat(((List<Object>) requestData.get("params")).get(1))
354+
.asInstanceOf(LIST)
355+
.containsExactlyElementsOf(
356+
blobVersionedHashes.stream()
357+
.map(VersionedHash::toHexString)
358+
.collect(Collectors.toList()));
359+
assertThat(((List<Object>) requestData.get("params")).get(2))
360+
.asString()
361+
.isEqualTo(parentBeaconBlockRoot.toHexString());
362+
}
363+
301364
private void mockSuccessfulResponse(final String responseBody) {
302365
mockWebServer.enqueue(
303366
new MockResponse()

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ protected void processOperationsNoValidation(
8585
final BeaconBlockBody body,
8686
final IndexedAttestationCache indexedAttestationCache)
8787
throws BlockProcessingException {
88-
final MutableBeaconStateElectra electraState = MutableBeaconStateElectra.required(state);
8988
super.processOperationsNoValidation(state, body, indexedAttestationCache);
89+
9090
safelyProcess(
9191
() ->
9292
processDepositReceipts(
93-
electraState,
93+
MutableBeaconStateElectra.required(state),
9494
body.getOptionalExecutionPayload()
9595
.flatMap(ExecutionPayload::toVersionElectra)
9696
.map(ExecutionPayloadElectra::getDepositReceipts)
@@ -136,7 +136,7 @@ protected void processExecutionLayerExits(
136136
}
137137

138138
/*
139-
Implements process_execution_layer_exit from consensus-spec (EIP-7002)
139+
Implements process_execution_layer_exit from consensus-specs (EIP-7002)
140140
*/
141141
@Override
142142
public void processExecutionLayerExits(
@@ -208,7 +208,7 @@ private SszList<ExecutionLayerExit> getExecutionLayerExitsFromBlock(
208208
}
209209

210210
/*
211-
Implements process_deposit_receipt from consensus-spec (EIP-6110)
211+
Implements process_deposit_receipt from consensus-specs (EIP-6110)
212212
*/
213213
public void processDepositReceipts(
214214
final MutableBeaconStateElectra state, final SszList<DepositReceipt> depositReceipts) {

Diff for: ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/BlindBlockUtilTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
2727
import tech.pegasys.teku.spec.util.DataStructureUtil;
2828

29-
@TestSpecContext(milestone = {SpecMilestone.BELLATRIX, SpecMilestone.CAPELLA, SpecMilestone.DENEB})
29+
@TestSpecContext(
30+
milestone = {
31+
SpecMilestone.BELLATRIX,
32+
SpecMilestone.CAPELLA,
33+
SpecMilestone.DENEB,
34+
SpecMilestone.ELECTRA
35+
})
3036
class BlindBlockUtilTest {
3137

3238
private DataStructureUtil dataStructureUtil;

Diff for: ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlobSidecarGossipValidatorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
4545
import tech.pegasys.teku.spec.util.DataStructureUtil;
4646

47-
@TestSpecContext(milestone = {SpecMilestone.DENEB})
47+
@TestSpecContext(milestone = {SpecMilestone.DENEB, SpecMilestone.ELECTRA})
4848
public class BlobSidecarGossipValidatorTest {
4949
private final Map<Bytes32, BlockImportResult> invalidBlocks = new HashMap<>();
5050
private final GossipValidationHelper gossipValidationHelper = mock(GossipValidationHelper.class);

Diff for: ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlockGossipValidatorTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@
4848
import tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder;
4949
import tech.pegasys.teku.storage.storageSystem.StorageSystem;
5050

51-
@TestSpecContext(milestone = {SpecMilestone.ALTAIR, SpecMilestone.BELLATRIX, SpecMilestone.DENEB})
51+
@TestSpecContext(
52+
milestone = {
53+
SpecMilestone.ALTAIR,
54+
SpecMilestone.BELLATRIX,
55+
SpecMilestone.DENEB,
56+
SpecMilestone.ELECTRA
57+
})
5258
public class BlockGossipValidatorTest {
5359
private Spec spec;
5460
private RecentChainData recentChainData;

0 commit comments

Comments
 (0)