From ad7e26bcb5aa3bf7c17a8ead2582f4d2b386c917 Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta <45264458+abdelhamidbakhta@users.noreply.github.com> Date: Wed, 24 Apr 2019 19:15:05 +0200 Subject: [PATCH] [PIE-1531] Allow whitespace in file paths loaded from resources directory (#1329) * [PIE-1531] Allow whitespace in file paths loaded from resources directory. * replace Resources.getResource call * Update LocalPermissioningConfigurationValidatorTest.java * Update RpcAuthFileValidatorTest.java * fix paths * Update SmartContractNodePermissioningAcceptanceTestBase.java --- .../dsl/node/factory/PantheonNodeFactory.java | 6 +-- .../node/factory/PermissionedNodeBuilder.java | 2 +- ...ctNodePermissioningAcceptanceTestBase.java | 2 +- .../pantheon/config/GenesisConfigFile.java | 6 ++- .../mainnet/MainnetProtocolSpecs.java | 2 +- .../mainnet/MainnetProtocolScheduleTest.java | 2 +- .../ethtaskutils/BlockchainSetupUtil.java | 6 +-- .../eth/messages/BlockBodiesMessageTest.java | 2 +- .../eth/messages/BlockHeadersMessageTest.java | 2 +- .../messages/GetBlockBodiesMessageTest.java | 2 +- .../messages/NewBlockHashesMessageTest.java | 2 +- ...PermissioningConfigurationBuilderTest.java | 38 +++++++++---------- ...rtContractPermissioningControllerTest.java | 19 +++++----- .../pantheon/cli/EthNetworkConfig.java | 12 +++--- .../pantheon/cli/PantheonCommandTest.java | 18 ++++----- .../cli/custom/RpcAuthFileValidatorTest.java | 13 +++---- .../pantheon/util/BlockImporterTest.java | 4 +- ...rmissioningConfigurationValidatorTest.java | 8 ++-- .../pantheon/testutil/BlockTestUtil.java | 2 +- 19 files changed, 75 insertions(+), 73 deletions(-) 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 5a6652c4b8..9b647216e4 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 @@ -267,14 +267,14 @@ public PantheonNode createIbftNodeWithValidators(final String name, final String private Optional createCliqueGenesisConfig( final Collection validators) { - final String template = readGenesisFile("clique/clique.json"); + final String template = readGenesisFile("/clique/clique.json"); return updateGenesisExtraData( validators, template, CliqueExtraData::createGenesisExtraDataString); } private Optional createIbftGenesisConfig( final Collection validators) { - final String template = readGenesisFile("ibft/ibft.json"); + final String template = readGenesisFile("/ibft/ibft.json"); return updateGenesisExtraData( validators, template, IbftExtraData::createGenesisExtraDataString); } @@ -292,7 +292,7 @@ private Optional updateGenesisExtraData( private String readGenesisFile(final String filepath) { try { - final URI uri = Resources.getResource(filepath).toURI(); + final URI uri = this.getClass().getResource(filepath).toURI(); return Resources.toString(uri.toURL(), Charset.defaultCharset()); } catch (final URISyntaxException | IOException e) { throw new IllegalStateException("Unable to get test genesis config " + filepath); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java index 94d348f0da..c5a78501da 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java @@ -120,7 +120,7 @@ public PermissionedNodeBuilder nodesContractEnabled(final String address) { public PermissionedNodeBuilder genesisFile(final String path) { try { - URI uri = Resources.getResource(path).toURI(); + URI uri = this.getClass().getResource(path).toURI(); this.genesisFile = Resources.toString(uri.toURL(), Charset.defaultCharset()); } catch (final URISyntaxException | IOException e) { throw new IllegalStateException("Unable to read genesis file from: " + path, e); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/SmartContractNodePermissioningAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/SmartContractNodePermissioningAcceptanceTestBase.java index 6d640f81ea..5bfbb1d556 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/SmartContractNodePermissioningAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/SmartContractNodePermissioningAcceptanceTestBase.java @@ -31,7 +31,7 @@ class SmartContractNodePermissioningAcceptanceTestBase extends AcceptanceTestBas private final SmartContractNodePermissioningConditions smartContractNodePermissioningConditions; private static final String CONTRACT_ADDRESS = "0x0000000000000000000000000000000000009999"; - private static final String GENESIS_FILE = "permissioning/simple_permissioning_genesis.json"; + private static final String GENESIS_FILE = "/permissioning/simple_permissioning_genesis.json"; protected final Cluster permissionedCluster; diff --git a/config/src/main/java/tech/pegasys/pantheon/config/GenesisConfigFile.java b/config/src/main/java/tech/pegasys/pantheon/config/GenesisConfigFile.java index 2bab85be0d..bb40077160 100644 --- a/config/src/main/java/tech/pegasys/pantheon/config/GenesisConfigFile.java +++ b/config/src/main/java/tech/pegasys/pantheon/config/GenesisConfigFile.java @@ -36,7 +36,8 @@ private GenesisConfigFile(final JsonObject config) { public static GenesisConfigFile mainnet() { try { - return fromConfig(Resources.toString(Resources.getResource("mainnet.json"), UTF_8)); + return fromConfig( + Resources.toString(GenesisConfigFile.class.getResource("/mainnet.json"), UTF_8)); } catch (final IOException e) { throw new IllegalStateException(e); } @@ -44,7 +45,8 @@ public static GenesisConfigFile mainnet() { public static GenesisConfigFile development() { try { - return fromConfig(Resources.toString(Resources.getResource("dev.json"), UTF_8)); + return fromConfig( + Resources.toString(GenesisConfigFile.class.getResource("/dev.json"), UTF_8)); } catch (final IOException e) { throw new IllegalStateException(e); } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSpecs.java index fe96d6cf51..dd10815de3 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSpecs.java @@ -276,7 +276,7 @@ private void updateWorldStateForDao(final MutableWorldState worldState) { final JsonArray json = new JsonArray( Resources.toString( - Resources.getResource("daoAddresses.json"), StandardCharsets.UTF_8)); + this.getClass().getResource("/daoAddresses.json"), StandardCharsets.UTF_8)); final List
addresses = IntStream.range(0, json.size()) .mapToObj(json::getString) diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java index 72a41b416f..bf857dabe4 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java @@ -94,7 +94,7 @@ public void shouldCreateRopstenConfig() throws Exception { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig( Resources.toString( - Resources.getResource("ropsten.json"), StandardCharsets.UTF_8)) + this.getClass().getResource("/ropsten.json"), StandardCharsets.UTF_8)) .getConfigOptions(), PrivacyParameters.DEFAULT); Assertions.assertThat(sched.getByBlockNumber(0).getName()).isEqualTo("TangerineWhistle"); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java index f6db36633a..13db01cb88 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java @@ -96,7 +96,7 @@ public static BlockchainSetupUtil forTesting() { final TemporaryFolder temp = new TemporaryFolder(); try { temp.create(); - final URL genesisFileUrl = getResourceUrl(temp, "testGenesis.json"); + final URL genesisFileUrl = getResourceUrl(temp, "/testGenesis.json"); final GenesisState genesisState = GenesisState.fromJson( Resources.toString(genesisFileUrl, Charsets.UTF_8), protocolSchedule); @@ -107,7 +107,7 @@ public static BlockchainSetupUtil forTesting() { final ProtocolContext protocolContext = new ProtocolContext<>(blockchain, worldArchive, null); - final Path blocksPath = getResourcePath(temp, "testBlockchain.blocks"); + final Path blocksPath = getResourcePath(temp, "/testBlockchain.blocks"); final List blocks = new ArrayList<>(); final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); @@ -128,7 +128,7 @@ public static BlockchainSetupUtil forTesting() { private static Path getResourcePath(final TemporaryFolder temp, final String resource) throws IOException { - final URL url = Resources.getResource(resource); + final URL url = BlockchainSetupUtil.class.getResource(resource); final Path path = Files.write( temp.newFile().toPath(), diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java index 3f17fbe25a..a0afc02048 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java @@ -42,7 +42,7 @@ public final class BlockBodiesMessageTest { public void blockBodiesRoundTrip() throws IOException { final List bodies = new ArrayList<>(); final ByteBuffer buffer = - ByteBuffer.wrap(Resources.toByteArray(Resources.getResource("50.blocks"))); + ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks"))); for (int i = 0; i < 50; ++i) { final int blockSize = RLP.calculateSize(BytesValue.wrapBuffer(buffer)); final byte[] block = new byte[blockSize]; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java index ef02021577..60795272b8 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java @@ -39,7 +39,7 @@ public final class BlockHeadersMessageTest { public void blockHeadersRoundTrip() throws IOException { final List headers = new ArrayList<>(); final ByteBuffer buffer = - ByteBuffer.wrap(Resources.toByteArray(Resources.getResource("50.blocks"))); + ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks"))); for (int i = 0; i < 50; ++i) { final int blockSize = RLP.calculateSize(BytesValue.wrapBuffer(buffer)); final byte[] block = new byte[blockSize]; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/GetBlockBodiesMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/GetBlockBodiesMessageTest.java index 426ef274f1..643c355f7f 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/GetBlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/GetBlockBodiesMessageTest.java @@ -39,7 +39,7 @@ public final class GetBlockBodiesMessageTest { public void getBlockBodiesRoundTrip() throws IOException { final List hashes = new ArrayList<>(); final ByteBuffer buffer = - ByteBuffer.wrap(Resources.toByteArray(Resources.getResource("50.blocks"))); + ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks"))); for (int i = 0; i < 50; ++i) { final int blockSize = RLP.calculateSize(BytesValue.wrapBuffer(buffer)); final byte[] block = new byte[blockSize]; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockHashesMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockHashesMessageTest.java index fde23c8c87..c982587295 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockHashesMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockHashesMessageTest.java @@ -38,7 +38,7 @@ public final class NewBlockHashesMessageTest { public void blockHeadersRoundTrip() throws IOException { final List hashes = new ArrayList<>(); final ByteBuffer buffer = - ByteBuffer.wrap(Resources.toByteArray(Resources.getResource("50.blocks"))); + ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks"))); for (int i = 0; i < 50; ++i) { final int blockSize = RLP.calculateSize(BytesValue.wrapBuffer(buffer)); final byte[] block = new byte[blockSize]; diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/LocalPermissioningConfigurationBuilderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/LocalPermissioningConfigurationBuilderTest.java index cee16c2633..d982c8943b 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/LocalPermissioningConfigurationBuilderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/LocalPermissioningConfigurationBuilderTest.java @@ -28,23 +28,23 @@ public class LocalPermissioningConfigurationBuilderTest { - private static final String PERMISSIONING_CONFIG_VALID = "permissioning_config.toml"; + private static final String PERMISSIONING_CONFIG_VALID = "/permissioning_config.toml"; private static final String PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY = - "permissioning_config_account_whitelist_only.toml"; + "/permissioning_config_account_whitelist_only.toml"; private static final String PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY = - "permissioning_config_node_whitelist_only.toml"; + "/permissioning_config_node_whitelist_only.toml"; private static final String PERMISSIONING_CONFIG_INVALID_ENODE = - "permissioning_config_invalid_enode.toml"; + "/permissioning_config_invalid_enode.toml"; private static final String PERMISSIONING_CONFIG_INVALID_ACCOUNT = - "permissioning_config_invalid_account.toml"; + "/permissioning_config_invalid_account.toml"; private static final String PERMISSIONING_CONFIG_EMPTY_WHITELISTS = - "permissioning_config_empty_whitelists.toml"; + "/permissioning_config_empty_whitelists.toml"; private static final String PERMISSIONING_CONFIG_ABSENT_WHITELISTS = - "permissioning_config_absent_whitelists.toml"; + "/permissioning_config_absent_whitelists.toml"; private static final String PERMISSIONING_CONFIG_UNRECOGNIZED_KEY = - "permissioning_config_unrecognized_key.toml"; + "/permissioning_config_unrecognized_key.toml"; private static final String PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY_MULTILINE = - "permissioning_config_node_whitelist_only_multiline.toml"; + "/permissioning_config_node_whitelist_only_multiline.toml"; private final String VALID_NODE_ID = "6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; @@ -54,7 +54,7 @@ public void permissioningConfig() throws Exception { final String uri = "enode://" + VALID_NODE_ID + "@192.168.0.9:4567"; final String uri2 = "enode://" + VALID_NODE_ID + "@192.169.0.9:4568"; - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_VALID); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_VALID); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); LocalPermissioningConfiguration permissioningConfiguration = permissioningConfig(toml); @@ -71,7 +71,7 @@ public void permissioningConfig() throws Exception { 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 URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); LocalPermissioningConfiguration permissioningConfiguration = @@ -85,7 +85,7 @@ public void permissioningConfigWithOnlyNodeWhitelistSet() throws Exception { @Test public void permissioningConfigWithOnlyAccountWhitelistSet() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); LocalPermissioningConfiguration permissioningConfiguration = @@ -100,7 +100,7 @@ public void permissioningConfigWithOnlyAccountWhitelistSet() throws Exception { @Test public void permissioningConfigWithInvalidAccount() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ACCOUNT); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_INVALID_ACCOUNT); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> accountOnlyPermissioningConfig(toml)); @@ -112,7 +112,7 @@ public void permissioningConfigWithInvalidAccount() throws Exception { @Test public void permissioningConfigWithInvalidEnode() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ENODE); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_INVALID_ENODE); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> nodeOnlyPermissioningConfig(toml)); @@ -124,7 +124,7 @@ public void permissioningConfigWithInvalidEnode() throws Exception { @Test public void permissioningConfigWithEmptyWhitelistMustNotError() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_EMPTY_WHITELISTS); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_EMPTY_WHITELISTS); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); LocalPermissioningConfiguration permissioningConfiguration = permissioningConfig(toml); @@ -137,7 +137,7 @@ public void permissioningConfigWithEmptyWhitelistMustNotError() throws Exception @Test public void permissioningConfigWithAbsentWhitelistMustThrowException() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> permissioningConfig(toml)); @@ -147,7 +147,7 @@ public void permissioningConfigWithAbsentWhitelistMustThrowException() throws Ex @Test public void permissioningConfigWithUnrecognizedKeyMustThrowException() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_UNRECOGNIZED_KEY); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_UNRECOGNIZED_KEY); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); final Throwable thrown = catchThrowable(() -> accountOnlyPermissioningConfig(toml)); @@ -170,7 +170,7 @@ public void permissioningConfigWithEmptyFileMustThrowException() throws Exceptio @Test public void permissioningConfigFromFileMustSetFilePath() throws Exception { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_VALID); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_VALID); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); LocalPermissioningConfiguration permissioningConfiguration = @@ -196,7 +196,7 @@ public void permissioningConfigFromNonexistentFileMustThrowException() { @Test public void permissioningConfigFromMultilineFileMustParseCorrectly() throws Exception { final URL configFile = - Resources.getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY_MULTILINE); + this.getClass().getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY_MULTILINE); final LocalPermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfiguration( true, configFile.getPath(), false, configFile.getPath()); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningControllerTest.java index cf5410c05d..66292d48a6 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningControllerTest.java @@ -39,7 +39,8 @@ private SmartContractPermissioningController setupController( final String resourceName, final String contractAddressString) throws IOException { final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.create(); - final String emptyContractFile = Resources.toString(Resources.getResource(resourceName), UTF_8); + final String emptyContractFile = + Resources.toString(this.getClass().getResource(resourceName), UTF_8); final GenesisState genesisState = GenesisState.fromConfig(GenesisConfigFile.fromConfig(emptyContractFile), protocolSchedule); @@ -59,7 +60,7 @@ private SmartContractPermissioningController setupController( public void testIpv4Included() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -75,7 +76,7 @@ public void testIpv4Included() throws IOException { public void testIpv4DestinationMissing() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -91,7 +92,7 @@ public void testIpv4DestinationMissing() throws IOException { public void testIpv4SourceMissing() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -107,7 +108,7 @@ public void testIpv4SourceMissing() throws IOException { public void testIpv6Included() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -123,7 +124,7 @@ public void testIpv6Included() throws IOException { public void testIpv6SourceMissing() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -139,7 +140,7 @@ public void testIpv6SourceMissing() throws IOException { public void testIpv6DestinationMissing() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThat( @@ -155,7 +156,7 @@ public void testIpv6DestinationMissing() throws IOException { public void testPermissioningContractMissing() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/noSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/noSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThatThrownBy( @@ -173,7 +174,7 @@ public void testPermissioningContractMissing() throws IOException { public void testPermissioningContractCorrupt() throws IOException { final SmartContractPermissioningController controller = setupController( - "SmartContractPermissioningControllerTest/corruptSmartPermissioning.json", + "/SmartContractPermissioningControllerTest/corruptSmartPermissioning.json", "0x0000000000000000000000000000000000001234"); assertThatThrownBy( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java index 1888fd1191..41f4a55fb2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java @@ -35,11 +35,11 @@ public class EthNetworkConfig { public static final int RINKEBY_NETWORK_ID = 4; public static final int GOERLI_NETWORK_ID = 5; public static final int DEV_NETWORK_ID = 2018; - private static final String MAINNET_GENESIS = "mainnet.json"; - private static final String ROPSTEN_GENESIS = "ropsten.json"; - private static final String RINKEBY_GENESIS = "rinkeby.json"; - private static final String GOERLI_GENESIS = "goerli.json"; - private static final String DEV_GENESIS = "dev.json"; + private static final String MAINNET_GENESIS = "/mainnet.json"; + private static final String ROPSTEN_GENESIS = "/ropsten.json"; + private static final String RINKEBY_GENESIS = "/rinkeby.json"; + private static final String GOERLI_GENESIS = "/goerli.json"; + private static final String DEV_GENESIS = "/dev.json"; private final String genesisConfig; private final int networkId; private final Collection bootNodes; @@ -118,7 +118,7 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) { private static String jsonConfig(final String resourceName) { try { - final URI uri = Resources.getResource(resourceName).toURI(); + final URI uri = EthNetworkConfig.class.getResource(resourceName).toURI(); return Resources.toString(uri.toURL(), UTF_8); } catch (final URISyntaxException | IOException e) { throw new IllegalStateException(e); 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 2c52baddb5..d5cb375ec0 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -85,7 +85,7 @@ public class PantheonCommandTest extends CommandTestAbstract { private final String ENCLAVE_PUBLIC_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; private final String VALID_NODE_ID = "6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; - static final String PERMISSIONING_CONFIG_TOML = "permissioning_config.toml"; + static final String PERMISSIONING_CONFIG_TOML = "/permissioning_config.toml"; private static final JsonRpcConfiguration defaultJsonRpcConfiguration; private static final WebSocketConfiguration defaultWebSocketConfiguration; @@ -249,7 +249,7 @@ public void callingWithConfigOptionButInvalidValueTomlFileShouldDisplayHelp() th public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException { assumeTrue(isFullInstantiation()); - final URL configFile = Resources.getResource("complete_config.toml"); + final URL configFile = this.getClass().getResource("/complete_config.toml"); final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); final String updatedConfig = Resources.toString(configFile, UTF_8) @@ -434,7 +434,7 @@ public void accountPermissioningEnabledWithNonexistentConfigFileMustError() { @Test public void nodePermissioningTomlFileWithNoPermissionsEnabledMustNotError() throws IOException { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_TOML); final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); parseCommand("--permissions-nodes-config-file", permToml.toString()); @@ -448,7 +448,7 @@ public void nodePermissioningTomlFileWithNoPermissionsEnabledMustNotError() thro public void accountPermissioningTomlFileWithNoPermissionsEnabledMustNotError() throws IOException { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_TOML); final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); parseCommand("--permissions-accounts-config-file", permToml.toString()); @@ -477,7 +477,7 @@ public void nodePermissioningTomlPathMustUseOption() throws IOException { URI.create( "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.169.0.9:4568")); - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_TOML); final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); final String whitelistedNodesString = @@ -508,7 +508,7 @@ public void nodePermissioningTomlPathMustUseOption() throws IOException { @Test public void accountPermissioningTomlPathMustUseOption() throws IOException { - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_TOML); final Path permToml = createTempFile("toml", Resources.toByteArray(configFile)); parseCommand( @@ -538,7 +538,7 @@ public void tomlThatConfiguresEverythingExceptPermissioningToml() throws IOExcep assumeTrue(isFullInstantiation()); // Load a TOML that configures literally everything (except permissioning TOML config) - final URL configFile = Resources.getResource("everything_config.toml"); + final URL configFile = this.getClass().getResource("/everything_config.toml"); final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); // Parse it. @@ -581,7 +581,7 @@ public void tomlThatConfiguresEverythingExceptPermissioningToml() throws IOExcep public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOException { assumeTrue(isFullInstantiation()); - final String configFile = Resources.getResource("partial_config.toml").getFile(); + final String configFile = this.getClass().getResource("/partial_config.toml").getFile(); parseCommand("--config-file", configFile); final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); @@ -2129,7 +2129,7 @@ public void fullCLIOptionsShownWhenNotInDockerContainer() { @Test public void mustUseEnclaveUriAndOptions() throws IOException { - final URL configFile = Resources.getResource("orion_publickey.pub"); + final URL configFile = this.getClass().getResource("/orion_publickey.pub"); parseCommand( "--privacy-enabled", diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/custom/RpcAuthFileValidatorTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/custom/RpcAuthFileValidatorTest.java index 5a5bef0b66..70cbb767c9 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/custom/RpcAuthFileValidatorTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/custom/RpcAuthFileValidatorTest.java @@ -15,7 +15,6 @@ import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.google.common.io.Resources; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -26,11 +25,11 @@ @RunWith(MockitoJUnitRunner.StrictStubs.class) public class RpcAuthFileValidatorTest { - private static final String CORRECT_TOML = "auth_correct.toml"; - private static final String DUPLICATE_USER_TOML = "auth_duplicate_user.toml"; - private static final String INVALID_TOML = "auth_invalid.toml"; - private static final String INVALID_VALUE_TOML = "auth_invalid_value.toml"; - private static final String NO_PASSWORD_TOML = "auth_no_password.toml"; + private static final String CORRECT_TOML = "/auth_correct.toml"; + private static final String DUPLICATE_USER_TOML = "/auth_duplicate_user.toml"; + private static final String INVALID_TOML = "/auth_invalid.toml"; + private static final String INVALID_VALUE_TOML = "/auth_invalid_value.toml"; + private static final String NO_PASSWORD_TOML = "/auth_no_password.toml"; @Mock CommandLine commandLine; @Test @@ -85,6 +84,6 @@ commandLine, getFilePath(DUPLICATE_USER_TOML), "HTTP")) } private String getFilePath(final String resourceName) { - return Resources.getResource(resourceName).getPath(); + return this.getClass().getResource(resourceName).getPath(); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java index 34ea3441c6..43e0958fb6 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java @@ -78,12 +78,12 @@ public void ibftImport() throws IOException { final Path dataDir = folder.newFolder().toPath(); final Path source = dataDir.resolve("ibft.blocks"); final String config = - Resources.toString(Resources.getResource("ibftlegacy_genesis.json"), UTF_8); + Resources.toString(this.getClass().getResource("/ibftlegacy_genesis.json"), UTF_8); try { Files.write( source, - Resources.toByteArray(Resources.getResource("ibft.blocks")), + Resources.toByteArray(this.getClass().getResource("/ibft.blocks")), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (final IOException ex) { diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java index ef4a5469dc..92168f126e 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java @@ -30,8 +30,8 @@ public class LocalPermissioningConfigurationValidatorTest { static final String PERMISSIONING_CONFIG_ROPSTEN_BOOTNODES = - "permissioning_config_ropsten_bootnodes.toml"; - static final String PERMISSIONING_CONFIG = "permissioning_config.toml"; + "/permissioning_config_ropsten_bootnodes.toml"; + static final String PERMISSIONING_CONFIG = "/permissioning_config.toml"; @Test public void ropstenWithNodesWhitelistOptionWhichDoesIncludeRopstenBootnodesMustNotError() @@ -39,7 +39,7 @@ public void ropstenWithNodesWhitelistOptionWhichDoesIncludeRopstenBootnodesMustN EthNetworkConfig ethNetworkConfig = EthNetworkConfig.getNetworkConfig(NetworkName.ROPSTEN); - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ROPSTEN_BOOTNODES); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_ROPSTEN_BOOTNODES); final Path toml = Files.createTempFile("toml", ""); Files.write(toml, Resources.toByteArray(configFile)); @@ -56,7 +56,7 @@ public void nodesWhitelistOptionWhichDoesNotIncludeBootnodesMustError() throws E EthNetworkConfig ethNetworkConfig = EthNetworkConfig.getNetworkConfig(NetworkName.ROPSTEN); - final URL configFile = Resources.getResource(PERMISSIONING_CONFIG); + final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG); final Path toml = Files.createTempFile("toml", ""); toml.toFile().deleteOnExit(); Files.write(toml, Resources.toByteArray(configFile)); diff --git a/testutil/src/main/java/tech/pegasys/pantheon/testutil/BlockTestUtil.java b/testutil/src/main/java/tech/pegasys/pantheon/testutil/BlockTestUtil.java index f4c2d6be09..673d846d19 100644 --- a/testutil/src/main/java/tech/pegasys/pantheon/testutil/BlockTestUtil.java +++ b/testutil/src/main/java/tech/pegasys/pantheon/testutil/BlockTestUtil.java @@ -34,7 +34,7 @@ public static void write1000Blocks(final Path target) { try { Files.write( target, - Resources.toByteArray(Resources.getResource("1000.blocks")), + Resources.toByteArray(BlockTestUtil.class.getResource("/1000.blocks")), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (final IOException ex) {