|
13 | 13 |
|
14 | 14 | package tech.pegasys.teku.validator.remote.typedef;
|
15 | 15 |
|
| 16 | +import static java.nio.charset.StandardCharsets.UTF_8; |
16 | 17 | import static java.util.Collections.emptyMap;
|
17 | 18 | import static org.assertj.core.api.Assertions.assertThat;
|
18 | 19 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
19 | 20 | import static org.assertj.core.api.Assumptions.assumeThat;
|
20 | 21 | import static tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorDataBuilder.STATE_VALIDATORS_RESPONSE_TYPE;
|
| 22 | +import static tech.pegasys.teku.ethereum.json.types.validator.AttesterDutiesBuilder.ATTESTER_DUTIES_RESPONSE_TYPE; |
21 | 23 | import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
|
22 | 24 | import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_METHOD_NOT_ALLOWED;
|
23 | 25 | import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
|
|
28 | 30 |
|
29 | 31 | import com.fasterxml.jackson.core.JsonProcessingException;
|
30 | 32 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 33 | +import it.unimi.dsi.fastutil.ints.IntList; |
31 | 34 | import java.util.List;
|
32 | 35 | import java.util.Optional;
|
33 | 36 | import okhttp3.mockwebserver.MockResponse;
|
|
39 | 42 | import tech.pegasys.teku.api.exceptions.RemoteServiceNotAvailableException;
|
40 | 43 | import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus;
|
41 | 44 | import tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorData;
|
| 45 | +import tech.pegasys.teku.ethereum.json.types.validator.AttesterDuties; |
| 46 | +import tech.pegasys.teku.ethereum.json.types.validator.AttesterDuty; |
42 | 47 | import tech.pegasys.teku.infrastructure.ssz.SszDataAssert;
|
43 | 48 | import tech.pegasys.teku.infrastructure.ssz.SszList;
|
44 | 49 | import tech.pegasys.teku.infrastructure.unsigned.UInt64;
|
@@ -410,6 +415,43 @@ private StateValidatorData generateStateValidatorData() {
|
410 | 415 | validator);
|
411 | 416 | }
|
412 | 417 |
|
| 418 | + @TestTemplate |
| 419 | + public void postAttesterDuties_WhenSuccess_ReturnsResponse() |
| 420 | + throws JsonProcessingException, InterruptedException { |
| 421 | + final List<AttesterDuty> duties = List.of(randomAttesterDuty(), randomAttesterDuty()); |
| 422 | + final AttesterDuties response = |
| 423 | + new AttesterDuties(true, dataStructureUtil.randomBytes32(), duties); |
| 424 | + |
| 425 | + final String body = serialize(response, ATTESTER_DUTIES_RESPONSE_TYPE); |
| 426 | + mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK).setBody(body)); |
| 427 | + |
| 428 | + final UInt64 epoch = UInt64.ONE; |
| 429 | + final IntList validatorIndices = IntList.of(1, 2); |
| 430 | + Optional<AttesterDuties> result = |
| 431 | + okHttpValidatorTypeDefClient.postAttesterDuties(epoch, validatorIndices); |
| 432 | + |
| 433 | + final RecordedRequest recordedRequest = mockWebServer.takeRequest(); |
| 434 | + assertThat(recordedRequest.getPath()).isEqualTo("/eth/v1/validator/duties/attester/" + epoch); |
| 435 | + assertThat(recordedRequest.getMethod()).isEqualTo("POST"); |
| 436 | + assertThat(recordedRequest.getHeader("Content-Type")).isEqualTo(JSON_CONTENT_TYPE); |
| 437 | + assertThat(recordedRequest.getBody().readByteArray()) |
| 438 | + .isEqualTo("[\"1\",\"2\"]".getBytes(UTF_8)); |
| 439 | + |
| 440 | + assertThat(result).isPresent(); |
| 441 | + assertThat(result.get()).isEqualTo(response); |
| 442 | + } |
| 443 | + |
| 444 | + private AttesterDuty randomAttesterDuty() { |
| 445 | + return new AttesterDuty( |
| 446 | + dataStructureUtil.randomPublicKey(), |
| 447 | + dataStructureUtil.randomValidatorIndex().intValue(), |
| 448 | + dataStructureUtil.randomPositiveInt(), |
| 449 | + dataStructureUtil.randomPositiveInt(), |
| 450 | + dataStructureUtil.randomPositiveInt(), |
| 451 | + dataStructureUtil.randomPositiveInt(), |
| 452 | + dataStructureUtil.randomSlot()); |
| 453 | + } |
| 454 | + |
413 | 455 | private void verifyRegisterValidatorsPostRequest(
|
414 | 456 | final RecordedRequest recordedRequest, final String expectedContentType) {
|
415 | 457 | assertThat(recordedRequest.getPath()).isEqualTo("/eth/v1/validator/register_validator");
|
|
0 commit comments