Search in sources :

Example 1 with QuorumNode

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

the class MultiTenancy method setRawSimpleContractValue.

@Step("`<clientName>` writes a new arbitrary value to <contractName> successfully by sending a transaction to `<node>` with its TM key `<privateFrom>`, signed by `<wallet>` and private for `<privateFor>`")
public void setRawSimpleContractValue(String clientName, String contractName, QuorumNode node, String privateFrom, String wallet, String privateFor) {
    Contract c = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
    assertThat(requestAccessToken(clientName).flatMap(t -> rawContractService.updateRawSimplePrivateContract(100, c.getContractAddress(), networkProperty.getWallets().get(wallet), node, privateFrom, privateForList)).map(Optional::of).onErrorResumeNext(o -> {
        return Observable.just(Optional.empty());
    }).doOnTerminate(Context::removeAccessToken).map(r -> r.isPresent() && r.get().isStatusOK()).blockingFirst()).isTrue();
}
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) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 2 with QuorumNode

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

the class MultiTenancy method invokeSetDelegate.

@Step("`<clientName>` invokes setDelegate to <value> in <contractName> by sending a transaction to `<node>` with its TM key `<privateFrom>`, signed by `<wallet>` and private for `<privateFor>`")
public void invokeSetDelegate(String clientName, boolean value, String contractName, QuorumNode node, String privateFrom, String wallet, String privateFor) {
    Contract c = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
    assertThat(requestAccessToken(clientName).flatMap(t -> rawContractService.updateDelegateInSneakyWrapperContract(value, c.getContractAddress(), networkProperty.getWallets().get(wallet), node, privateFrom, privateForList)).map(Optional::of).onErrorResumeNext(o -> {
        return Observable.just(Optional.empty());
    }).doOnTerminate(Context::removeAccessToken).map(r -> r.isPresent() && r.get().isStatusOK()).blockingFirst()).isTrue();
}
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) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 3 with QuorumNode

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

the class NestedPrivateContract method callNewContractC2.

@Step("Execute <privacyFlags> <contractName>'s `newContractC2()` function with new value <newValue> in <source> and it's private for <target>")
public void callNewContractC2(String privacyFlags, String contractName, int newValue, QuorumNode source, String target) {
    Contract c1 = mustHaveValue(contractName, Contract.class);
    TransactionReceipt receipt = nestedContractService.newContractC2(source, Arrays.stream(target.split(",")).map(s -> QuorumNode.valueOf(s)).collect(Collectors.toList()), c1.getContractAddress(), BigInteger.valueOf(newValue), Arrays.stream(privacyFlags.split(",")).map(PrivacyFlag::valueOf).collect(Collectors.toList())).blockingFirst();
    Gauge.writeMessage("Transaction Hash %s", receipt.getTransactionHash());
    DataStoreFactory.getScenarioDataStore().put("transactionHash", receipt.getTransactionHash());
}
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) Gauge(com.thoughtworks.gauge.Gauge) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) QuorumNode(com.quorum.gauge.common.QuorumNode) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.springframework.stereotype.Service) BigInteger(java.math.BigInteger) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 4 with QuorumNode

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

the class MultiTenancy method depositClientReceipt.

@Step("`<clientName>` executes <contractName>'s `deposit()` function <times> times with arbitrary id and value between original parties")
public void depositClientReceipt(String clientName, String contractName, int times) {
    Contract c = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    Object[] data = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientName + "ClientReceipt" + contractName, Object[].class);
    QuorumNode node = (QuorumNode) data[0];
    String privateFrom = (String) data[1];
    String privateFor = (String) data[2];
    List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
    requestAccessToken(clientName).blockingSubscribe();
    try {
        List<String> txHashes = new ArrayList<>();
        for (int i = 0; i < times; i++) {
            assertThat(rawContractService.updateRawClientReceiptPrivateContract(c.getContractAddress(), networkProperty.getWallets().get("Wallet1"), node, privateFrom, privateForList).map(Optional::of).onErrorResumeNext(o -> {
                return Observable.just(Optional.empty());
            }).doOnNext(r -> {
                if (r.isPresent()) {
                    txHashes.add(r.get().getTransactionHash());
                }
            }).map(r -> r.isPresent() && r.get().isStatusOK()).blockingFirst()).isTrue();
        }
        DataStoreFactory.getScenarioDataStore().put("hashes", txHashes.toArray(new String[0]));
    } finally {
        Context.removeAccessToken();
    }
}
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) QuorumNode(com.quorum.gauge.common.QuorumNode) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 5 with QuorumNode

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

the class PrivateStateValidation method updateNewValue.

@Step("Execute contract `C2`(<contractName>)'s `set()` function with new value <newValue> in <source> and it's private for <privateFor>")
public void updateNewValue(String contractName, int newValue, QuorumNode source, String privateFor) {
    Contract c = mustHaveValue(DataStoreFactory.getSpecDataStore(), contractName, Contract.class);
    TransactionReceipt receipt = nestedContractService.updateC2Contract(source, Arrays.stream(privateFor.split(",")).map(s -> QuorumNode.valueOf(s)).collect(Collectors.toList()), c.getContractAddress(), newValue, Arrays.asList(PrivacyFlag.StandardPrivate)).blockingFirst();
    assertThat(receipt.getTransactionHash()).isNotBlank();
    assertThat(receipt.getBlockNumber()).isNotEqualTo(currentBlockNumber());
    TransactionReceipt receiptPrivateFor = transactionService.waitForTransactionReceipt(QuorumNode.valueOf(privateFor), receipt.getTransactionHash());
    assertThat(receiptPrivateFor.getBlockNumber()).isNotEqualTo(currentBlockNumber());
}
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) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) QuorumNode(com.quorum.gauge.common.QuorumNode) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) Collectors(java.util.stream.Collectors) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) Observable(io.reactivex.Observable) AssertionsForClassTypes.assertThatThrownBy(org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Aggregations

QuorumNode (com.quorum.gauge.common.QuorumNode)52 Contract (org.web3j.tx.Contract)47 Service (org.springframework.stereotype.Service)46 Logger (org.slf4j.Logger)42 LoggerFactory (org.slf4j.LoggerFactory)42 Observable (io.reactivex.Observable)39 Collectors (java.util.stream.Collectors)39 BigInteger (java.math.BigInteger)36 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)33 Step (com.thoughtworks.gauge.Step)30 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)29 Autowired (org.springframework.beans.factory.annotation.Autowired)28 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)27 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)26 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)26 RetryWithDelay (com.quorum.gauge.common.RetryWithDelay)25 java.util (java.util)25 WalletData (com.quorum.gauge.common.config.WalletData)23 Response (org.web3j.protocol.core.Response)21 Schedulers (io.reactivex.schedulers.Schedulers)20