Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PRIV] Fix private transaction acceptance test #1134

Merged
merged 4 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.node;

import static java.util.Collections.unmodifiableList;
import static net.consensys.cava.io.file.Files.copyResource;
import static org.apache.logging.log4j.LogManager.getLogger;

import tech.pegasys.pantheon.controller.KeyPairUtil;
Expand Down Expand Up @@ -104,6 +105,7 @@ public PantheonNode(
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<String> keyfilePath,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand All @@ -112,10 +114,19 @@ public PantheonNode(
throws IOException {
this.bootnodeEligible = bootnodeEligible;
this.homeDirectory = Files.createTempDirectory("acctest");
keyfilePath.ifPresent(
path -> {
try {
copyResource(path, homeDirectory.resolve("key"));
} catch (IOException e) {
LOG.error("Could not find key file \"{}\" in resources", path);
}
});
this.keyPair = KeyPairUtil.loadKeyPair(homeDirectory);
this.name = name;
this.miningParameters = miningParameters;
this.privacyParameters = privacyParameters;
this.privacyParameters.setSigningKeyPair(keyPair);
this.jsonRpcConfiguration = jsonRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.metricsConfiguration = metricsConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void startNode(final PantheonNode node) {
params.add("--privacy-url");
params.add(node.getPrivacyParameters().getUrl());
params.add("--privacy-public-key-file");
params.add(node.getPrivacyParameters().getPublicKeyFile().getAbsolutePath());
params.add(node.getPrivacyParameters().getEnclavePublicKeyFile().getAbsolutePath());
params.add("--privacy-precompiled-address");
params.add(String.valueOf(node.getPrivacyParameters().getPrivacyAddress()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.pantheon.cli.PantheonControllerBuilder;
import tech.pegasys.pantheon.controller.KeyPairUtil;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void startNode(final PantheonNode node) {
.devMode(node.isDevMode())
.nodePrivateKeyFile(KeyPairUtil.getDefaultKeyFile(node.homeDirectory()))
.metricsSystem(noOpMetricsSystem)
.maxPendingTransactions(PendingTransactions.MAX_PENDING_TRANSACTIONS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PantheonControllerBuilder has been updated to set PendingTransactions.MAX_PENDING_TRANSACTIONS as default when the parameter hasn't been set. We can remove this line.

.build();
} catch (final IOException e) {
throw new RuntimeException("Error building PantheonController", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PantheonFactoryConfiguration {
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final Optional<String> keyFilePath;
private final boolean devMode;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean p2pEnabled;
Expand All @@ -45,6 +46,7 @@ class PantheonFactoryConfiguration {
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<String> keyFilePath,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand All @@ -57,6 +59,7 @@ class PantheonFactoryConfiguration {
this.webSocketConfiguration = webSocketConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.keyFilePath = keyFilePath;
this.devMode = devMode;
this.genesisConfigProvider = genesisConfigProvider;
this.p2pEnabled = p2pEnabled;
Expand Down Expand Up @@ -92,6 +95,10 @@ public Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

public Optional<String> getKeyFilePath() {
return keyFilePath;
}

public boolean isDevMode() {
return devMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class PantheonFactoryConfigurationBuilder {
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private Optional<String> keyFilePath = Optional.empty();
private boolean devMode = true;
private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty();
private Boolean p2pEnabled = true;
Expand Down Expand Up @@ -142,6 +143,11 @@ public PantheonFactoryConfigurationBuilder setPermissioningConfiguration(
return this;
}

public PantheonFactoryConfigurationBuilder setKeyFilePath(final String keyFilePath) {
this.keyFilePath = Optional.of(keyFilePath);
return this;
}

public PantheonFactoryConfigurationBuilder setDevMode(final boolean devMode) {
this.devMode = devMode;
return this;
Expand Down Expand Up @@ -172,6 +178,7 @@ public PantheonFactoryConfiguration build() {
webSocketConfiguration,
metricsConfiguration,
permissioningConfiguration,
keyFilePath,
devMode,
genesisConfigProvider,
p2pEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private PantheonNode create(final PantheonFactoryConfiguration config) throws IO
config.getWebSocketConfiguration(),
config.getMetricsConfiguration(),
config.getPermissioningConfiguration(),
config.getKeyFilePath(),
config.isDevMode(),
config.getGenesisConfigProvider(),
config.isP2pEnabled(),
Expand All @@ -79,12 +80,14 @@ public PantheonNode createMinerNode(final String name) throws IOException {
}

public PantheonNode createPrivateTransactionEnabledMinerNode(
final String name, final PrivacyParameters privacyParameters) throws IOException {
final String name, final PrivacyParameters privacyParameters, final String keyFilePath)
throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
.miningEnabled()
.jsonRpcEnabled()
.setKeyFilePath(keyFilePath)
.enablePrivateTransactions(privacyParameters)
.webSocketEnabled()
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public class ExpectValidPrivateContractDeployedReceipt
extends ExpectValidPrivateTransactionReceipt {
public class ExpectValidPrivateContractDeployedReceipt extends GetValidPrivateTransactionReceipt {

private final String contractAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.web3j.utils.Numeric;

public class ExpectValidPrivateContractEventsEmitted extends ExpectValidPrivateTransactionReceipt {
public class ExpectValidPrivateContractEventsEmitted extends GetValidPrivateTransactionReceipt {
private final String eventValue;

public ExpectValidPrivateContractEventsEmitted(
Expand All @@ -33,12 +33,12 @@ public ExpectValidPrivateContractEventsEmitted(
}

public void verify(
final PantheonNode node, final String transactionHash, final String PUBLIC_KEY) {
final PantheonNode node, final String transactionHash, final String publicKey) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, PUBLIC_KEY);
getPrivateTransactionReceipt(node, transactionHash, publicKey);

String event = privateTxReceipt.getLogs().get(0).getData().substring(66, 130);
assertEquals(
Numeric.decodeQuantity(Numeric.prependHexPrefix(event)), new BigInteger(eventValue));
new BigInteger(eventValue), Numeric.decodeQuantity(Numeric.prependHexPrefix(event)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.web3j.utils.Numeric;

public class ExpectValidPrivateContractValuesReturned extends ExpectValidPrivateTransactionReceipt {
public class ExpectValidPrivateContractValuesReturned extends GetValidPrivateTransactionReceipt {
private final String returnValue;

public ExpectValidPrivateContractValuesReturned(
Expand All @@ -34,11 +34,11 @@ public ExpectValidPrivateContractValuesReturned(
}

public void verify(
final PantheonNode node, final String transactionHash, final String PUBLIC_KEY) {
final PantheonNode node, final String transactionHash, final String publicKey) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, PUBLIC_KEY);
getPrivateTransactionReceipt(node, transactionHash, publicKey);

BytesValue output = BytesValue.fromHexString(privateTxReceipt.getOutput());
assertEquals(Numeric.decodeQuantity(output.toString()), new BigInteger(returnValue));
assertEquals(new BigInteger(returnValue), Numeric.decodeQuantity(output.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,25 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;

import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public abstract class ExpectValidPrivateTransactionReceipt {
public class ExpectValidPrivateTransactionReceipt extends GetValidPrivateTransactionReceipt {

private Eea eea;
private Transactions transactions;

ExpectValidPrivateTransactionReceipt(final Eea eea, final Transactions transactions) {
this.eea = eea;
this.transactions = transactions;
public ExpectValidPrivateTransactionReceipt(final Eea eea, final Transactions transactions) {
super(eea, transactions);
}

ResponseTypes.PrivateTransactionReceipt getPrivateTransactionReceipt(
public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {

waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash, publicKey)));
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
node.execute(transactions.getPrivateTransactionReceipt(transactionHash, publicKey));
return privateTxReceipt;
getPrivateTransactionReceipt(node, transactionHash, publicKey);
assertNotNull(privateTxReceipt);
assertThat(privateTxReceipt.getFrom()).isNotBlank();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;

import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public abstract class GetValidPrivateTransactionReceipt {

private Eea eea;
private Transactions transactions;

GetValidPrivateTransactionReceipt(final Eea eea, final Transactions transactions) {
this.eea = eea;
this.transactions = transactions;
}

ResponseTypes.PrivateTransactionReceipt getPrivateTransactionReceipt(
final PantheonNode node, final String transactionHash, final String publicKey) {

waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash, publicKey)));
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
node.execute(transactions.getPrivateTransactionReceipt(transactionHash, publicKey));
return privateTxReceipt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@
import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public class PrivateContractVerifier {
public class PrivateTransactionVerifier {

private final Transactions transactions;
private final Eea eea;

public PrivateContractVerifier(final Eea eea, final Transactions transactions) {
public PrivateTransactionVerifier(final Eea eea, final Transactions transactions) {
this.eea = eea;
this.transactions = transactions;
}

public ExpectValidPrivateContractDeployedReceipt validPrivateTransactionReceipt(
public ExpectValidPrivateTransactionReceipt validPrivateTransactionReceipt() {
return new ExpectValidPrivateTransactionReceipt(eea, transactions);
}

public ExpectValidPrivateContractDeployedReceipt validPrivateContractDeployed(
final String contractAddress) {
return new ExpectValidPrivateContractDeployedReceipt(contractAddress, eea, transactions);
}

public ExpectValidPrivateContractEventsEmitted validPrivateTransactionReceiptReturnsEvents(
final String eventValue) {
public ExpectValidPrivateContractEventsEmitted validEventReturned(final String eventValue) {
return new ExpectValidPrivateContractEventsEmitted(eventValue, eea, transactions);
}

public ExpectValidPrivateContractValuesReturned validPrivateTransactionReceiptReturnsValues(
final String returnValue) {
public ExpectValidPrivateContractValuesReturned validOutputReturned(final String returnValue) {
return new ExpectValidPrivateContractValuesReturned(returnValue, eea, transactions);
}
}
Loading