Skip to content

Commit

Permalink
add post block integration tests (#8771)
Browse files Browse the repository at this point in the history
* refactor post block integration tests
  • Loading branch information
mehdi-aouadi authored Oct 23, 2024
1 parent 21efe6e commit d0b0bc1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.beaconrestapi.v1.validator;
package tech.pegasys.teku.beaconrestapi.beacon;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V1;
import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V2;
import static tech.pegasys.teku.beaconrestapi.beacon.PostBlindedAndUnblindedBlockTest.Version.V1;
import static tech.pegasys.teku.beaconrestapi.beacon.PostBlindedAndUnblindedBlockTest.Version.V2;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;

import java.io.IOException;
Expand Down Expand Up @@ -58,22 +58,30 @@ public static Stream<Arguments> postBlockCases() {
.flatMap(
route ->
Stream.of(
// route, useSsz
Arguments.of(route, false), Arguments.of(route, true)))
// route, useSsz, set consensus header
Arguments.of(route, false, true),
Arguments.of(route, false, false),
Arguments.of(route, true, false),
Arguments.of(route, true, true)))
.map(
args -> {
final String route = (String) args.get()[0];
final boolean isBlindedBlock = route.contains("blinded");
final Version version = route.contains("/v2/") ? V2 : V1;
final boolean useSsz = (boolean) args.get()[1];
return Arguments.of(version, isBlindedBlock, route, useSsz);
final boolean setConsensusHeader = (boolean) args.get()[2];
return Arguments.of(version, isBlindedBlock, route, useSsz, setConsensusHeader);
});
}

@ParameterizedTest(name = "version:{0}_blinded:{1}_ssz:{3}")
@ParameterizedTest(name = "version:{0}_blinded:{1}_ssz:{3}_setConsensusHeader:{4}")
@MethodSource("postBlockCases")
void preDeneb(
final Version version, final boolean isBlindedBlock, final String route, final boolean useSsz)
final Version version,
final boolean isBlindedBlock,
final String route,
final boolean useSsz,
final boolean setConsensusHeader)
throws IOException {

startRestAPIAtGenesis(SpecMilestone.BELLATRIX);
Expand All @@ -96,21 +104,20 @@ void preDeneb(

prepareResponse(request, version);

postRequestAndAssert(
route,
request,
signedBeaconBlockSchema,
Optional.of(SpecMilestone.BELLATRIX.name()),
useSsz,
version);
postRequestAndAssert(
route, request, signedBeaconBlockSchema, Optional.empty(), useSsz, version);
final Optional<String> consensusHeader =
setConsensusHeader ? Optional.of(SpecMilestone.BELLATRIX.name()) : Optional.empty();

postRequestAndAssert(route, request, signedBeaconBlockSchema, consensusHeader, useSsz, version);
}

@ParameterizedTest(name = "version:{0}_blinded:{1}_ssz:{3}")
@ParameterizedTest(name = "version:{0}_blinded:{1}_ssz:{3}_setConsensusHeader:{4}")
@MethodSource("postBlockCases")
void postDeneb(
final Version version, final boolean isBlindedBlock, final String route, final boolean useSsz)
final Version version,
final boolean isBlindedBlock,
final String route,
final boolean useSsz,
final boolean setConsensusHeader)
throws IOException {
startRestAPIAtGenesis(SpecMilestone.DENEB);
dataStructureUtil = new DataStructureUtil(spec);
Expand All @@ -132,15 +139,11 @@ void postDeneb(

prepareResponse(request, version);

final Optional<String> consensusHeader =
setConsensusHeader ? Optional.of(SpecMilestone.DENEB.name()) : Optional.empty();

postRequestAndAssert(
route,
request,
signedBlockContainerSchema,
Optional.of(SpecMilestone.DENEB.name()),
useSsz,
version);
postRequestAndAssert(
route, request, signedBlockContainerSchema, Optional.empty(), useSsz, version);
route, request, signedBlockContainerSchema, consensusHeader, useSsz, version);
}

private void prepareResponse(final SignedBeaconBlock request, final Version version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
},
"503" : {
"description" : "Beacon node is currently syncing.",
"description" : "Beacon node is currently syncing and not serving requests",
"content" : {
"application/json" : {
"schema" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
},
"503" : {
"description" : "Beacon node is currently syncing.",
"description" : "Beacon node is currently syncing and not serving requests",
"content" : {
"application/json" : {
"schema" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_SERVICE_UNAVAILABLE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.SERVICE_UNAVAILABLE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_VALIDATOR_REQUIRED;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.HTTP_ERROR_RESPONSE_TYPE;
Expand Down Expand Up @@ -64,7 +65,7 @@ public PostBlindedBlockV2(
@Override
public void handleRequest(final RestApiRequest request) throws JsonProcessingException {
if (syncDataProvider.isSyncing()) {
request.respondError(SC_SERVICE_UNAVAILABLE, "Beacon node is currently syncing.");
request.respondError(SC_SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE);
return;
}

Expand Down Expand Up @@ -127,8 +128,7 @@ broadcast but a different status code is returned (202). Pre-Bellatrix, this end
SC_ACCEPTED,
"Block has been successfully broadcast, but failed validation and has not been imported.")
.withBadRequestResponse(Optional.of("Unable to parse request body."))
.response(
SC_SERVICE_UNAVAILABLE, "Beacon node is currently syncing.", HTTP_ERROR_RESPONSE_TYPE)
.response(SC_SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE, HTTP_ERROR_RESPONSE_TYPE)
.response(
SC_NO_CONTENT, "Data is unavailable because the chain has not yet reached genesis")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ validation, a separate success response code (202) is used to indicate that the
SC_ACCEPTED,
"Block has been successfully broadcast, but failed validation and has not been imported.")
.withBadRequestResponse(Optional.of("Unable to parse request body."))
.response(
SC_SERVICE_UNAVAILABLE, "Beacon node is currently syncing.", HTTP_ERROR_RESPONSE_TYPE)
.response(SC_SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE, HTTP_ERROR_RESPONSE_TYPE)
.response(
SC_NO_CONTENT, "Data is unavailable because the chain has not yet reached genesis")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ public enum ValidatorApiMethod {
GET_SYNCING_STATUS("/eth/v1/node/syncing"),
GET_GENESIS("eth/v1/beacon/genesis"),
GET_VALIDATORS("eth/v1/beacon/states/head/validators"),
GET_DUTIES("validator/duties"),
GET_UNSIGNED_BLOCK_V3("eth/v3/validator/blocks/:slot"),
SEND_SIGNED_BLOCK("eth/v1/beacon/blocks"),
SEND_SIGNED_BLOCK_V2("eth/v2/beacon/blocks"),
SEND_SIGNED_BLINDED_BLOCK("eth/v1/beacon/blinded_blocks"),
SEND_SIGNED_BLINDED_BLOCK_V2("eth/v2/beacon/blinded_blocks"),
GET_ATTESTATION_DATA("eth/v1/validator/attestation_data"),
SEND_SIGNED_ATTESTATION("eth/v1/beacon/pool/attestations"),
Expand Down

This file was deleted.

0 comments on commit d0b0bc1

Please sign in to comment.