Skip to content

Commit

Permalink
reword epoch missing error, add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone committed Jul 22, 2024
1 parent 692346e commit eac5cb4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public class VoluntaryExitCommandTest {
@BeforeEach
public void setup(final ClientAndServer server) throws IOException {
this.mockBeaconServer = server;
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulValidatorResponses(mockBeaconServer);
originalSystemIn = System.in;
originalSystemOut = System.out;
Expand Down Expand Up @@ -151,6 +150,7 @@ public void tearDown() {
@Test
public void shouldExitAllLoadedValidators() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);

final List<String> args = getCommandArguments(true, false, List.of());
Expand All @@ -165,6 +165,7 @@ public void shouldExitAllLoadedValidators() throws JsonProcessingException {
public void shouldExitLoadedValidatorsUsingConfirmationMessage() throws JsonProcessingException {
setUserInput("yes");
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);

final List<String> args = getCommandArguments(true, true, List.of());
Expand All @@ -178,6 +179,7 @@ public void shouldExitLoadedValidatorsUsingConfirmationMessage() throws JsonProc
@Test
public void shouldExitValidatorWithPubKeyFromKeyManagerOnly() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);

final List<String> args =
Expand All @@ -196,6 +198,7 @@ public void shouldExitValidatorWithPubKeyFromKeyManagerOnly() throws JsonProcess
@Test
public void shouldAcceptNetworkOnCommandLine() {
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

// No beacon-api offered by spec, so would need to be loaded from local network option
final List<String> args =
Expand All @@ -213,6 +216,7 @@ public void shouldAcceptNetworkOnCommandLine() {
@Test
public void shouldReturnRejectedReasonWhenExitIsRejectedByBeaconNode() throws IOException {
configureRejectedVoluntaryExitResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

final List<String> args =
getCommandArguments(
Expand Down Expand Up @@ -242,6 +246,7 @@ public void shouldFailToRunExitWithoutASpec() {
@Test
public void shouldExitValidatorWithPubKeyFromPathOnly() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);

final List<String> args =
Expand All @@ -260,6 +265,7 @@ public void shouldExitValidatorWithPubKeyFromPathOnly() throws JsonProcessingExc
@Test
public void shouldSkipKeyManagerKeys() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);
configureSuccessfulVoluntaryExitResponse(mockBeaconServer);

final List<String> args =
Expand All @@ -278,6 +284,7 @@ public void shouldSkipKeyManagerKeys() throws JsonProcessingException {
@Test
void shouldNotWarn_NotWithdrawableIfCapellaEnabled() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
configureSuccessfulGenesisResponse(mockBeaconServer);

final List<String> args = getCommandArguments(false, true, List.of());
setUserInput("no");
Expand All @@ -293,6 +300,7 @@ void shouldNotWarn_NotWithdrawableIfCapellaEnabled() throws JsonProcessingExcept
@Test
void shouldGenerateExitWithoutSendingToNode(@TempDir final Path tempDir) throws IOException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
configureSuccessfulGenesisResponse(mockBeaconServer);
final Path outputFolder = tempDir.resolve("out");
final List<String> args = new ArrayList<>();
args.addAll(commandArgs);
Expand Down Expand Up @@ -320,6 +328,8 @@ void shouldGenerateExitWithoutSendingToNode(@TempDir final Path tempDir) throws
@Test
void shouldFailIfSaveFolderCannotBeCreated(@TempDir final Path tempDir) throws IOException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
configureSuccessfulGenesisResponse(mockBeaconServer);

final Path invalidOutputDestination = tempDir.resolve("testFile");
Files.writeString(invalidOutputDestination, "test");
final List<String> args = new ArrayList<>();
Expand All @@ -340,6 +350,8 @@ void shouldFailIfSaveFolderCannotBeCreated(@TempDir final Path tempDir) throws I
@DisabledOnOs(OS.WINDOWS) // can't set permissions on windows
void shouldFailIfSaveFolderHasInsufficientAccess(@TempDir final Path tempDir) throws IOException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
configureSuccessfulGenesisResponse(mockBeaconServer);

final Path invalidOutputDestination = tempDir.resolve("testFile");
tempDir.toFile().mkdir();
tempDir.toFile().setWritable(false);
Expand All @@ -356,9 +368,29 @@ void shouldFailIfSaveFolderHasInsufficientAccess(@TempDir final Path tempDir) th
assertThat(stdErr.toString(UTF_8)).contains("Failed to store exit for a756543");
}

@Test
void shouldFailIfGenesisDataNotAvailableAndNoEpochSpecified() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
final List<String> args =
getCommandArguments(false, true, List.of("--validator-public-keys", validatorPubKey1));
final int parseResult = beaconNodeCommand.parse(args.toArray(new String[0]));
assertThat(parseResult).isEqualTo(1);
assertThat(stdErr.toString(UTF_8)).contains("Could not calculate epoch from genesis data");
}

@Test
void shouldFailToGenerateExitWithoutBeaconNodeAvailable() {
final List<String> args =
List.of("voluntary-exit", "--validator-public-keys", validatorPubKey1);
final int parseResult = beaconNodeCommand.parse(args.toArray(new String[0]));
assertThat(parseResult).isEqualTo(1);
assertThat(stdErr.toString(UTF_8)).contains("Failed to connect to beacon node.");
}

@Test
void shouldExitFailureWithNoValidatorKeysFound() throws JsonProcessingException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

final List<String> args = commandArgs.subList(0, 5);
int parseResult = beaconNodeCommand.parse(args.toArray(new String[0]));
Expand All @@ -370,6 +402,7 @@ void shouldExitFailureWithNoValidatorKeysFound() throws JsonProcessingException
@Test
void shouldExitFailureFutureEpoch() throws IOException {
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

final List<String> args = getCommandArguments(false, true, List.of("--epoch=1024"));
int parseResult = beaconNodeCommand.parse(args.toArray(new String[0]));
Expand All @@ -383,6 +416,7 @@ void shouldExitFailureFutureEpoch() throws IOException {
void shouldCreateExitForFutureEpochIfOutputFolderDefined(@TempDir final Path tempDir)
throws IOException {
configureSuccessfulSpecResponse(mockBeaconServer, TestSpecFactory.createMinimalCapella());
configureSuccessfulGenesisResponse(mockBeaconServer);
final List<String> args = new ArrayList<>();
args.addAll(commandArgs);
args.addAll(
Expand All @@ -403,6 +437,8 @@ void shouldCreateExitForFutureEpochIfOutputFolderDefined(@TempDir final Path tem
void shouldUseCurrentForkDomainForSignatureBeforeDeneb() throws JsonProcessingException {
setUserInput("yes");
configureSuccessfulSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

final Supplier<List<SignedVoluntaryExit>> exitsCapture =
configureSuccessfulVoluntaryExitResponseWithCapture(mockBeaconServer);

Expand All @@ -427,6 +463,8 @@ void shouldUseCurrentForkDomainForSignatureBeforeDeneb() throws JsonProcessingEx
void shouldUseCapellaForkDomainForSignatureAfterCapella() throws JsonProcessingException {
setUserInput("yes");
configureSuccessfulDenebSpecResponse(mockBeaconServer);
configureSuccessfulGenesisResponse(mockBeaconServer);

final Supplier<List<SignedVoluntaryExit>> exitsCapture =
configureSuccessfulVoluntaryExitResponseWithCapture(mockBeaconServer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void validateOrDefaultEpoch(final Optional<GenesisData> maybeGenesisData
if (epoch == null) {
if (maybeEpoch.isEmpty()) {
throw new InvalidConfigurationException(
"Could not calculate epoch from latest block header, please specify --epoch");
"Could not calculate epoch from genesis data, please specify --epoch");
}
epoch = maybeEpoch.orElseThrow();
} else if (maybeEpoch.isPresent()
Expand Down

0 comments on commit eac5cb4

Please sign in to comment.