|
|
|
@ -48,7 +48,6 @@ import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
@ -184,10 +183,11 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
public void callingWithConfigOptionButNonExistingFileShouldDisplayHelp() throws IOException { |
|
|
|
|
assumeTrue(isFullInstantiation()); |
|
|
|
|
|
|
|
|
|
final File tempConfigFile = temp.newFile("an-invalid-file-name-without-extension"); |
|
|
|
|
parseCommand("--config-file", tempConfigFile.getPath()); |
|
|
|
|
final Path tempConfigFilePath = createTempFile("an-invalid-file-name-without-extension", ""); |
|
|
|
|
parseCommand("--config-file", tempConfigFilePath.toString()); |
|
|
|
|
|
|
|
|
|
final String expectedOutputStart = "Unable to read TOML configuration file " + tempConfigFile; |
|
|
|
|
final String expectedOutputStart = |
|
|
|
|
"Unable to read TOML configuration file " + tempConfigFilePath; |
|
|
|
|
assertThat(commandErrorOutput.toString()).startsWith(expectedOutputStart); |
|
|
|
|
assertThat(commandOutput.toString()).isEmpty(); |
|
|
|
|
} |
|
|
|
@ -209,20 +209,15 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
|
|
|
|
|
// We write a config file to prevent an invalid file in resource folder to raise errors in
|
|
|
|
|
// code checks (CI + IDE)
|
|
|
|
|
final File tempConfigFile = temp.newFile("invalid_config.toml"); |
|
|
|
|
try (final Writer fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8)) { |
|
|
|
|
|
|
|
|
|
fileWriter.write("."); // an invalid toml content
|
|
|
|
|
fileWriter.flush(); |
|
|
|
|
final Path tempConfigFile = createTempFile("invalid_config.toml", "."); |
|
|
|
|
|
|
|
|
|
parseCommand("--config-file", tempConfigFile.getPath()); |
|
|
|
|
parseCommand("--config-file", tempConfigFile.toString()); |
|
|
|
|
|
|
|
|
|
final String expectedOutputStart = |
|
|
|
|
"Invalid TOML configuration : Unexpected '.', expected a-z, A-Z, 0-9, ', \", a table key, " |
|
|
|
|
+ "a newline, or end-of-input (line 1, column 1)"; |
|
|
|
|
assertThat(commandErrorOutput.toString()).startsWith(expectedOutputStart); |
|
|
|
|
assertThat(commandOutput.toString()).isEmpty(); |
|
|
|
|
} |
|
|
|
|
final String expectedOutputStart = |
|
|
|
|
"Invalid TOML configuration : Unexpected '.', expected a-z, A-Z, 0-9, ', \", a table key, " |
|
|
|
|
+ "a newline, or end-of-input (line 1, column 1)"; |
|
|
|
|
assertThat(commandErrorOutput.toString()).startsWith(expectedOutputStart); |
|
|
|
|
assertThat(commandOutput.toString()).isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -231,20 +226,14 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
|
|
|
|
|
// We write a config file to prevent an invalid file in resource folder to raise errors in
|
|
|
|
|
// code checks (CI + IDE)
|
|
|
|
|
final File tempConfigFile = temp.newFile("invalid_config.toml"); |
|
|
|
|
try (final Writer fileWriter = Files.newBufferedWriter(tempConfigFile.toPath(), UTF_8)) { |
|
|
|
|
final Path tempConfigFile = createTempFile("invalid_config.toml", "tester===========......."); |
|
|
|
|
parseCommand("--config-file", tempConfigFile.toString()); |
|
|
|
|
|
|
|
|
|
fileWriter.write("tester===========......."); // an invalid toml content
|
|
|
|
|
fileWriter.flush(); |
|
|
|
|
|
|
|
|
|
parseCommand("--config-file", tempConfigFile.getPath()); |
|
|
|
|
|
|
|
|
|
final String expectedOutputStart = |
|
|
|
|
"Invalid TOML configuration : Unexpected '=', expected ', \", ''', \"\"\", a number, " |
|
|
|
|
+ "a boolean, a date/time, an array, or a table (line 1, column 8)"; |
|
|
|
|
assertThat(commandErrorOutput.toString()).startsWith(expectedOutputStart); |
|
|
|
|
assertThat(commandOutput.toString()).isEmpty(); |
|
|
|
|
} |
|
|
|
|
final String expectedOutputStart = |
|
|
|
|
"Invalid TOML configuration : Unexpected '=', expected ', \", ''', \"\"\", a number, " |
|
|
|
|
+ "a boolean, a date/time, an array, or a table (line 1, column 8)"; |
|
|
|
|
assertThat(commandErrorOutput.toString()).startsWith(expectedOutputStart); |
|
|
|
|
assertThat(commandOutput.toString()).isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -256,8 +245,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
final String updatedConfig = |
|
|
|
|
Resources.toString(configFile, UTF_8) |
|
|
|
|
.replace("~/genesis.json", escapeTomlString(genesisFile.toString())); |
|
|
|
|
final Path toml = Files.createTempFile("toml", ""); |
|
|
|
|
Files.write(toml, updatedConfig.getBytes(UTF_8)); |
|
|
|
|
final Path toml = createTempFile("toml", updatedConfig.getBytes(UTF_8)); |
|
|
|
|
|
|
|
|
|
Collection<RpcApi> expectedApis = asList(ETH, WEB3); |
|
|
|
|
|
|
|
|
@ -341,10 +329,8 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
public void permissionsTomlFileWithNoPermissionsEnabledMustError() throws IOException { |
|
|
|
|
|
|
|
|
|
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); |
|
|
|
|
final Path permToml = Files.createTempFile("toml", ""); |
|
|
|
|
Files.write(permToml, Resources.toByteArray(configFile)); |
|
|
|
|
final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); |
|
|
|
|
parseCommand("--permissions-config-file", permToml.toString()); |
|
|
|
|
permToml.toFile().deleteOnExit(); |
|
|
|
|
|
|
|
|
|
verify(mockRunnerBuilder).build(); |
|
|
|
|
|
|
|
|
@ -353,7 +339,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustError() throws IOException { |
|
|
|
|
public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustError() { |
|
|
|
|
parseCommand("--p2p-enabled", "false"); |
|
|
|
|
|
|
|
|
|
verify(mockRunnerBuilder).build(); |
|
|
|
@ -366,8 +352,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
public void permissionsTomlPathMustUseOption() throws IOException { |
|
|
|
|
|
|
|
|
|
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); |
|
|
|
|
final Path permToml = Files.createTempFile("toml", ""); |
|
|
|
|
Files.write(permToml, Resources.toByteArray(configFile)); |
|
|
|
|
final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); |
|
|
|
|
|
|
|
|
|
parseCommand( |
|
|
|
|
"--permissions-accounts-enabled", "--permissions-config-file", permToml.toString()); |
|
|
|
@ -394,8 +379,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
|
|
|
|
|
// Load a TOML that configures literally everything (except permissioning TOML config)
|
|
|
|
|
final URL configFile = Resources.getResource("everything_config.toml"); |
|
|
|
|
final Path toml = Files.createTempFile("toml", ""); |
|
|
|
|
Files.write(toml, Resources.toByteArray(configFile)); |
|
|
|
|
final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); |
|
|
|
|
|
|
|
|
|
// Parse it.
|
|
|
|
|
final CommandLine.Model.CommandSpec spec = parseCommand("--config-file", toml.toString()); |
|
|
|
@ -480,6 +464,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
@Test |
|
|
|
|
public void nodekeyOptionMustBeUsed() throws Exception { |
|
|
|
|
final File file = new File("./specific/key"); |
|
|
|
|
file.deleteOnExit(); |
|
|
|
|
|
|
|
|
|
parseCommand("--node-private-key-file", file.getPath()); |
|
|
|
|
|
|
|
|
@ -501,6 +486,7 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
assumeFalse(isFullInstantiation()); |
|
|
|
|
|
|
|
|
|
final File file = new File("./specific/key"); |
|
|
|
|
file.deleteOnExit(); |
|
|
|
|
|
|
|
|
|
parseCommand("--node-private-key-file", file.getPath()); |
|
|
|
|
|
|
|
|
@ -591,8 +577,6 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
assumeTrue(isFullInstantiation()); |
|
|
|
|
|
|
|
|
|
final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); |
|
|
|
|
final ArgumentCaptor<EthNetworkConfig> networkArg = |
|
|
|
|
ArgumentCaptor.forClass(EthNetworkConfig.class); |
|
|
|
|
|
|
|
|
|
parseCommand("--genesis-file", genesisFile.toString(), "--network", "rinkeby"); |
|
|
|
|
|
|
|
|
@ -1639,10 +1623,6 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
public void metricsAndMetricsPushMustNotBeUsedTogether() throws Exception { |
|
|
|
|
assumeTrue(isFullInstantiation()); |
|
|
|
|
|
|
|
|
|
final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); |
|
|
|
|
final ArgumentCaptor<EthNetworkConfig> networkArg = |
|
|
|
|
ArgumentCaptor.forClass(EthNetworkConfig.class); |
|
|
|
|
|
|
|
|
|
parseCommand("--metrics-enabled", "--metrics-push-enabled"); |
|
|
|
|
|
|
|
|
|
verifyZeroInteractions(mockRunnerBuilder); |
|
|
|
@ -1880,15 +1860,16 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void privacyOptionsRequiresServiceToBeEnabled() { |
|
|
|
|
public void privacyOptionsRequiresServiceToBeEnabled() throws IOException { |
|
|
|
|
|
|
|
|
|
final File file = new File("./specific/public_key"); |
|
|
|
|
file.deleteOnExit(); |
|
|
|
|
|
|
|
|
|
parseCommand( |
|
|
|
|
"--privacy-url", |
|
|
|
|
ENCLAVE_URI, |
|
|
|
|
"--privacy-public-key-file", |
|
|
|
|
file.getPath(), |
|
|
|
|
file.toString(), |
|
|
|
|
"--privacy-precompiled-address", |
|
|
|
|
String.valueOf(Byte.MAX_VALUE - 1)); |
|
|
|
|
|
|
|
|
@ -1918,9 +1899,24 @@ public class PantheonCommandTest extends CommandTestAbstract { |
|
|
|
|
private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException { |
|
|
|
|
final Path genesisFile = Files.createTempFile("genesisFile", ""); |
|
|
|
|
Files.write(genesisFile, encodeJsonGenesis(jsonGenesis).getBytes(UTF_8)); |
|
|
|
|
genesisFile.toFile().deleteOnExit(); |
|
|
|
|
return genesisFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Path createTempFile(final String filename, final String contents) throws IOException { |
|
|
|
|
final Path file = Files.createTempFile(filename, ""); |
|
|
|
|
Files.write(file, contents.getBytes(UTF_8)); |
|
|
|
|
file.toFile().deleteOnExit(); |
|
|
|
|
return file; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Path createTempFile(final String filename, final byte[] contents) throws IOException { |
|
|
|
|
final Path file = Files.createTempFile(filename, ""); |
|
|
|
|
Files.write(file, contents); |
|
|
|
|
file.toFile().deleteOnExit(); |
|
|
|
|
return file; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String encodeJsonGenesis(final JsonObject jsonGenesis) { |
|
|
|
|
return jsonGenesis.encodePrettily(); |
|
|
|
|
} |
|
|
|
|