Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get aggregate attestation request #8483

Merged
merged 16 commits into from
Aug 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class CreateAggregateAttestationRequestElectraTest extends AbstractTypeDe
void setupRequest() {
createAggregateAttestationRequest =
new CreateAggregateAttestationRequest(
mockWebServer.url("/"), okHttpClient, new SchemaDefinitionCache(spec), spec);
mockWebServer.url("/"), okHttpClient, new SchemaDefinitionCache(spec));
responseBodyBuffer = new Buffer();
}

Expand All @@ -70,7 +70,7 @@ public void getAggregateAttestation_makesExpectedRequest() throws Exception {
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_NO_CONTENT));

createAggregateAttestationRequest.submit(
slot, attestationHashTreeRoot, Optional.of(committeeIndex));
slot, attestationHashTreeRoot, Optional.of(committeeIndex), spec);

final RecordedRequest request = mockWebServer.takeRequest();

Expand Down Expand Up @@ -104,7 +104,7 @@ public void shouldGetAggregateAttestation() {

final Optional<ObjectAndMetaData<Attestation>> maybeAttestationAndMetaData =
createAggregateAttestationRequest.submit(
slot, attestation.hashTreeRoot(), Optional.of(committeeIndex));
slot, attestation.hashTreeRoot(), Optional.of(committeeIndex), spec);
assertThat(maybeAttestationAndMetaData).isPresent();
assertThat(maybeAttestationAndMetaData.get().getData())
.isEqualTo(getAggregateAttestationResponse.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CreateAggregateAttestationRequestTest extends AbstractTypeDefReques
void setupRequest() {
request =
new CreateAggregateAttestationRequest(
mockWebServer.url("/"), okHttpClient, new SchemaDefinitionCache(spec), spec);
mockWebServer.url("/"), okHttpClient, new SchemaDefinitionCache(spec));
}

@TestTemplate
Expand All @@ -60,7 +60,7 @@ public void getAggregateAttestation_makesExpectedRequest() throws Exception {

mockWebServer.enqueue(new MockResponse().setResponseCode(SC_NO_CONTENT));

request.submit(slot, attestationHashTreeRoot, Optional.empty());
request.submit(slot, attestationHashTreeRoot, Optional.empty(), spec);

final RecordedRequest request = mockWebServer.takeRequest();
assertThat(request.getMethod()).isEqualTo("GET");
Expand All @@ -84,7 +84,7 @@ public void shouldGetAggregateAttestation() {
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK).setBody(mockResponse));

final Optional<ObjectAndMetaData<Attestation>> maybeAttestation =
request.submit(slot, attestation.hashTreeRoot(), Optional.empty());
request.submit(slot, attestation.hashTreeRoot(), Optional.empty(), spec);

assertThat(maybeAttestation).isPresent();
assertThat(maybeAttestation.get().getData())
Expand All @@ -99,7 +99,8 @@ void handle400() {
request.submit(
dataStructureUtil.randomSlot(),
dataStructureUtil.randomBytes32(),
Optional.empty()))
Optional.empty(),
spec))
.isInstanceOf(IllegalArgumentException.class);
}

Expand All @@ -110,7 +111,8 @@ void handle404() {
request.submit(
dataStructureUtil.randomSlot(),
dataStructureUtil.randomBytes32(),
Optional.empty()))
Optional.empty(),
spec))
.isEmpty();
}

Expand All @@ -122,7 +124,8 @@ void handle500() {
request.submit(
dataStructureUtil.randomSlot(),
dataStructureUtil.randomBytes32(),
Optional.empty()))
Optional.empty(),
spec))
.isInstanceOf(RemoteServiceNotAvailableException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ public Optional<ObjectAndMetaData<Attestation>> createAggregate(
final Optional<UInt64> committeeIndex) {
final CreateAggregateAttestationRequest createAggregateAttestationRequest =
new CreateAggregateAttestationRequest(
getBaseEndpoint(), getOkHttpClient(), schemaDefinitionCache, spec);
return createAggregateAttestationRequest.submit(slot, attestationHashTreeRoot, committeeIndex);
getBaseEndpoint(), getOkHttpClient(), schemaDefinitionCache);
return createAggregateAttestationRequest.submit(
slot, attestationHashTreeRoot, committeeIndex, spec);
}

public Optional<List<ValidatorLivenessAtEpoch>> sendValidatorsLiveness(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@

public class CreateAggregateAttestationRequest extends AbstractTypeDefRequest {
private final SchemaDefinitionCache schemaDefinitionCache;
private final Spec spec;

public CreateAggregateAttestationRequest(
final HttpUrl baseEndpoint,
final OkHttpClient okHttpClient,
final SchemaDefinitionCache schemaDefinitionCache,
final Spec spec) {
final SchemaDefinitionCache schemaDefinitionCache) {
super(baseEndpoint, okHttpClient);
this.schemaDefinitionCache = schemaDefinitionCache;
this.spec = spec;
mehdi-aouadi marked this conversation as resolved.
Show resolved Hide resolved
}

public Optional<ObjectAndMetaData<Attestation>> submit(
final UInt64 slot,
final Bytes32 attestationHashTreeRoot,
final Optional<UInt64> committeeIndex) {
final Optional<UInt64> committeeIndex,
final Spec spec) {
final AttestationSchema<Attestation> attestationSchema =
schemaDefinitionCache.atSlot(slot).getAttestationSchema().castTypeToAttestationSchema();

Expand Down