Skip to content

Commit ec3e547

Browse files
committed
Merge branch 'master' into set-graffiti
# Conflicts: # validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/ValidatorRestApi.java # validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_graffiti.json
2 parents ab82225 + 064ce08 commit ec3e547

File tree

5 files changed

+289
-0
lines changed

5 files changed

+289
-0
lines changed

Diff for: validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/ValidatorRestApi.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import tech.pegasys.teku.validator.client.restapi.apis.DeleteRemoteKeys;
4343
import tech.pegasys.teku.validator.client.restapi.apis.GetFeeRecipient;
4444
import tech.pegasys.teku.validator.client.restapi.apis.GetGasLimit;
45+
import tech.pegasys.teku.validator.client.restapi.apis.GetGraffiti;
4546
import tech.pegasys.teku.validator.client.restapi.apis.GetKeys;
4647
import tech.pegasys.teku.validator.client.restapi.apis.GetRemoteKeys;
4748
import tech.pegasys.teku.validator.client.restapi.apis.PostKeys;
@@ -130,6 +131,7 @@ public static RestApi create(
130131
.endpoint(new DeleteFeeRecipient(proposerConfigManager))
131132
.endpoint(new DeleteGasLimit(proposerConfigManager))
132133
.endpoint(new PostVoluntaryExit(voluntaryExitDataProvider))
134+
.endpoint(new GetGraffiti())
133135
.endpoint(new SetGraffiti())
134136
.sslCertificate(config.getRestApiKeystoreFile(), config.getRestApiKeystorePasswordFile())
135137
.passwordFilePath(validatorApiBearerFile)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 tech.pegasys.teku.ethereum.json.types.SharedApiTypes.PUBKEY_API_TYPE;
17+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
18+
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.STRING_TYPE;
19+
import static tech.pegasys.teku.validator.client.restapi.ValidatorRestApi.TAG_GRAFFITI;
20+
import static tech.pegasys.teku.validator.client.restapi.ValidatorTypes.PARAM_PUBKEY_TYPE;
21+
22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import java.util.Objects;
24+
import java.util.Optional;
25+
import java.util.function.Function;
26+
import org.apache.commons.lang3.NotImplementedException;
27+
import tech.pegasys.teku.bls.BLSPublicKey;
28+
import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition;
29+
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
30+
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint;
31+
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
32+
33+
public class GetGraffiti extends RestApiEndpoint {
34+
public static final String ROUTE = "/eth/v1/validator/{pubkey}/graffiti";
35+
36+
private static final SerializableTypeDefinition<GraffitiResponse> GRAFFITI_TYPE =
37+
SerializableTypeDefinition.object(GraffitiResponse.class)
38+
.withOptionalField("pubkey", PUBKEY_API_TYPE, GraffitiResponse::getPublicKey)
39+
.withField("graffiti", STRING_TYPE, GraffitiResponse::getGraffiti)
40+
.build();
41+
42+
private static final SerializableTypeDefinition<GraffitiResponse> RESPONSE_TYPE =
43+
SerializableTypeDefinition.object(GraffitiResponse.class)
44+
.name("GraffitiResponse")
45+
.withField("data", GRAFFITI_TYPE, Function.identity())
46+
.build();
47+
48+
public GetGraffiti() {
49+
super(
50+
EndpointMetadata.get(ROUTE)
51+
.operationId("getGraffiti")
52+
.summary("Get Graffiti")
53+
.description(
54+
"Get the graffiti for an individual validator. If no graffiti is set explicitly, returns the process-wide default.")
55+
.tags(TAG_GRAFFITI)
56+
.withBearerAuthSecurity()
57+
.pathParam(PARAM_PUBKEY_TYPE)
58+
.response(SC_OK, "Success response", RESPONSE_TYPE)
59+
.withAuthenticationResponses()
60+
.withNotFoundResponse()
61+
.withNotImplementedResponse()
62+
.build());
63+
}
64+
65+
@Override
66+
public void handleRequest(RestApiRequest request) throws JsonProcessingException {
67+
throw new NotImplementedException("Not implemented");
68+
}
69+
70+
static class GraffitiResponse {
71+
private final Optional<BLSPublicKey> publicKey;
72+
private final String graffiti;
73+
74+
GraffitiResponse(final BLSPublicKey publicKey, final String graffiti) {
75+
this.publicKey = Optional.of(publicKey);
76+
this.graffiti = graffiti;
77+
}
78+
79+
Optional<BLSPublicKey> getPublicKey() {
80+
return publicKey;
81+
}
82+
83+
String getGraffiti() {
84+
return graffiti;
85+
}
86+
87+
@Override
88+
public boolean equals(Object o) {
89+
if (this == o) {
90+
return true;
91+
}
92+
if (o == null || getClass() != o.getClass()) {
93+
return false;
94+
}
95+
GraffitiResponse that = (GraffitiResponse) o;
96+
return Objects.equals(publicKey, that.publicKey) && Objects.equals(graffiti, that.graffiti);
97+
}
98+
99+
@Override
100+
public int hashCode() {
101+
return Objects.hash(publicKey, graffiti);
102+
}
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
final 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+
}

Diff for: validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_graffiti.json

+91
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,95 @@
11
{
2+
"get" : {
3+
"tags" : [ "Graffiti" ],
4+
"operationId" : "getGraffiti",
5+
"summary" : "Get Graffiti",
6+
"description" : "Get the graffiti for an individual validator. If no graffiti is set explicitly, returns the process-wide default.",
7+
"parameters" : [ {
8+
"name" : "pubkey",
9+
"required" : true,
10+
"in" : "path",
11+
"schema" : {
12+
"type" : "string",
13+
"pattern" : "^0x[a-fA-F0-9]{96}$",
14+
"example" : "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a"
15+
}
16+
} ],
17+
"security" : [ {
18+
"bearerAuth" : [ ]
19+
} ],
20+
"responses" : {
21+
"200" : {
22+
"description" : "Success response",
23+
"content" : {
24+
"application/json" : {
25+
"schema" : {
26+
"$ref" : "#/components/schemas/GraffitiResponse"
27+
}
28+
}
29+
}
30+
},
31+
"401" : {
32+
"description" : "Unauthorized, no token is found",
33+
"content" : {
34+
"application/json" : {
35+
"schema" : {
36+
"$ref" : "#/components/schemas/HttpErrorResponse"
37+
}
38+
}
39+
}
40+
},
41+
"403" : {
42+
"description" : "Forbidden, a token is found but is invalid",
43+
"content" : {
44+
"application/json" : {
45+
"schema" : {
46+
"$ref" : "#/components/schemas/HttpErrorResponse"
47+
}
48+
}
49+
}
50+
},
51+
"404" : {
52+
"description" : "Not found",
53+
"content" : {
54+
"application/json" : {
55+
"schema" : {
56+
"$ref" : "#/components/schemas/HttpErrorResponse"
57+
}
58+
}
59+
}
60+
},
61+
"501" : {
62+
"description" : "Not implemented",
63+
"content" : {
64+
"application/json" : {
65+
"schema" : {
66+
"$ref" : "#/components/schemas/HttpErrorResponse"
67+
}
68+
}
69+
}
70+
},
71+
"400" : {
72+
"description" : "The request could not be processed, check the response for more information.",
73+
"content" : {
74+
"application/json" : {
75+
"schema" : {
76+
"$ref" : "#/components/schemas/HttpErrorResponse"
77+
}
78+
}
79+
}
80+
},
81+
"500" : {
82+
"description" : "Internal server error",
83+
"content" : {
84+
"application/json" : {
85+
"schema" : {
86+
"$ref" : "#/components/schemas/HttpErrorResponse"
87+
}
88+
}
89+
}
90+
}
91+
}
92+
},
293
"post" : {
394
"tags" : [ "Graffiti" ],
495
"operationId" : "setGraffiti",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"title" : "GraffitiResponse",
3+
"type" : "object",
4+
"required" : [ "data" ],
5+
"properties" : {
6+
"data" : {
7+
"type" : "object",
8+
"required" : [ "graffiti" ],
9+
"properties" : {
10+
"pubkey" : {
11+
"$ref" : "#/components/schemas/Pubkey"
12+
},
13+
"graffiti" : {
14+
"type" : "string"
15+
}
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)