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

Revert Reason #1603

Merged
merged 24 commits into from
Jul 4, 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 @@ -48,6 +48,17 @@ public Condition expectNoTransactionReceipt(final String transactionHash) {
public Condition sendRawTransactionExceptional(
final String transactionData, final String expectedMessage) {
return new ExpectEthSendRawTransactionException(
transactions.sendRawTransactionTransaction(transactionData), expectedMessage);
transactions.sendRawTransaction(transactionData), expectedMessage);
}

public Condition expectSuccessfulTransactionReceiptWithReason(
CjHare marked this conversation as resolved.
Show resolved Hide resolved
final String transactionHash, final String revertReason) {
return new ExpectSuccessfulEthGetTransactionReceiptWithReason(
transactions.getTransactionReceiptWithRevertReason(transactionHash), revertReason);
}

public Condition expectSuccessfulTransactionReceiptWithoutReason(final String transactionHash) {
return new ExpectSuccessfulEthGetTransactionReceiptWithoutReason(
transactions.getTransactionReceiptWithRevertReason(transactionHash));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.condition.eth;

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthGetTransactionReceiptWithRevertReason;

public class ExpectSuccessfulEthGetTransactionReceiptWithReason implements Condition {

private final EthGetTransactionReceiptWithRevertReason transaction;
private final String expectedRevertReason;

public ExpectSuccessfulEthGetTransactionReceiptWithReason(
final EthGetTransactionReceiptWithRevertReason transaction,
final String expectedRevertReason) {
this.transaction = transaction;
this.expectedRevertReason = expectedRevertReason;
}

@Override
public void verify(final Node node) {
WaitUtils.waitFor(() -> assertThat(revertReasonMatches(node, expectedRevertReason)).isTrue());
}

private boolean revertReasonMatches(final Node node, final String expectedRevertReason) {
return node.execute(transaction)
.filter(
transactionReceipt ->
transactionReceipt.getRevertReason().contains(expectedRevertReason))
.isPresent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.condition.eth;

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthGetTransactionReceiptWithRevertReason;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.CustomRequestFactory.TransactionReceiptWithRevertReason;

public class ExpectSuccessfulEthGetTransactionReceiptWithoutReason implements Condition {

private final EthGetTransactionReceiptWithRevertReason transaction;

public ExpectSuccessfulEthGetTransactionReceiptWithoutReason(
final EthGetTransactionReceiptWithRevertReason transaction) {
this.transaction = transaction;
}

@Override
public void verify(final Node node) {
WaitUtils.waitFor(() -> assertThat(revertReasonIsEmpty(node)).isTrue());
}

private boolean revertReasonIsEmpty(final Node node) {
return node.execute(transaction)
.map(TransactionReceiptWithRevertReason::getRevertReason)
.filter(String::isEmpty)
.isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft2.Ibft2RequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.login.LoginRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.CustomNetJsonRpcRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.CustomRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.PermissioningJsonRpcRequestFactory;

import java.io.File;
Expand Down Expand Up @@ -80,6 +80,7 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea
private final Properties portsProperties = new Properties();
private final Boolean p2pEnabled;
private final NetworkingConfiguration networkingConfiguration;
private final boolean revertReasonEnabled;

private final String name;
private final MiningParameters miningParameters;
Expand Down Expand Up @@ -117,10 +118,12 @@ public PantheonNode(
final NetworkingConfiguration networkingConfiguration,
final boolean discoveryEnabled,
final boolean bootnodeEligible,
final boolean revertReasonEnabled,
final List<String> plugins,
final List<String> extraCLIOptions)
throws IOException {
this.bootnodeEligible = bootnodeEligible;
this.revertReasonEnabled = revertReasonEnabled;
this.homeDirectory = Files.createTempDirectory("acctest");
keyfilePath.ifPresent(
path -> {
Expand Down Expand Up @@ -287,7 +290,7 @@ private NodeRequests nodeRequests() {
new PermissioningJsonRpcRequestFactory(web3jService),
new AdminRequestFactory(web3jService),
new EeaRequestFactory(web3jService),
new CustomNetJsonRpcRequestFactory(web3jService),
new CustomRequestFactory(web3jService),
websocketService,
loginRequestFactory());
}
Expand Down Expand Up @@ -521,6 +524,11 @@ public List<String> getExtraCLIOptions() {
return extraCLIOptions;
}

@Override
public boolean isRevertReasonEnabled() {
return revertReasonEnabled;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public void startNode(final PantheonNode node) {
params.addAll(networkConfigParams);
}

if (node.isRevertReasonEnabled()) {
params.add("--revert-reason-enabled");
}

node.getPermissioningConfiguration()
.flatMap(PermissioningConfiguration::getLocalConfig)
.ifPresent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void startNode(final PantheonNode node) {
.rocksDbConfiguration(RocksDbConfiguration.builder().databaseDir(tempDir).build())
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.clock(Clock.systemUTC())
.isRevertReasonEnabled(node.isRevertReasonEnabled())
.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 @@ -47,4 +47,6 @@ public interface NodeConfiguration {
boolean isBootnodeEligible();

List<String> getExtraCLIOptions();

boolean isRevertReasonEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PantheonFactoryConfiguration {
private final NetworkingConfiguration networkingConfiguration;
private final boolean discoveryEnabled;
private final boolean bootnodeEligible;
private final boolean revertReasonEnabled;
private final List<String> plugins;
private final List<String> extraCLIOptions;

Expand All @@ -58,6 +59,7 @@ public PantheonFactoryConfiguration(
final NetworkingConfiguration networkingConfiguration,
final boolean discoveryEnabled,
final boolean bootnodeEligible,
final boolean revertReasonEnabled,
final List<String> plugins,
final List<String> extraCLIOptions) {
this.name = name;
Expand All @@ -74,6 +76,7 @@ public PantheonFactoryConfiguration(
this.networkingConfiguration = networkingConfiguration;
this.discoveryEnabled = discoveryEnabled;
this.bootnodeEligible = bootnodeEligible;
this.revertReasonEnabled = revertReasonEnabled;
this.plugins = plugins;
this.extraCLIOptions = extraCLIOptions;
}
Expand Down Expand Up @@ -141,4 +144,8 @@ public List<String> getPlugins() {
public List<String> getExtraCLIOptions() {
return extraCLIOptions;
}

public boolean isRevertReasonEnabled() {
return revertReasonEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class PantheonFactoryConfigurationBuilder {
private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create();
private boolean discoveryEnabled = true;
private boolean bootnodeEligible = true;
private boolean revertReasonEnabled = false;
private List<String> plugins = new ArrayList<>();
private List<String> extraCLIOptions = new ArrayList<>();

Expand Down Expand Up @@ -187,6 +188,11 @@ public PantheonFactoryConfigurationBuilder extraCLIOptions(final List<String> ex
return this;
}

public PantheonFactoryConfigurationBuilder revertReasonEnabled() {
this.revertReasonEnabled = true;
return this;
}

public PantheonFactoryConfiguration build() {
return new PantheonFactoryConfiguration(
name,
Expand All @@ -203,6 +209,7 @@ public PantheonFactoryConfiguration build() {
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
revertReasonEnabled,
plugins,
extraCLIOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public PantheonNode create(final PantheonFactoryConfiguration config) throws IOE
config.getNetworkingConfiguration(),
config.isDiscoveryEnabled(),
config.isBootnodeEligible(),
config.isRevertReasonEnabled(),
config.getPlugins(),
config.getExtraCLIOptions());
}
Expand All @@ -61,6 +62,17 @@ public PantheonNode createMinerNode(final String name) throws IOException {
.build());
}

public PantheonNode createMinerNodeWithRevertReasonEnabled(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcEnabled()
.webSocketEnabled()
.revertReasonEnabled()
.build());
}

public PantheonNode createArchiveNode(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur
final NetworkingConfiguration networkingConfiguration,
final boolean discoveryEnabled,
final boolean bootnodeEligible,
final boolean revertReasonEnabled,
final List<String> plugins,
final List<String> extraCLIOptions,
final OrionTestHarness orion) {
Expand All @@ -63,6 +64,7 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
revertReasonEnabled,
plugins,
extraCLIOptions);
this.orion = orion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public PrivacyPantheonFactoryConfiguration build() {
config.getNetworkingConfiguration(),
config.isDiscoveryEnabled(),
config.isBootnodeEligible(),
config.isRevertReasonEnabled(),
config.getPlugins(),
config.getExtraCLIOptions(),
orion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private static PrivacyNode create(final PrivacyPantheonFactoryConfiguration conf
config.getNetworkingConfiguration(),
config.isDiscoveryEnabled(),
config.isBootnodeEligible(),
config.isRevertReasonEnabled(),
config.getPlugins(),
config.getExtraCLIOptions(),
config.getOrion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public PrivacyNode(
final NetworkingConfiguration networkingConfiguration,
final boolean discoveryEnabled,
final boolean bootnodeEligible,
final boolean revertReasonEnabled,
final List<String> plugins,
final List<String> extraCLIOptions,
final OrionTestHarness orion)
Expand All @@ -78,6 +79,7 @@ public PrivacyNode(
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
revertReasonEnabled,
plugins,
extraCLIOptions);
this.orion = orion;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.transaction;

import tech.pegasys.pantheon.tests.acceptance.dsl.account.Accounts;

import java.io.IOException;
import java.math.BigInteger;
import java.util.Collections;

import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.datatypes.Function;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.tx.RawTransactionManager;

public class CallSmartContractFunction implements Transaction<EthSendTransaction> {

private static final BigInteger GAS_PRICE = BigInteger.valueOf(1000);
private static final BigInteger GAS_LIMIT = BigInteger.valueOf(3000000);
private static final Credentials BENEFACTOR_ONE =
Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY);

private final String functionName;
private final String contractAddress;

public CallSmartContractFunction(final String functionName, final String contractAddress) {
this.functionName = functionName;
this.contractAddress = contractAddress;
}

@Override
public EthSendTransaction execute(final NodeRequests node) {
final Function function =
new Function(functionName, Collections.emptyList(), Collections.emptyList());
final RawTransactionManager transactionManager =
new RawTransactionManager(node.eth(), BENEFACTOR_ONE);
try {
return transactionManager.sendTransaction(
GAS_PRICE, GAS_LIMIT, contractAddress, FunctionEncoder.encode(function), BigInteger.ZERO);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
Loading