|
| 1 | +/* |
| 2 | + * Copyright Consensys Software Inc., 2024 |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package tech.pegasys.teku.validator.client.restapi.apis; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST; |
| 18 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_FORBIDDEN; |
| 19 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR; |
| 20 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_IMPLEMENTED; |
| 21 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; |
| 22 | +import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_UNAUTHORIZED; |
| 23 | +import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.getResponseStringFromMetadata; |
| 24 | +import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse; |
| 25 | + |
| 26 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import tech.pegasys.teku.spec.TestSpecFactory; |
| 29 | +import tech.pegasys.teku.spec.util.DataStructureUtil; |
| 30 | + |
| 31 | +class GetGraffitiTest { |
| 32 | + private final GetGraffiti handler = new GetGraffiti(); |
| 33 | + |
| 34 | + private final DataStructureUtil dataStructureUtil = |
| 35 | + new DataStructureUtil(TestSpecFactory.createDefault()); |
| 36 | + |
| 37 | + @Test |
| 38 | + void metadata_shouldHandle200() throws JsonProcessingException { |
| 39 | + GetGraffiti.GraffitiResponse response = |
| 40 | + new GetGraffiti.GraffitiResponse(dataStructureUtil.randomPublicKey(), "Test graffiti"); |
| 41 | + final String responseData = getResponseStringFromMetadata(handler, SC_OK, response); |
| 42 | + assertThat(responseData) |
| 43 | + .isEqualTo( |
| 44 | + "{\"data\":{\"pubkey\":" |
| 45 | + + "\"0xa4654ac3105a58c7634031b5718c4880c87300f72091cfbc69fe490b71d93a671e00e80a388e1ceb8ea1de112003e976\"," |
| 46 | + + "\"graffiti\":\"Test graffiti\"}}"); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void metadata_shouldHandle400() throws JsonProcessingException { |
| 51 | + verifyMetadataErrorResponse(handler, SC_BAD_REQUEST); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void metadata_shouldHandle401() throws JsonProcessingException { |
| 56 | + verifyMetadataErrorResponse(handler, SC_UNAUTHORIZED); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void metadata_shouldHandle403() throws JsonProcessingException { |
| 61 | + verifyMetadataErrorResponse(handler, SC_FORBIDDEN); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void metadata_shouldHandle500() throws JsonProcessingException { |
| 66 | + verifyMetadataErrorResponse(handler, SC_INTERNAL_SERVER_ERROR); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void metadata_shouldHandle501() throws JsonProcessingException { |
| 71 | + verifyMetadataErrorResponse(handler, SC_NOT_IMPLEMENTED); |
| 72 | + } |
| 73 | +} |
0 commit comments