Search in sources :

Example 21 with Context

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

the class MultiTenancy method failToSetSimpleContractValueUsingNodeDefaultAccount.

@Step("`<clientName>` fails to write a new arbitrary value to <contractName> by sending a transaction to `<node>` with its TM key `<privateFrom>` using `<ethAccount>` and private for `<privateForList>`")
public void failToSetSimpleContractValueUsingNodeDefaultAccount(String clientName, String contractName, QuorumNode node, String privateFrom, String ethAccount, String privateFor) {
    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 -> {
        Node source = networkProperty.getNode(node.name());
        if (contractId.startsWith("SimpleStorageDelegate")) {
            return contractService.updateSimpleStorageDelegateContract(100, c.getContractAddress(), source, ethAccount, privateFrom, privateForList);
        } else {
            return contractService.updateSimpleStorageContract(100, c.getContractAddress(), source, ethAccount, 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 -> r.isPresent() && r.get().isStatusOK()).blockingFirst()).isFalse();
    assertThat(caughtException.get()).hasMessageContaining("not authorized");
}
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) Node(com.quorum.gauge.common.QuorumNetworkProperty.Node) QuorumNode(com.quorum.gauge.common.QuorumNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 22 with Context

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

the class MultiTenancy method failToSetSimpleContractValue.

@Step("`<clientName>` fails to write a new arbitrary value to <contractName> by sending a transaction to `<node>` with its TM key `<privateFrom>`, signed by `<wallet>` and private for `<privateForList>`")
public void failToSetSimpleContractValue(String clientName, String contractName, QuorumNode node, String privateFrom, String wallet, String privateFor) {
    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 -> {
        if (contractId.startsWith("SimpleStorageDelegate")) {
            return rawContractService.updateRawSimpleDelegatePrivateContract(100, c.getContractAddress(), networkProperty.getWallets().get(wallet), node, privateFrom, privateForList);
        } else {
            return rawContractService.updateRawSimplePrivateContract(100, 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 -> r.isPresent() && r.get().isStatusOK()).blockingFirst()).isFalse();
    assertThat(caughtException.get()).hasMessageContaining("not authorized");
}
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) AtomicReference(java.util.concurrent.atomic.AtomicReference) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 23 with Context

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

the class MultiTenancy method setNodeManagedPublicSimpleContractValue.

@Step("`<clientName>` writes a new value <newValue> to <contractName> successfully by sending a transaction to `<node>` using `<ethAccount>`")
public void setNodeManagedPublicSimpleContractValue(String clientName, int newValue, String contractName, Node node, String ethAccount) {
    Contract contract = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    assertThat(requestAccessToken(clientName).flatMap(t -> contractService.updatePublicSimpleStorageContract(newValue, contract.getContractAddress(), node, ethAccount)).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 24 with Context

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

the class MultiTenancy method deployPublicContract.

@Step("`<clientName>` deploys a <contractId> public contract, named <contractName>, by sending a transaction to `<node>`")
public void deployPublicContract(String clientName, String contractId, String contractName, QuorumNetworkProperty.Node node) {
    Contract contract = requestAccessToken(clientName).flatMap(accessToken -> rpcService.call(node, "eth_chainId", Collections.emptyList(), EthChainId.class)).flatMap(ethChainId -> rawContractService.createRawSimplePublicContract(42, networkProperty.getWallets().get("Wallet1"), node, ethChainId.getChainId())).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) EthChainId(com.quorum.gauge.ext.EthChainId) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 25 with Context

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

the class MultiTenancy method getLastCodeSizeWithAssertion.

private void getLastCodeSizeWithAssertion(String clientName, String contractName, Node source, Consumer<BigInteger> assertFunc) {
    Contract reader = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    obtainAccessToken(clientName);
    Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
    accessToken.ifPresent(Context::storeAccessToken);
    BigInteger actual = contractCodeReaderService.getLastCodeSize(source, reader.getContractAddress()).doOnTerminate(Context::removeAccessToken).blockingFirst();
    assertFunc.accept(actual);
}
Also used : Context(com.quorum.gauge.common.Context) BigInteger(java.math.BigInteger) Contract(org.web3j.tx.Contract)

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