Skip to content

Commit

Permalink
Implement updated Deneb builder rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 6, 2023
1 parent 0178be5 commit 976f298
Show file tree
Hide file tree
Showing 23 changed files with 450 additions and 515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlindedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
import tech.pegasys.teku.spec.datastructures.builder.SignedBuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration;
Expand Down Expand Up @@ -99,7 +99,7 @@ class RestBuilderClientTest {
private RestBuilderClient restBuilderClient;

private String signedValidatorRegistrationsRequest;
private String signedBlindedBlockContainerRequest;
private String signedBlindedBeaconBlockRequest;

private String signedBuilderBidResponse;
private String unblindedBuilderPayloadResponse;
Expand All @@ -118,8 +118,8 @@ void setUp(final SpecContext specContext) throws IOException {

signedValidatorRegistrationsRequest = readResource("builder/signedValidatorRegistrations.json");
final String milestoneFolder = "builder/" + milestone.toString().toLowerCase(Locale.ROOT);
signedBlindedBlockContainerRequest =
readResource(milestoneFolder + "/signedBlindedBlockContainer.json");
signedBlindedBeaconBlockRequest =
readResource(milestoneFolder + "/signedBlindedBeaconBlock.json");
signedBuilderBidResponse = readResource(milestoneFolder + "/signedBuilderBid.json");
unblindedBuilderPayloadResponse =
readResource(milestoneFolder + "/unblindedBuilderPayload.json");
Expand Down Expand Up @@ -378,10 +378,9 @@ void getPayload_success() {
mockWebServer.enqueue(
new MockResponse().setResponseCode(200).setBody(unblindedBuilderPayloadResponse));

final SignedBlindedBlockContainer signedBlindedBlockContainer =
createSignedBlindedBlockContainer();
final SignedBeaconBlock signedBlindedBeaconBlock = createSignedBlindedBeaconBlock();

assertThat(restBuilderClient.getPayload(signedBlindedBlockContainer))
assertThat(restBuilderClient.getPayload(signedBlindedBeaconBlock))
.succeedsWithin(WAIT_FOR_CALL_COMPLETION)
.satisfies(
response -> {
Expand All @@ -390,7 +389,7 @@ void getPayload_success() {
verifyBuilderPayloadResponse(builderPayload);
});

verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBlockContainerRequest);
verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBeaconBlockRequest);
}

@TestTemplate
Expand All @@ -400,31 +399,30 @@ void getPayload_failures() {
"{\"code\":400,\"message\":\"Invalid block: missing signature\"}";
mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody(missingSignatureError));

final SignedBlindedBlockContainer signedBlindedBlockContainer =
createSignedBlindedBlockContainer();
final SignedBeaconBlock signedBlindedBeaconBlock = createSignedBlindedBeaconBlock();

assertThat(restBuilderClient.getPayload(signedBlindedBlockContainer))
assertThat(restBuilderClient.getPayload(signedBlindedBeaconBlock))
.succeedsWithin(WAIT_FOR_CALL_COMPLETION)
.satisfies(
response -> {
assertThat(response.isFailure()).isTrue();
assertThat(response.getErrorMessage()).isEqualTo(missingSignatureError);
});

verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBlockContainerRequest);
verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBeaconBlockRequest);

mockWebServer.enqueue(
new MockResponse().setResponseCode(500).setBody(INTERNAL_SERVER_ERROR_MESSAGE));

assertThat(restBuilderClient.getPayload(signedBlindedBlockContainer))
assertThat(restBuilderClient.getPayload(signedBlindedBeaconBlock))
.succeedsWithin(WAIT_FOR_CALL_COMPLETION)
.satisfies(
response -> {
assertThat(response.isFailure()).isTrue();
assertThat(response.getErrorMessage()).isEqualTo(INTERNAL_SERVER_ERROR_MESSAGE);
});

verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBlockContainerRequest);
verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBeaconBlockRequest);
}

@TestTemplate
Expand All @@ -437,10 +435,9 @@ void getPayload_wrongVersion(final SpecContext specContext) {
mockWebServer.enqueue(
new MockResponse().setResponseCode(200).setBody(unblindedBuilderPayloadResponse));

final SignedBlindedBlockContainer signedBlindedBlockContainer =
createSignedBlindedBlockContainer();
final SignedBeaconBlock signedBlindedBeaconBlock = createSignedBlindedBeaconBlock();

assertThat(restBuilderClient.getPayload(signedBlindedBlockContainer))
assertThat(restBuilderClient.getPayload(signedBlindedBeaconBlock))
.succeedsWithin(WAIT_FOR_CALL_COMPLETION)
.satisfies(
response -> {
Expand All @@ -449,7 +446,7 @@ void getPayload_wrongVersion(final SpecContext specContext) {
verifyBuilderPayloadResponse(builderPayload);
});

verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBlockContainerRequest);
verifyPostRequest("/eth/v1/builder/blinded_blocks", signedBlindedBeaconBlockRequest);
}

private void verifyGetRequest(final String apiPath) {
Expand Down Expand Up @@ -517,13 +514,11 @@ private void verifySignedBuilderBidResponse(final SignedBuilderBid actual) {
}
}

private SignedBlindedBlockContainer createSignedBlindedBlockContainer() {
private SignedBeaconBlock createSignedBlindedBeaconBlock() {
try {
return JsonUtil.parse(
signedBlindedBlockContainerRequest,
schemaDefinitions.getSignedBlindedBlockContainerSchema().getJsonTypeDefinition())
.toBlinded()
.orElseThrow();
signedBlindedBeaconBlockRequest,
schemaDefinitions.getSignedBlindedBeaconBlockSchema().getJsonTypeDefinition());
} catch (final JsonProcessingException ex) {
throw new UncheckedIOException(ex);
}
Expand Down
Loading

0 comments on commit 976f298

Please sign in to comment.