Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed May 5, 2024
1 parent e1e2602 commit 57e6e4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -58,15 +59,16 @@ public Stream<BLSPublicKey> readKeys() {
return Arrays.stream(keys).map(key -> BLSPublicKey.fromSSZBytes(Bytes.fromHexString(key)));
}

public SafeFuture<String[]> readUrl() {
private SafeFuture<String[]> readUrl() {
try {
return SafeFuture.completedFuture(mapper.readValue(new URL(url), String[].class));
} catch (IOException e) {
return SafeFuture.failedFuture(e);
}
}

public SafeFuture<String[]> retry() {
@VisibleForTesting
SafeFuture<String[]> retry() {
return asyncRunner
.runWithRetry(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@
class ExternalUrlKeyReaderTest {
private static final Duration DELAY = Duration.ofSeconds(5);
private static final String VALID_URL = "http://test:0000/api/v1/eth2/publicKeys";
private final ObjectMapper mapper = mock(ObjectMapper.class);

private final ObjectMapper mapper = mock(ObjectMapper.class);
private final StubTimeProvider timeProvider = StubTimeProvider.withTimeInMillis(0);
private final StubAsyncRunner asyncRunner = new StubAsyncRunner(timeProvider);

private final DataStructureUtil dataStructureUtil =
new DataStructureUtil(TestSpecFactory.createDefault());

final BLSPublicKey publicKey1 = dataStructureUtil.randomPublicKey();
final BLSPublicKey publicKey2 = dataStructureUtil.randomPublicKey();
final String[] expectedKeys = new String[] {publicKey1.toHexString(), publicKey2.toHexString()};
private final BLSPublicKey publicKey1 = dataStructureUtil.randomPublicKey();
private final BLSPublicKey publicKey2 = dataStructureUtil.randomPublicKey();
private final String[] expectedKeys =
new String[] {publicKey1.toHexString(), publicKey2.toHexString()};

@Test
void readKeys_validUrlReturnsValidKeys() throws IOException {
Expand Down

0 comments on commit 57e6e4e

Please sign in to comment.