Skip to content

Commit

Permalink
Merge pull request #2145 from rsksmart/fingerroot530-master-merge
Browse files Browse the repository at this point in the history
FINGERROOT-5.3.0 -> master merge
  • Loading branch information
Vovchyk authored Oct 2, 2023
2 parents e06686f + 3f0bf43 commit 6dde0cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
9 changes: 3 additions & 6 deletions rskj-core/src/main/java/co/rsk/cli/RskCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ static class NetworkFlags {
@CommandLine.Option(names = {"-r", "--reset"}, description = "Reset the database")
private boolean dbReset;

@CommandLine.Option(names = {"--import"}, description = "Import database")
private String dbImport;
@CommandLine.Option(names = {"-i", "--import"}, description = "Import database")
private boolean dbImport;

// config flags
@CommandLine.Option(names = {"--verify-config"}, description = "Verify configuration")
Expand Down Expand Up @@ -110,9 +110,8 @@ private void loadCliArgs() {
activatedFlags.add(NodeCliFlags.DB_RESET);
}

if (dbImport != null) {
if (dbImport) {
activatedFlags.add(NodeCliFlags.DB_IMPORT);
paramValueMap.put("import", dbImport);
}

if (verifyConfig) {
Expand All @@ -129,12 +128,10 @@ private void loadCliArgs() {

if (rpcCors != null) {
activatedOptions.put(NodeCliOptions.RPC_CORS, rpcCors);
paramValueMap.put("rpc-cors", rpcCors);
}

if (basePath != null) {
activatedOptions.put(NodeCliOptions.BASE_PATH, basePath);
paramValueMap.put("base-path", basePath);
}

if (xArguments != null) {
Expand Down
36 changes: 33 additions & 3 deletions rskj-core/src/test/java/co/rsk/cli/RskCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,43 @@ void shouldReturnTrueIfVersionRequested() {
rskCli.load(args);
assertTrue(rskCli.getCliArgs().getFlags().contains(NodeCliFlags.VERSION));
}

@Test
void argsAreParsedCorrectly() {
RskCli rskCli = new RskCli();
String[] args = {"--main", "--skip-java-check", "--print-system-info", "--verify-config", "--reset"};
rskCli.load(args);
String[] mainnetArgs = {"--main", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="};
rskCli.load(mainnetArgs);
CliArgs<NodeCliOptions, NodeCliFlags> parsedArgs = rskCli.getCliArgs();
assertEquals(5, parsedArgs.getFlags().size());
assertEquals(6, parsedArgs.getFlags().size());
assertEquals(2, parsedArgs.getOptions().size());
assertEquals(1, parsedArgs.getParamValueMap().size());

assertEquals("*", parsedArgs.getOptions().get(NodeCliOptions.RPC_CORS));
assertEquals("./test-db", parsedArgs.getOptions().get(NodeCliOptions.BASE_PATH));

rskCli = new RskCli();
String[] shortArgs = {"-r", "-i"};
rskCli.load(shortArgs);
parsedArgs = rskCli.getCliArgs();
assertEquals(2, parsedArgs.getFlags().size());
assertTrue(parsedArgs.getFlags().contains(NodeCliFlags.DB_RESET));
assertTrue(parsedArgs.getFlags().contains(NodeCliFlags.DB_IMPORT));

rskCli = new RskCli();
String[] testnetArgs = {"--testnet", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="};
rskCli.load(testnetArgs);
parsedArgs = rskCli.getCliArgs();
assertEquals(6, parsedArgs.getFlags().size());
assertEquals(2, parsedArgs.getOptions().size());
assertEquals(1, parsedArgs.getParamValueMap().size());

rskCli = new RskCli();
String[] regtestArgs = {"--regtest", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="};
rskCli.load(regtestArgs);
parsedArgs = rskCli.getCliArgs();
assertEquals(6, parsedArgs.getFlags().size());
assertEquals(2, parsedArgs.getOptions().size());
assertEquals(1, parsedArgs.getParamValueMap().size());
}

}

0 comments on commit 6dde0cd

Please sign in to comment.