This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include revert reason if available in eth_getTransactionReceipt (#1603)
- Loading branch information
Showing
68 changed files
with
910 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ests/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceiptWithReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...s/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceiptWithoutReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ava/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/CallSmartContractFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.