Skip to content

Commit e838281

Browse files
authored
Fix handling of invalid eth1Address for setFeeRecipient. (#5795)
Signed-off-by: Paul Harris <paul.harris@consensys.net>
1 parent e93785a commit e838281

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public static RestApi create(
7474
.exceptionHandler(
7575
BadRequestException.class,
7676
(throwable) -> new HttpErrorResponse(SC_BAD_REQUEST, throwable.getMessage()))
77+
.exceptionHandler(
78+
IllegalArgumentException.class,
79+
(throwable) -> new HttpErrorResponse(SC_BAD_REQUEST, throwable.getMessage()))
7780
.exceptionHandler(
7881
JsonProcessingException.class,
7982
(throwable) -> new HttpErrorResponse(SC_BAD_REQUEST, throwable.getMessage()))

validator/client/src/test/java/tech/pegasys/teku/validator/client/restapi/apis/SetFeeRecipientTest.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,28 @@
2727
import java.io.IOException;
2828
import java.util.Optional;
2929
import org.junit.jupiter.api.Test;
30-
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
30+
import tech.pegasys.teku.infrastructure.restapi.StubRestApiRequest;
31+
import tech.pegasys.teku.spec.Spec;
32+
import tech.pegasys.teku.spec.TestSpecFactory;
3133
import tech.pegasys.teku.spec.datastructures.eth1.Eth1Address;
34+
import tech.pegasys.teku.spec.util.DataStructureUtil;
3235
import tech.pegasys.teku.validator.client.BeaconProposerPreparer;
3336

3437
public class SetFeeRecipientTest {
3538
private final BeaconProposerPreparer beaconProposerPreparer = mock(BeaconProposerPreparer.class);
3639
private final SetFeeRecipient handler = new SetFeeRecipient(Optional.of(beaconProposerPreparer));
3740

38-
private final RestApiRequest request = mock(RestApiRequest.class);
41+
private final StubRestApiRequest request = new StubRestApiRequest(handler.getMetadata());
42+
43+
private final Spec spec = TestSpecFactory.createMinimalAltair();
44+
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
45+
46+
@Test
47+
void badPubkey_shouldGiveIllegalArgument() {
48+
request.setPathParameter("pubkey", "pubkey");
49+
assertThatThrownBy(() -> handler.handleRequest(request))
50+
.isInstanceOf(IllegalArgumentException.class);
51+
}
3952

4053
@Test
4154
void metadata_shouldHandle400() throws JsonProcessingException {
@@ -49,6 +62,9 @@ void metadata_shouldHandle500() throws JsonProcessingException {
4962

5063
@Test
5164
void shouldShareContextIfBellatrixNotEnabled() {
65+
request.setPathParameter("pubkey", dataStructureUtil.randomPublicKey().toString());
66+
request.setRequestBody(
67+
new SetFeeRecipient.SetFeeRecipientBody(dataStructureUtil.randomEth1Address()));
5268
assertThatThrownBy(
5369
() -> {
5470
SetFeeRecipient handler = new SetFeeRecipient(Optional.empty());
@@ -73,4 +89,13 @@ void metadata_shouldReadRequestBody() throws IOException {
7389
new SetFeeRecipient.SetFeeRecipientBody(
7490
Eth1Address.fromHexString("0xabcf8e0d4e9587369b2301d0790347320302cc09")));
7591
}
92+
93+
@Test
94+
void metadata_shoulThrowInvalidArgument() {
95+
assertThatThrownBy(
96+
() ->
97+
getRequestBodyFromMetadata(
98+
handler, "{\"ethaddress\":\"0xabcF8e0d4E9587369b2301d0790347320302CC09\"}"))
99+
.isInstanceOf(IllegalArgumentException.class);
100+
}
76101
}

0 commit comments

Comments
 (0)