diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index b7b5655c50..d0dedc544a 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -136,6 +136,7 @@ public void startNode(final PantheonNode node) { private Path createGenesisFile(final PantheonNode node, final EthNetworkConfig ethNetworkConfig) { try { Path genesisFile = Files.createTempFile(node.homeDirectory(), "genesis", ""); + genesisFile.toFile().deleteOnExit(); Files.write(genesisFile, ethNetworkConfig.getGenesisConfig().getBytes(UTF_8)); return genesisFile; } catch (IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java index f2f94407c8..1fda4335bf 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java @@ -223,6 +223,7 @@ public PantheonNode createNodeWithNodesWhitelist( PermissioningConfiguration.createDefault(); permissioningConfiguration.setNodeWhitelist(nodesWhitelist); File tempFile = createTempPermissioningConfigurationFile(); + tempFile.deleteOnExit(); permissioningConfiguration.setConfigurationFilePath(tempFile.getPath()); initPermissioningConfigurationFile( WhitelistPersistor.WHITELIST_TYPE.NODES, diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java index bf13091b63..f710ee2565 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java @@ -46,6 +46,7 @@ import java.net.InetAddress; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -414,8 +415,10 @@ public void rejectIncomingConnectionFromNonWhitelistedPeer() throws Exception { final PeerBlacklist localBlacklist = new PeerBlacklist(); final PeerBlacklist remoteBlacklist = new PeerBlacklist(); final PermissioningConfiguration config = PermissioningConfiguration.createDefault(); - config.setConfigurationFilePath( - Files.createTempFile("test", "test").toAbsolutePath().toString()); + final Path tempFile = Files.createTempFile("test", "test"); + tempFile.toFile().deleteOnExit(); + config.setConfigurationFilePath(tempFile.toAbsolutePath().toString()); + final NodeWhitelistController localWhitelistController = new NodeWhitelistController(config, Collections.emptyList()); // turn on whitelisting by adding a different node NOT remote node diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java index 148db0eb44..1d47042576 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.net.URI; import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -1212,8 +1213,9 @@ private PeerDiscoveryController startPeerDiscoveryController( private PermissioningConfiguration permissioningConfigurationWithTempFile() throws IOException { final PermissioningConfiguration config = PermissioningConfiguration.createDefault(); - config.setConfigurationFilePath( - Files.createTempFile("test", "test").toAbsolutePath().toString()); + Path tempFile = Files.createTempFile("test", "test"); + tempFile.toFile().deleteOnExit(); + config.setConfigurationFilePath(tempFile.toAbsolutePath().toString()); return config; } diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java index a9c56f2525..89958391d0 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java @@ -32,6 +32,7 @@ import tech.pegasys.pantheon.util.bytes.BytesValue; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -480,10 +481,11 @@ public void shouldNotBondWithNodesRejectedByWhitelist() throws Exception { final DiscoveryPeer peerA = new DiscoveryPeer(createId(1), "127.0.0.1", 1, 1); final DiscoveryPeer peerB = new DiscoveryPeer(createId(2), "127.0.0.2", 2, 2); + final Path tempFile = Files.createTempFile("test", "test"); + tempFile.toFile().deleteOnExit(); final PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration.createDefault(); - permissioningConfiguration.setConfigurationFilePath( - Files.createTempFile("test", "test").toAbsolutePath().toString()); + permissioningConfiguration.setConfigurationFilePath(tempFile.toAbsolutePath().toString()); final NodeWhitelistController peerWhitelist = new NodeWhitelistController(permissioningConfiguration, Collections.emptyList()); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistControllerTest.java index 0a7803e769..4823617af5 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistControllerTest.java @@ -234,6 +234,7 @@ public void accountThatDoesNotStartWith0xIsNotValid() { private Path createPermissionsFileWithAccount(final String account) throws IOException { final String nodePermissionsFileContent = "accounts-whitelist=[\"" + account + "\"]"; final Path permissionsFile = Files.createTempFile("account_permissions", ""); + permissionsFile.toFile().deleteOnExit(); Files.write(permissionsFile, nodePermissionsFileContent.getBytes(StandardCharsets.UTF_8)); return permissionsFile; } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeWhitelistControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeWhitelistControllerTest.java index c1bd99eece..0f2b97f6dd 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeWhitelistControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeWhitelistControllerTest.java @@ -388,6 +388,7 @@ public void whenReloadingWhitelistAndNothingChangesShouldNotNotifyWhitelistModif private Path createPermissionsFileWithNode(final String node) throws IOException { final String nodePermissionsFileContent = "nodes-whitelist=[\"" + node + "\"]"; final Path permissionsFile = Files.createTempFile("node_permissions", ""); + permissionsFile.toFile().deleteOnExit(); Files.write(permissionsFile, nodePermissionsFileContent.getBytes(StandardCharsets.UTF_8)); return permissionsFile; } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilderTest.java index cab95ffe5b..a6208535af 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilderTest.java @@ -12,9 +12,11 @@ */ package tech.pegasys.pantheon.ethereum.permissioning; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; +import java.io.IOException; import java.net.URI; import java.net.URL; import java.nio.file.Files; @@ -53,8 +55,7 @@ public void permissioningConfig() throws Exception { final String uri2 = "enode://" + VALID_NODE_ID + "@192.169.0.9:4568"; final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_VALID); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration = permissioningConfig(toml); @@ -71,8 +72,7 @@ public void permissioningConfigWithOnlyNodeWhitelistSet() throws Exception { final String uri = "enode://" + VALID_NODE_ID + "@192.168.0.9:4567"; final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfiguration( @@ -86,8 +86,7 @@ public void permissioningConfigWithOnlyNodeWhitelistSet() throws Exception { @Test public void permissioningConfigWithOnlyAccountWhitelistSet() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfiguration( @@ -102,8 +101,7 @@ public void permissioningConfigWithOnlyAccountWhitelistSet() throws Exception { @Test public void permissioningConfigWithInvalidAccount() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ACCOUNT); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -115,8 +113,7 @@ public void permissioningConfigWithInvalidAccount() throws Exception { @Test public void permissioningConfigWithInvalidEnode() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ENODE); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -128,8 +125,7 @@ public void permissioningConfigWithInvalidEnode() throws Exception { @Test public void permissioningConfigWithEmptyWhitelistMustNotError() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_EMPTY_WHITELISTS); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration = permissioningConfig(toml); @@ -142,8 +138,7 @@ public void permissioningConfigWithEmptyWhitelistMustNotError() throws Exception @Test public void permissioningConfigWithAbsentWhitelistMustThrowException() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -153,8 +148,7 @@ public void permissioningConfigWithAbsentWhitelistMustThrowException() throws Ex @Test public void permissioningConfigWithUnrecognizedKeyMustThrowException() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_UNRECOGNIZED_KEY); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -167,7 +161,7 @@ public void permissioningConfigWithUnrecognizedKeyMustThrowException() throws Ex @Test public void permissioningConfigWithEmptyFileMustThrowException() throws Exception { // write an empty file - final Path toml = Files.createTempFile("toml", ""); + final Path toml = createTempFile("toml", "".getBytes(UTF_8)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -177,8 +171,7 @@ public void permissioningConfigWithEmptyFileMustThrowException() throws Exceptio @Test public void permissioningConfigFromFileMustSetFilePath() throws Exception { final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_VALID); - final Path toml = Files.createTempFile("toml", ""); - Files.write(toml, Resources.toByteArray(configFile)); + final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfigurationFromToml( @@ -213,4 +206,11 @@ private PermissioningConfiguration permissioningConfig(final Path toml) throws E return PermissioningConfigurationBuilder.permissioningConfiguration( toml.toAbsolutePath().toString(), true, true); } + + 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; + } } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/WhitelistPersistorTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/WhitelistPersistorTest.java index a3b2a0fdfa..9c948b8f3c 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/WhitelistPersistorTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/WhitelistPersistorTest.java @@ -43,6 +43,7 @@ public class WhitelistPersistorTest { public void setUp() throws IOException { List lines = Lists.newArrayList(nodesWhitelist, accountsWhitelist); tempFile = File.createTempFile("test", "test"); + tempFile.deleteOnExit(); Files.write(tempFile.toPath(), lines, StandardOpenOption.WRITE, StandardOpenOption.CREATE); whitelistPersistor = new WhitelistPersistor(tempFile.getAbsolutePath()); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index a0f1aafeac..7949572c3a 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -48,7 +48,6 @@ 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 void callingWithConfigOptionButNoConfigFileShouldDisplayHelp() { 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 void callingWithConfigOptionButInvalidContentTomlFileShouldDisplayHelp() // 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 void callingWithConfigOptionButInvalidValueTomlFileShouldDisplayHelp() th // 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 void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException 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 expectedApis = asList(ETH, WEB3); @@ -341,10 +329,8 @@ public void permissionsEnabledWithNonexistentConfigFileMustError() { 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 void permissionsTomlFileWithNoPermissionsEnabledMustError() throws IOExce } @Test - public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustError() throws IOException { + public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustError() { parseCommand("--p2p-enabled", "false"); verify(mockRunnerBuilder).build(); @@ -366,8 +352,7 @@ public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustError() throws 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 void tomlThatConfiguresEverythingExceptPermissioningToml() throws IOExcep // 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 void configOptionDisabledUnderDocker() { @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 void nodekeyOptionDisabledUnderDocker() { assumeFalse(isFullInstantiation()); final File file = new File("./specific/key"); + file.deleteOnExit(); parseCommand("--node-private-key-file", file.getPath()); @@ -591,8 +577,6 @@ public void genesisAndNetworkMustNotBeUsedTogether() throws Exception { assumeTrue(isFullInstantiation()); final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); - final ArgumentCaptor networkArg = - ArgumentCaptor.forClass(EthNetworkConfig.class); parseCommand("--genesis-file", genesisFile.toString(), "--network", "rinkeby"); @@ -1639,10 +1623,6 @@ public void metricsPrometheusJobMustBeUsed() { public void metricsAndMetricsPushMustNotBeUsedTogether() throws Exception { assumeTrue(isFullInstantiation()); - final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); - final ArgumentCaptor networkArg = - ArgumentCaptor.forClass(EthNetworkConfig.class); - parseCommand("--metrics-enabled", "--metrics-push-enabled"); verifyZeroInteractions(mockRunnerBuilder); @@ -1880,15 +1860,16 @@ public void mustUseEnclaveUriAndOptions() throws IOException { } @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 void mustVerifyPrivacyIsDisabled() throws IOException { 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(); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidatorTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidatorTest.java index da3e65afc1..b4cf39c40a 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidatorTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidatorTest.java @@ -58,6 +58,7 @@ public void nodesWhitelistOptionWhichDoesNotIncludeBootnodesMustError() throws E final URL configFile = Resources.getResource(PERMISSIONING_CONFIG); final Path toml = Files.createTempFile("toml", ""); + toml.toFile().deleteOnExit(); Files.write(toml, Resources.toByteArray(configFile)); PermissioningConfiguration permissioningConfiguration =