Search in sources :

Example 1 with RetryWithDelay

use of com.quorum.gauge.common.RetryWithDelay in project quorum-acceptance-tests by ConsenSys.

the class PublicSmartContract method verifyLogEvents.

@Step("<node> has received <expectedTxCount> transactions which contain <expectedEventCount> log events in total")
public void verifyLogEvents(QuorumNode node, int expectedTxCount, int expectedEventCount) {
    List<TransactionReceipt> originalReceipts = (List<TransactionReceipt>) DataStoreFactory.getScenarioDataStore().get("receipts");
    List<Observable<TransactionReceipt>> receiptsInNode = new ArrayList<>();
    Scheduler scheduler = threadLocalDelegateScheduler(expectedTxCount);
    for (TransactionReceipt r : originalReceipts) {
        receiptsInNode.add(transactionService.getTransactionReceipt(node, r.getTransactionHash()).map(tr -> {
            if (tr.getTransactionReceipt().isPresent()) {
                return tr.getTransactionReceipt().get();
            } else {
                throw new RuntimeException("retry");
            }
        }).retryWhen(new RetryWithDelay(20, 3000)).subscribeOn(scheduler));
    }
    AtomicInteger actualTxCount = new AtomicInteger();
    AtomicInteger actualEventCount = new AtomicInteger();
    Observable.zip(receiptsInNode, args -> {
        for (Object o : args) {
            TransactionReceipt r = (TransactionReceipt) o;
            assertThat(r.isStatusOK()).isTrue();
            assertThat(r.getBlockNumber()).isNotEqualTo(BigInteger.ZERO);
            actualTxCount.getAndIncrement();
            actualEventCount.addAndGet(r.getLogs().size());
        }
        // but we dont care about the real result so return a dummy instead
        return new Object();
    }).blockingFirst();
    assertThat(actualTxCount.get()).as("Transaction Count").isEqualTo(expectedTxCount);
    assertThat(actualEventCount.get()).as("Log Event Count").isEqualTo(expectedEventCount);
}
Also used : Contract(org.web3j.tx.Contract) AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) QuorumNode(com.quorum.gauge.common.QuorumNode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) List(java.util.List) Scheduler(io.reactivex.Scheduler) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scheduler(io.reactivex.Scheduler) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) Observable(io.reactivex.Observable) Step(com.thoughtworks.gauge.Step)

Example 2 with RetryWithDelay

use of com.quorum.gauge.common.RetryWithDelay in project quorum-acceptance-tests by ConsenSys.

the class PrivateRawSmartContract method verifyTransactionReceipt.

@Step("Transaction Receipt is present in <node> for <contractName> from external wallet <wallet>")
public void verifyTransactionReceipt(QuorumNode node, String contractName, WalletData wallet) {
    String transactionHash = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName + "_transactionHash", String.class);
    Optional<TransactionReceipt> receipt = transactionService.getTransactionReceipt(node, transactionHash).map(ethGetTransactionReceipt -> {
        if (ethGetTransactionReceipt.getTransactionReceipt().isPresent()) {
            return ethGetTransactionReceipt;
        } else {
            throw new RuntimeException("retry");
        }
    }).retryWhen(new RetryWithDelay(20, 3000)).blockingFirst().getTransactionReceipt();
    assertThat(receipt.isPresent()).isTrue();
    assertThat(receipt.get().getBlockNumber()).isNotEqualTo(currentBlockNumber());
    final Credentials[] credentials = new Credentials[1];
    assertThatCode(() -> credentials[0] = WalletUtils.loadCredentials(wallet.getWalletPass(), wallet.getWalletPath())).doesNotThrowAnyException();
    assertThat(receipt.get().getFrom()).isEqualTo(credentials[0].getAddress());
}
Also used : Contract(org.web3j.tx.Contract) AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) AssertionsForClassTypes.assertThatCode(org.assertj.core.api.AssertionsForClassTypes.assertThatCode) QuorumNode(com.quorum.gauge.common.QuorumNode) AssertionsForClassTypes(org.assertj.core.api.AssertionsForClassTypes) LoggerFactory(org.slf4j.LoggerFactory) Credentials(org.web3j.crypto.Credentials) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.springframework.stereotype.Service) WalletUtils(org.web3j.crypto.WalletUtils) WalletData(com.quorum.gauge.common.config.WalletData) Optional(java.util.Optional) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) Credentials(org.web3j.crypto.Credentials) Step(com.thoughtworks.gauge.Step)

Example 3 with RetryWithDelay

use of com.quorum.gauge.common.RetryWithDelay in project quorum-acceptance-tests by ConsenSys.

the class RawContractService method updateRawSimplePrivateContractUsingEthApi.

public Observable<EthGetTransactionReceipt> updateRawSimplePrivateContractUsingEthApi(String apiMethod, int newValue, String contractAddress, QuorumNode source, QuorumNode target) {
    Quorum client = connectionFactory().getConnection(source);
    Enclave enclave = buildEnclave(source, client);
    String payload = base64SimpleStorageSetBytecode(newValue);
    SendResponse storeRawResponse = enclave.storeRawRequest(payload, privacyService.id(source), Collections.emptyList());
    String tmHash = base64ToHex(storeRawResponse.getKey());
    EthSendTransaction sendTransactionResponse = transactionService.sendSignedPrivateTransaction(apiMethod, tmHash, source, target, contractAddress).blockingFirst();
    Optional<String> responseError = Optional.ofNullable(sendTransactionResponse.getError()).map(Response.Error::getMessage);
    responseError.ifPresent(e -> logger.error("EthSendTransaction error: {}", e));
    logger.debug("sent tx: {}", sendTransactionResponse.getTransactionHash());
    return transactionService.getTransactionReceipt(source, sendTransactionResponse.getTransactionHash()).map(ethGetTransactionReceipt -> {
        if (ethGetTransactionReceipt.getTransactionReceipt().isPresent()) {
            return ethGetTransactionReceipt;
        } else {
            throw new RuntimeException("retry");
        }
    }).retryWhen(new RetryWithDelay(20, 3000));
}
Also used : UnixDomainSocketFactory(org.web3j.quorum.UnixDomainSocketFactory) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Constellation(org.web3j.quorum.enclave.Constellation) Credentials(org.web3j.crypto.Credentials) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) RlpList(org.web3j.rlp.RlpList) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) URI(java.net.URI) RawDeployedContractTarget(com.quorum.gauge.common.RawDeployedContractTarget) Quorum(org.web3j.quorum.Quorum) Contract(org.web3j.tx.Contract) SneakyWrapper(com.quorum.gauge.sol.SneakyWrapper) QuorumNode(com.quorum.gauge.common.QuorumNode) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) ContractCallException(org.web3j.tx.exceptions.ContractCallException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientReceipt(com.quorum.gauge.sol.ClientReceipt) TransactionEncoder(org.web3j.crypto.TransactionEncoder) Collectors(java.util.stream.Collectors) EthGetTransactionReceipt(org.web3j.protocol.core.methods.response.EthGetTransactionReceipt) SendResponse(org.web3j.quorum.enclave.SendResponse) CipherException(org.web3j.crypto.CipherException) Web3j(org.web3j.protocol.Web3j) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) TransactionManager(org.web3j.tx.TransactionManager) RlpEncoder(org.web3j.rlp.RlpEncoder) java.util(java.util) FunctionEncoder(org.web3j.abi.FunctionEncoder) Response(org.web3j.protocol.core.Response) Request(org.web3j.protocol.core.Request) FillTransactionResponse(com.quorum.gauge.ext.filltx.FillTransactionResponse) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) Charset(java.nio.charset.Charset) Service(org.springframework.stereotype.Service) EnclaveService(org.web3j.quorum.enclave.protocol.EnclaveService) WalletUtils(org.web3j.crypto.WalletUtils) Observable(io.reactivex.Observable) RlpDecoder(org.web3j.rlp.RlpDecoder) StreamUtils(org.springframework.util.StreamUtils) RlpString(org.web3j.rlp.RlpString) Logger(org.slf4j.Logger) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) PrivateFillTransaction(com.quorum.gauge.ext.filltx.PrivateFillTransaction) IOException(java.io.IOException) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) SimpleStorage(com.quorum.gauge.sol.SimpleStorage) RawTransaction(org.web3j.crypto.RawTransaction) File(java.io.File) SimpleStorageDelegate(com.quorum.gauge.sol.SimpleStorageDelegate) Tessera(org.web3j.quorum.enclave.Tessera) OkHttpClient(okhttp3.OkHttpClient) Enclave(org.web3j.quorum.enclave.Enclave) RawTransactionManager(org.web3j.tx.RawTransactionManager) Numeric(org.web3j.utils.Numeric) WalletData(com.quorum.gauge.common.config.WalletData) Function(org.web3j.abi.datatypes.Function) InputStream(java.io.InputStream) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) Quorum(org.web3j.quorum.Quorum) Enclave(org.web3j.quorum.enclave.Enclave) SendResponse(org.web3j.quorum.enclave.SendResponse) RlpString(org.web3j.rlp.RlpString) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay)

Example 4 with RetryWithDelay

use of com.quorum.gauge.common.RetryWithDelay in project quorum-acceptance-tests by ConsenSys.

the class AccumulatorSmartContract method getTransactionReceipt.

private TransactionReceipt getTransactionReceipt(QuorumNetworkProperty.Node node, String txReference) {
    String transactionHash = mustHaveValue(DataStoreFactory.getScenarioDataStore(), txReference, String.class);
    Optional<TransactionReceipt> receipt = transactionService.getTransactionReceipt(node, transactionHash).map(ethGetTransactionReceipt -> {
        if (ethGetTransactionReceipt.getTransactionReceipt().isPresent()) {
            return ethGetTransactionReceipt;
        } else {
            throw new RuntimeException("retry");
        }
    }).retryWhen(new RetryWithDelay(20, 3000)).blockingFirst().getTransactionReceipt();
    assertThat(receipt.isPresent()).isTrue();
    return receipt.get();
}
Also used : Contract(org.web3j.tx.Contract) AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Arrays(java.util.Arrays) AbstractService(com.quorum.gauge.services.AbstractService) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) Accumulator(com.quorum.gauge.sol.Accumulator) EventValues(org.web3j.abi.EventValues) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Log(org.web3j.protocol.core.methods.response.Log) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) BigInteger(java.math.BigInteger) AssertionsForClassTypes.assertThatThrownBy(org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy) LinkedList(java.util.LinkedList) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay)

Example 5 with RetryWithDelay

use of com.quorum.gauge.common.RetryWithDelay in project quorum-acceptance-tests by ConsenSys.

the class TransactionService method waitForTransactionReceipt.

public TransactionReceipt waitForTransactionReceipt(QuorumNode node, String transactionHash) {
    Optional<TransactionReceipt> receipt = getTransactionReceipt(node, transactionHash).map(ethGetTransactionReceipt -> {
        if (ethGetTransactionReceipt.getTransactionReceipt().isPresent()) {
            return ethGetTransactionReceipt;
        } else {
            throw new RuntimeException("retry");
        }
    }).retryWhen(new RetryWithDelay(20, 3000)).blockingFirst().getTransactionReceipt();
    assertThat(receipt.isPresent()).isTrue();
    return receipt.get();
}
Also used : Transaction(org.web3j.protocol.core.methods.request.Transaction) java.util(java.util) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FunctionEncoder(org.web3j.abi.FunctionEncoder) PrivatePayload(org.web3j.quorum.methods.response.PrivatePayload) Request(org.web3j.protocol.core.Request) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Type(org.web3j.abi.datatypes.Type) Quorum(org.web3j.quorum.Quorum) Contract(org.web3j.tx.Contract) Logger(org.slf4j.Logger) QuorumNode(com.quorum.gauge.common.QuorumNode) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) DefaultBlockParameter(org.web3j.protocol.core.DefaultBlockParameter) IOException(java.io.IOException) com.quorum.gauge.ext(com.quorum.gauge.ext) TimeUnit(java.util.concurrent.TimeUnit) Web3j(org.web3j.protocol.Web3j) EthFilter(org.web3j.protocol.core.methods.request.EthFilter) Function(org.web3j.abi.datatypes.Function) org.web3j.protocol.core.methods.response(org.web3j.protocol.core.methods.response) FUNC_SET(com.quorum.gauge.sol.SimpleStorage.FUNC_SET) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay)

Aggregations

RetryWithDelay (com.quorum.gauge.common.RetryWithDelay)10 Contract (org.web3j.tx.Contract)10 Step (com.thoughtworks.gauge.Step)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Service (org.springframework.stereotype.Service)8 QuorumNode (com.quorum.gauge.common.QuorumNode)7 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)7 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)6 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)6 BigInteger (java.math.BigInteger)6 Observable (io.reactivex.Observable)5 Schedulers (io.reactivex.schedulers.Schedulers)5 AssertionsForClassTypes.assertThat (org.assertj.core.api.AssertionsForClassTypes.assertThat)5 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)4 WalletData (com.quorum.gauge.common.config.WalletData)4 IOException (java.io.IOException)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)3