use of org.web3j.protocol.exceptions.TransactionException in project web3j by web3j.
the class ContractTest method testTransactionFailedWithRevertReason.
@Test
public void testTransactionFailedWithRevertReason() throws Exception {
TransactionReceipt transactionReceipt = createFailedTransactionReceipt();
prepareCall(OWNER_REVERT_MSG_HASH);
TransactionException thrown = assertThrows(TransactionException.class, () -> {
prepareTransaction(transactionReceipt);
contract.performTransaction(new Address(BigInteger.TEN), new Uint256(BigInteger.ONE)).send();
});
assertEquals(String.format("Transaction %s has failed with status: %s. Gas used: 1. Revert reason: '%s'.", TRANSACTION_HASH, TXN_FAIL_STATUS, OWNER_REVERT_MSG_STR), thrown.getMessage());
assertEquals(transactionReceipt, thrown.getTransactionReceipt().get());
}
use of org.web3j.protocol.exceptions.TransactionException in project web3j by web3j.
the class JsonRpc2_0Besu method privOnChainAddToPrivacyGroup.
@Override
public Request<?, EthSendTransaction> privOnChainAddToPrivacyGroup(Base64String privacyGroupId, Credentials credentials, Base64String enclaveKey, List<Base64String> participants) throws IOException, TransactionException {
BigInteger transactionCount = privGetTransactionCount(credentials.getAddress(), privacyGroupId).send().getTransactionCount();
String lockContractCall = OnChainPrivacyTransactionBuilder.getEncodedSingleParamFunction("lock");
String lockPrivacyGroupTransactionPayload = onChainPrivacyTransactionBuilder.buildOnChainPrivateTransaction(privacyGroupId, credentials, enclaveKey, transactionCount, lockContractCall);
String lockTransactionHash = eeaSendRawTransaction(lockPrivacyGroupTransactionPayload).send().getTransactionHash();
PollingPrivateTransactionReceiptProcessor processor = new PollingPrivateTransactionReceiptProcessor(this, 1000, 15);
PrivateTransactionReceipt receipt = processor.waitForTransactionReceipt(lockTransactionHash);
if (receipt.isStatusOK()) {
return privOnChainCreatePrivacyGroup(privacyGroupId, credentials, enclaveKey, participants);
} else {
throw new TransactionException("Lock transaction failed - the group may already be locked", receipt);
}
}
use of org.web3j.protocol.exceptions.TransactionException in project besu by hyperledger.
the class PrivGetTransactionReceiptTransaction method execute.
@Override
public PrivateTransactionReceipt execute(final NodeRequests node) {
final Besu besu = node.privacy().getBesuClient();
final PollingPrivateTransactionReceiptProcessor receiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, 1000, 15);
try {
final PrivateTransactionReceipt result = receiptProcessor.waitForTransactionReceipt(transactionHash);
assertThat(result).isNotNull();
return result;
} catch (final IOException | TransactionException e) {
throw new RuntimeException(e);
}
}
use of org.web3j.protocol.exceptions.TransactionException in project quorum-acceptance-tests by ConsenSys.
the class RevertReason method setValueOnContractFailsWithReason.
@Step("Set value <value> from <node> and private for <nodes> fails with reason <reasonText>")
public void setValueOnContractFailsWithReason(int value, String node, String nodes, String reasonText) {
String contractAddress = DataStoreFactory.getScenarioDataStore().get("contractAddress").toString();
try {
increasingSimpleStorageContractService.setValue(contractAddress, value, node, parseNodes(nodes)).map(r -> r.getBlockNumber()).blockingFirst();
fail("Expected to fail");
} catch (RuntimeException err) {
TransactionException exception = (TransactionException) err.getCause().getCause();
String revertReason = exception.getTransactionReceipt().get().getRevertReason().substring(REVERT_REASON_METHOD_ID.length());
Utf8String decodedRevertReason = (Utf8String) FunctionReturnDecoder.decode(revertReason, REVERT_REASON_TYPES).get(0);
assertThat(decodedRevertReason.getValue()).isEqualTo(reasonText);
}
}
use of org.web3j.protocol.exceptions.TransactionException in project quorum-acceptance-tests by ConsenSys.
the class MultiTenancy method invokeGetFromDelegate.
@Step("`<clientName>` invokes getFromDelgate with nonce shift <nonceShift> in <contractName> by sending a transaction to `<node>` with its TM key `<privateFrom>`, signed by `<wallet>` and private for `<privateForList>` name this transaction <transactionName>")
public void invokeGetFromDelegate(String clientName, int nonceShift, String contractName, QuorumNode node, String privateFrom, String wallet, String privateFor, String transactionName) {
Contract c = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
String contractId = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName + "_id", String.class);
List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
AtomicReference<Throwable> caughtException = new AtomicReference<>();
assertThat(requestAccessToken(clientName).flatMap(t -> {
return rawContractService.invokeGetFromDelegateInSneakyWrapper(nonceShift, c.getContractAddress(), networkProperty.getWallets().get(wallet), node, privateFrom, privateForList);
}).map(Optional::of).doOnError(e -> {
logger.debug("On exception: {}", e.getMessage());
caughtException.set(e);
}).onErrorResumeNext(o -> {
return Observable.just(Optional.empty());
}).doOnTerminate(Context::removeAccessToken).map(r -> true).blockingFirst()).isTrue();
assertThat(caughtException.get()).hasMessageContaining("Transaction receipt was not generated after");
TransactionException txe = (TransactionException) caughtException.get();
assertThat(txe.getTransactionHash()).isNotEmpty();
DataStoreFactory.getScenarioDataStore().put(transactionName, txe.getTransactionHash().get());
}
Aggregations