diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java index 276dfb26de7..e34fa53b9cf 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java @@ -62,25 +62,24 @@ private void setUpBaseSpec(final SpecMilestone specMilestone) { private void setUpNextSpec(final SpecMilestone nextSpecMilestone) { switch (baseSpec.getGenesisSpec().getMilestone()) { - case PHASE0: + case PHASE0 -> { checkState(nextSpecMilestone.equals(SpecMilestone.ALTAIR), "next spec should be altair"); nextSpec = Optional.of(TestSpecFactory.createMinimalWithAltairForkEpoch(nextSpecEpoch)); - break; - case ALTAIR: + } + case ALTAIR -> { checkState( nextSpecMilestone.equals(SpecMilestone.BELLATRIX), "next spec should be bellatrix"); nextSpec = Optional.of(TestSpecFactory.createMinimalWithBellatrixForkEpoch(nextSpecEpoch)); - break; - case BELLATRIX: + } + case BELLATRIX -> { checkState(nextSpecMilestone.equals(SpecMilestone.CAPELLA), "next spec should be capella"); nextSpec = Optional.of(TestSpecFactory.createMinimalWithCapellaForkEpoch(nextSpecEpoch)); - break; - case CAPELLA: + } + case CAPELLA -> { checkState(nextSpecMilestone.equals(SpecMilestone.DENEB), "next spec should be deneb"); nextSpec = Optional.of(TestSpecFactory.createMinimalWithDenebForkEpoch(nextSpecEpoch)); - break; - case DENEB: - throw new RuntimeException("Base spec is already latest supported milestone"); + } + case DENEB -> throw new RuntimeException("Base spec is already latest supported milestone"); } nextSpecSlot = nextSpec.orElseThrow().computeStartSlotAtEpoch(nextSpecEpoch); } @@ -91,7 +90,7 @@ public void tearDown() throws Exception { } protected Eth2Peer createPeer() { - return createRemotePeerAndNetwork().getPeer(); + return createRemotePeerAndNetwork().peer(); } private Spec getSpec(final boolean nextSpecEnabled) { @@ -118,7 +117,7 @@ protected Eth2Peer createPeer( return createRemotePeerAndNetwork( getSpec(enableNextSpecLocally), getSpec(enableNextSpecRemotely)) - .getPeer(); + .peer(); } /** @@ -129,7 +128,7 @@ protected Eth2Peer createPeer( * @return An Eth2Peer to which we can send requests */ protected Eth2Peer createPeer(final Spec spec) { - return createRemotePeerAndNetwork(spec, spec).getPeer(); + return createRemotePeerAndNetwork(spec, spec).peer(); } protected PeerAndNetwork createRemotePeerAndNetwork() { @@ -201,23 +200,7 @@ protected PeerAndNetwork createRemotePeerAndNetwork(final Spec localSpec, final } } - public static class PeerAndNetwork { - private final Eth2Peer peer; - private final Eth2P2PNetwork network; - - public PeerAndNetwork(final Eth2Peer peer, final Eth2P2PNetwork network) { - this.peer = peer; - this.network = network; - } - - public Eth2Peer getPeer() { - return peer; - } - - public Eth2P2PNetwork getNetwork() { - return network; - } - } + public record PeerAndNetwork(Eth2Peer peer, Eth2P2PNetwork network) {} protected static Stream generateSpecTransitionWithCombinationParams() { return Arrays.stream(SpecMilestone.values()) @@ -273,19 +256,12 @@ private List safeRetrieveBlobSidecars(final SlotAndBlockRoot slotAn } protected static Class milestoneToBeaconBlockBodyClass(final SpecMilestone milestone) { - switch (milestone) { - case PHASE0: - return BeaconBlockBodyPhase0.class; - case ALTAIR: - return BeaconBlockBodyAltair.class; - case BELLATRIX: - return BeaconBlockBodyBellatrix.class; - case CAPELLA: - return BeaconBlockBodyCapella.class; - case DENEB: - return BeaconBlockBodyDeneb.class; - default: - throw new UnsupportedOperationException("unsupported milestone: " + milestone); - } + return switch (milestone) { + case PHASE0 -> BeaconBlockBodyPhase0.class; + case ALTAIR -> BeaconBlockBodyAltair.class; + case BELLATRIX -> BeaconBlockBodyBellatrix.class; + case CAPELLA -> BeaconBlockBodyCapella.class; + case DENEB -> BeaconBlockBodyDeneb.class; + }; } } diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRangeIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRangeIntegrationTest.java index 161bdd6eee9..0bd175440bc 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRangeIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/BlobSidecarsByRangeIntegrationTest.java @@ -124,7 +124,6 @@ private List requestBlobSidecarsByRange( final List blobSidecars = new ArrayList<>(); waitFor( peer.requestBlobSidecarsByRange(from, count, RpcResponseListener.from(blobSidecars::add))); - assertThat(peer.getOutstandingRequests()).isEqualTo(0); return blobSidecars; } } diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java index 2d0e2944dd8..d9db758e9f2 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java @@ -38,14 +38,14 @@ public void requestMetadata_shouldSendLatestAttnets(final SpecMilestone baseMile throws Exception { setUp(baseMilestone, Optional.empty()); final PeerAndNetwork peerAndNetwork = createRemotePeerAndNetwork(); - final Eth2Peer peer = peerAndNetwork.getPeer(); + final Eth2Peer peer = peerAndNetwork.peer(); MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS); MetadataMessage md2 = peer.requestMetadata().get(10, TimeUnit.SECONDS); assertThat(md1.getSeqNumber()).isEqualTo(md2.getSeqNumber()); assertThat(md1.getAttnets().getBitCount()).isEqualTo(0); - peerAndNetwork.getNetwork().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8)); + peerAndNetwork.network().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8)); MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS); assertThat(md3.getSeqNumber()).isGreaterThan(md2.getSeqNumber()); assertThat(md3.getAttnets().getBitCount()).isEqualTo(3); @@ -60,7 +60,7 @@ public void requestMetadata_shouldSendLatestSyncnets( final SpecMilestone baseMilestone, final SpecMilestone nextMilestone) throws Exception { setUp(baseMilestone, Optional.of(nextMilestone)); final PeerAndNetwork peerAndNetwork = createRemotePeerAndNetwork(true, true); - final Eth2Peer peer = peerAndNetwork.getPeer(); + final Eth2Peer peer = peerAndNetwork.peer(); MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS); MetadataMessage md2 = peer.requestMetadata().get(10, TimeUnit.SECONDS); @@ -68,8 +68,8 @@ public void requestMetadata_shouldSendLatestSyncnets( assertThat(md1.getAttnets().getBitCount()).isEqualTo(0); // Subscribe to some sync committee subnets - peerAndNetwork.getNetwork().subscribeToSyncCommitteeSubnetId(1); - peerAndNetwork.getNetwork().subscribeToSyncCommitteeSubnetId(2); + peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(1); + peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(2); MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS); assertThat(md3).isInstanceOf(MetadataMessageAltair.class); final MetadataMessageAltair altairMetadata = (MetadataMessageAltair) md3; @@ -81,7 +81,7 @@ public void requestMetadata_shouldSendLatestSyncnets( assertThat(altairMetadata.getSyncnets().getBit(2)).isTrue(); // Unsubscribe from sync committee subnet - peerAndNetwork.getNetwork().unsubscribeFromSyncCommitteeSubnetId(2); + peerAndNetwork.network().unsubscribeFromSyncCommitteeSubnetId(2); MetadataMessage md4 = peer.requestMetadata().get(10, TimeUnit.SECONDS); assertThat(md4).isInstanceOf(MetadataMessageAltair.class); final MetadataMessageAltair altairMetadata2 = (MetadataMessageAltair) md4; @@ -98,7 +98,7 @@ public void requestMetadata_shouldSendLatestAttnetsAndSyncnets( final SpecMilestone baseMilestone, final SpecMilestone nextMilestone) throws Exception { setUp(baseMilestone, Optional.of(nextMilestone)); final PeerAndNetwork peerAndNetwork = createRemotePeerAndNetwork(true, true); - final Eth2Peer peer = peerAndNetwork.getPeer(); + final Eth2Peer peer = peerAndNetwork.peer(); MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS); MetadataMessage md2 = peer.requestMetadata().get(10, TimeUnit.SECONDS); @@ -106,8 +106,8 @@ public void requestMetadata_shouldSendLatestAttnetsAndSyncnets( assertThat(md1.getAttnets().getBitCount()).isEqualTo(0); // Update attnets and syncnets - peerAndNetwork.getNetwork().subscribeToSyncCommitteeSubnetId(1); - peerAndNetwork.getNetwork().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8)); + peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(1); + peerAndNetwork.network().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8)); MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS); assertThat(md3).isInstanceOf(MetadataMessageAltair.class); final MetadataMessageAltair altairMetadata = (MetadataMessageAltair) md3; @@ -145,16 +145,9 @@ public void requestMetadata_withDisparateVersionsEnabled( } private static Class milestoneToMetadataClass(final SpecMilestone milestone) { - switch (milestone) { - case PHASE0: - return MetadataMessagePhase0.class; - case ALTAIR: - case BELLATRIX: - case CAPELLA: - case DENEB: - return MetadataMessageAltair.class; - default: - throw new UnsupportedOperationException("unsupported milestone: " + milestone); - } + return switch (milestone) { + case PHASE0 -> MetadataMessagePhase0.class; + case ALTAIR, BELLATRIX, CAPELLA, DENEB -> MetadataMessageAltair.class; + }; } }