Search in sources :

Example 1 with Context

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

the class MultiTenancy method invokeGetMethodOnSimpleContract.

@Step("`<clientName>` invokes get in <contractName> on `<node>` and gets value <expectedValue>")
public void invokeGetMethodOnSimpleContract(String clientName, String contractName, Node node, int expectedValue) {
    Contract c = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    BigInteger actualValue = requestAccessToken(clientName).flatMap(t -> contractService.readSimpleContractValue(node, c.getContractAddress())).doOnTerminate(Context::removeAccessToken).onErrorReturn(err -> {
        if (StringUtils.equals("Empty value (0x) returned from contract", err.getMessage())) {
            return BigInteger.ZERO;
        }
        throw new RuntimeException(err);
    }).blockingFirst();
    assertThat(actualValue).isEqualTo(expectedValue);
}
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) BigInteger(java.math.BigInteger) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 2 with Context

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

the class MultiTenancy method deployNodeManagedPublicContract.

@Step("`<clientName>` deploys a <contractId> public contract, named <contractName>, by sending a transaction to `<node>` using `<ethAccount>`")
public void deployNodeManagedPublicContract(String clientName, String contractId, String contractName, Node node, String ethAccount) {
    Contract contract = requestAccessToken(clientName).flatMap(t -> contractService.createPublicSimpleContract(42, node, ethAccount)).doOnTerminate(Context::removeAccessToken).doOnNext(c -> {
        if (c == null || !c.getTransactionReceipt().isPresent()) {
            throw new RuntimeException("contract not deployed");
        }
    }).blockingFirst();
    logger.debug("Saving contract address {} with name {}", contract.getContractAddress(), contractName);
    DataStoreFactory.getScenarioDataStore().put(contractName, contract);
}
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 Context

use of com.quorum.gauge.common.Context 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 4 with Context

use of com.quorum.gauge.common.Context 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 5 with Context

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

the class MultiTenancy method setLastCodeSize.

@Step("`<clientName>` invokes ContractCodeReader(<reader>)'s setLastCodeSize(<target>) by sending a transaction to `<Node1>` with its TM key `<GS_K1>` using `<GS_ACC1>` and private for `<JPM_K1>`")
public void setLastCodeSize(String clientName, String contractName, String targetContractName, Node source, String privateFromAlias, String ethAccountAlias, String privateForAlias) {
    Contract reader = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    Contract target = mustHaveValue(DataStoreFactory.getScenarioDataStore(), targetContractName, Contract.class);
    obtainAccessToken(clientName);
    Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
    accessToken.ifPresent(Context::storeAccessToken);
    contractCodeReaderService.setLastCodeSize(source, reader.getContractAddress(), target.getContractAddress(), ethAccountAlias, privateFromAlias, List.of(privateForAlias)).doOnTerminate(Context::removeAccessToken).blockingSubscribe();
}
Also used : Context(com.quorum.gauge.common.Context) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Aggregations

Context (com.quorum.gauge.common.Context)28 Contract (org.web3j.tx.Contract)26 Step (com.thoughtworks.gauge.Step)23 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)18 DataStore (com.thoughtworks.gauge.datastore.DataStore)17 BigInteger (java.math.BigInteger)17 Collectors (java.util.stream.Collectors)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Service (org.springframework.stereotype.Service)17 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)16 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)16 ExtensionService (com.quorum.gauge.services.ExtensionService)16 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)16 Stream (java.util.stream.Stream)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 Observable (io.reactivex.Observable)15 StringUtils (org.apache.commons.lang.StringUtils)15 Ints (com.google.common.primitives.Ints)14