Search in sources :

Example 1 with TransactionException

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());
}
Also used : TransactionException(org.web3j.protocol.exceptions.TransactionException) Address(org.web3j.abi.datatypes.Address) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) EthGetTransactionReceipt(org.web3j.protocol.core.methods.response.EthGetTransactionReceipt) Uint256(org.web3j.abi.datatypes.generated.Uint256) Test(org.junit.jupiter.api.Test)

Example 2 with TransactionException

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);
    }
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionException(org.web3j.protocol.exceptions.TransactionException) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) BigInteger(java.math.BigInteger) Base64String(org.web3j.utils.Base64String)

Example 3 with TransactionException

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);
    }
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionException(org.web3j.protocol.exceptions.TransactionException) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) Besu(org.web3j.protocol.besu.Besu) IOException(java.io.IOException)

Example 4 with TransactionException

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);
    }
}
Also used : Contract(org.web3j.tx.Contract) AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Arrays(java.util.Arrays) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) TransactionException(org.web3j.protocol.exceptions.TransactionException) TypeReference(org.web3j.abi.TypeReference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IncreasingSimpleStorageContractService(com.quorum.gauge.services.IncreasingSimpleStorageContractService) LoggerFactory(org.slf4j.LoggerFactory) Utf8String(org.web3j.abi.datatypes.Utf8String) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) List(java.util.List) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Assertions.fail(org.assertj.core.api.Assertions.fail) Service(org.springframework.stereotype.Service) AbiTypes(org.web3j.abi.datatypes.AbiTypes) BigInteger(java.math.BigInteger) Strings(org.assertj.core.util.Strings) FunctionReturnDecoder(org.web3j.abi.FunctionReturnDecoder) Collections(java.util.Collections) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) Type(org.web3j.abi.datatypes.Type) Utf8String(org.web3j.abi.datatypes.Utf8String) TransactionException(org.web3j.protocol.exceptions.TransactionException) Utf8String(org.web3j.abi.datatypes.Utf8String) Step(com.thoughtworks.gauge.Step)

Example 5 with TransactionException

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());
}
Also used : AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) EthChainId(com.quorum.gauge.ext.EthChainId) TransactionException(org.web3j.protocol.exceptions.TransactionException) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Response(org.web3j.protocol.core.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) Credentials(org.web3j.crypto.Credentials) ExtensionService(com.quorum.gauge.services.ExtensionService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DataStore(com.thoughtworks.gauge.datastore.DataStore) Context(com.quorum.gauge.common.Context) Service(org.springframework.stereotype.Service) WalletUtils(org.web3j.crypto.WalletUtils) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) Node(com.quorum.gauge.common.QuorumNetworkProperty.Node) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) QuorumNode(com.quorum.gauge.common.QuorumNode) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) Ints(com.google.common.primitives.Ints) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) WalletData(com.quorum.gauge.common.config.WalletData) org.web3j.protocol.core.methods.response(org.web3j.protocol.core.methods.response) Table(com.thoughtworks.gauge.Table) Context(com.quorum.gauge.common.Context) TransactionException(org.web3j.protocol.exceptions.TransactionException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Aggregations

TransactionException (org.web3j.protocol.exceptions.TransactionException)5 BigInteger (java.math.BigInteger)3 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)2 Step (com.thoughtworks.gauge.Step)2 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 Contract (org.web3j.tx.Contract)2 Ints (com.google.common.primitives.Ints)1 Context (com.quorum.gauge.common.Context)1 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)1 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)1 Node (com.quorum.gauge.common.QuorumNetworkProperty.Node)1 QuorumNode (com.quorum.gauge.common.QuorumNode)1 WalletData (com.quorum.gauge.common.config.WalletData)1 EthChainId (com.quorum.gauge.ext.EthChainId)1