Skip to content

Commit

Permalink
change set to list
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 2, 2023
1 parent 1282e05 commit d4a2bc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -280,21 +279,23 @@ public SafeFuture<Optional<BlobSidecar>> requestBlobSidecarByRoot(
return rpcMethods
.blobSidecarsByRoot()
.map(
method ->
requestOptionalItem(
method,
new BlobSidecarsByRootRequestMessage(
blobSidecarsByRootRequestMessageSchema.get(),
Collections.singletonList(blobIdentifier)))
.thenPeek(
maybeBlobSidecar ->
maybeBlobSidecar.ifPresent(
blobSidecar -> {
final BlobSidecarsByRootValidator validator =
new BlobSidecarsByRootValidator(
this, spec, kzg, Set.of(blobIdentifier));
validator.validate(blobSidecar);
})))
method -> {
final List<BlobIdentifier> blobIdentifiers =
Collections.singletonList(blobIdentifier);
return requestOptionalItem(
method,
new BlobSidecarsByRootRequestMessage(
blobSidecarsByRootRequestMessageSchema.get(), blobIdentifiers))
.thenPeek(
maybeBlobSidecar ->
maybeBlobSidecar.ifPresent(
blobSidecar -> {
final BlobSidecarsByRootValidator validator =
new BlobSidecarsByRootValidator(
this, spec, kzg, blobIdentifiers);
validator.validate(blobSidecar);
}));
})
.orElse(failWithUnsupportedMethodException("BlobSidecarsByRoot"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods;

import java.util.Set;
import java.util.List;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsResponseInvalidResponseException.InvalidResponseType;
import tech.pegasys.teku.networking.p2p.peer.Peer;
Expand All @@ -23,13 +23,13 @@

public class BlobSidecarsByRootValidator extends AbstractBlobSidecarsValidator {

private final Set<BlobIdentifier> expectedBlobIdentifiers;
private final List<BlobIdentifier> expectedBlobIdentifiers;

public BlobSidecarsByRootValidator(
final Peer peer,
final Spec spec,
final KZG kzg,
final Set<BlobIdentifier> expectedBlobIdentifiers) {
final List<BlobIdentifier> expectedBlobIdentifiers) {
super(peer, spec, kzg);
this.expectedBlobIdentifiers = expectedBlobIdentifiers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Set;
import java.util.List;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -51,7 +51,7 @@ void blobSidecarIsCorrect() {
final BlobSidecar blobSidecar1 =
dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO);

validator = new BlobSidecarsByRootValidator(peer, spec, kzg, Set.of(blobIdentifier1));
validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier1));
assertDoesNotThrow(() -> validator.validate(blobSidecar1));
}

Expand All @@ -63,7 +63,7 @@ void blobSidecarIdentifierNotRequested() {
final BlobSidecar blobSidecar1 =
dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO);

validator = new BlobSidecarsByRootValidator(peer, spec, kzg, Set.of(blobIdentifier2));
validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier2));
assertThatThrownBy(() -> validator.validate(blobSidecar1))
.isExactlyInstanceOf(BlobSidecarsResponseInvalidResponseException.class)
.hasMessageContaining(
Expand All @@ -80,7 +80,7 @@ void blobSidecarFailsKzgVerification() {
final BlobSidecar blobSidecar1 =
dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO);

validator = new BlobSidecarsByRootValidator(peer, spec, kzg, Set.of(blobIdentifier1));
validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier1));
assertThatThrownBy(() -> validator.validate(blobSidecar1))
.isExactlyInstanceOf(BlobSidecarsResponseInvalidResponseException.class)
.hasMessageContaining(
Expand Down

0 comments on commit d4a2bc0

Please sign in to comment.