-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated sendValidatorLiveness to use typedef client (#8498)
- Loading branch information
Showing
14 changed files
with
258 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...tech/pegasys/teku/validator/remote/typedef/handlers/SendValidatorLivenessRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.validator.remote.typedef.handlers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import tech.pegasys.teku.api.migrated.ValidatorLivenessAtEpoch; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.SpecMilestone; | ||
import tech.pegasys.teku.spec.TestSpecContext; | ||
import tech.pegasys.teku.spec.networks.Eth2Network; | ||
import tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod; | ||
import tech.pegasys.teku.validator.remote.typedef.AbstractTypeDefRequestTestBase; | ||
|
||
@TestSpecContext(milestone = SpecMilestone.PHASE0, network = Eth2Network.MINIMAL) | ||
public class SendValidatorLivenessRequestTest extends AbstractTypeDefRequestTestBase { | ||
|
||
private SendValidatorLivenessRequest sendValidatorLivenessRequest; | ||
|
||
@BeforeEach | ||
void setupRequest() { | ||
sendValidatorLivenessRequest = | ||
new SendValidatorLivenessRequest(mockWebServer.url("/"), okHttpClient); | ||
} | ||
|
||
@TestTemplate | ||
public void sendValidatorLiveness_makesExpectedRequest() throws Exception { | ||
mockWebServer.enqueue(new MockResponse().setResponseCode(SC_OK)); | ||
sendValidatorLivenessRequest.submit(UInt64.ONE, List.of(UInt64.valueOf(1))); | ||
|
||
final RecordedRequest request = mockWebServer.takeRequest(); | ||
assertThat(request.getMethod()).isEqualTo("POST"); | ||
assertThat(request.getPath()) | ||
.contains(ValidatorApiMethod.SEND_VALIDATOR_LIVENESS.getPath(Map.of("epoch", "1"))); | ||
} | ||
|
||
@TestTemplate | ||
public void sendValidatorLiveness_readsResponse() throws Exception { | ||
mockWebServer.enqueue( | ||
new MockResponse() | ||
.setResponseCode(SC_OK) | ||
.setBody("{\"data\":[{\"index\":\"1\",\"is_live\":false}]}")); | ||
final Optional<List<ValidatorLivenessAtEpoch>> result = | ||
sendValidatorLivenessRequest.submit(UInt64.ONE, List.of(UInt64.valueOf(1))); | ||
|
||
final RecordedRequest request = mockWebServer.takeRequest(); | ||
assertThat(request.getMethod()).isEqualTo("POST"); | ||
assertThat(request.getPath()) | ||
.contains(ValidatorApiMethod.SEND_VALIDATOR_LIVENESS.getPath(Map.of("epoch", "1"))); | ||
|
||
assertThat(result).isPresent(); | ||
assertThat(result.get()).containsExactly(new ValidatorLivenessAtEpoch(UInt64.ONE, false)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.