Search in sources :

Example 6 with Context

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

the class MultiTenancy method setSimpleContractValue.

@Step("`<clientName>` writes a new value <newValue> to <contractName> successfully by sending a transaction to `<node>`")
public void setSimpleContractValue(String clientName, int newValue, String contractName, QuorumNetworkProperty.Node node) {
    long chainId = rpcService.call(node, "eth_chainId", Collections.emptyList(), EthChainId.class).blockingFirst().getChainId();
    Contract contract = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    assertThat(requestAccessToken(clientName).flatMap(t -> rawContractService.updateRawSimplePublicContract(node, networkProperty.getWallets().get("Wallet1"), contract.getContractAddress(), newValue, chainId)).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 7 with Context

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

the class MultiTenancy method notAuthorizedToExtendContract.

@Step("`<sourceClientName>` <expectedErr> to extend <contractName> on `<sourceNode>` private from `<sourceParty>` using `<sourceEthAccount>` to `<targetClientName>`'s `<targetParty>` on `<targetNode>` with acceptance by `<targetEthAccount>`")
public void notAuthorizedToExtendContract(String sourceClientName, String expectedErr, String contractName, Node sourceNode, String sourceParty, String sourceEthAccount, String targetClientName, String targetParty, Node targetNode, String targetEthAccount) {
    Contract existingContract = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    PrivacyFlag privacyFlag = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName + "_privacyFlag", PrivacyFlag.class);
    Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
    accessToken.ifPresent(Context::storeAccessToken);
    extensionService.initiateContractExtension(sourceNode, sourceEthAccount, sourceParty, existingContract.getContractAddress(), targetNode, targetEthAccount, targetParty, privacyFlag).doOnNext(res -> {
        assertThat(res.getError()).as("expected error to return").isNotNull();
        assertThat(res.getError().getMessage()).contains(expectedErr);
    }).doOnTerminate(Context::removeAccessToken).blockingSubscribe();
}
Also used : Context(com.quorum.gauge.common.Context) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 8 with Context

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

the class MultiTenancy method getCodeWithAssertion.

private void getCodeWithAssertion(String clientName, String contractName, String targetContractName, Node source, Consumer<byte[]> assertFunc) {
    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);
    byte[] actual = contractCodeReaderService.getCode(source, reader.getContractAddress(), target.getContractAddress()).doOnTerminate(Context::removeAccessToken).blockingFirst();
    assertFunc.accept(actual);
}
Also used : Context(com.quorum.gauge.common.Context) Contract(org.web3j.tx.Contract)

Example 9 with Context

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

the class MultiTenancy method canReadContract.

@Step("`<clientNames>` can read <contractName> on `<node>`")
public void canReadContract(String clientNames, String contractName, Node node) {
    Contract existingContract = mustHaveValue(DataStoreFactory.getScenarioDataStore(), contractName, Contract.class);
    Observable.fromIterable(Arrays.stream(clientNames.split(",")).map(String::trim).collect(Collectors.toList())).forEach(clientName -> {
        obtainAccessToken(clientName);
        Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
        accessToken.ifPresent(Context::storeAccessToken);
        BigInteger actualValue = contractService.readSimpleContractValue(node, existingContract.getContractAddress()).doOnTerminate(Context::removeAccessToken).blockingFirst();
        assertThat(actualValue).as(clientName).isNotZero();
    });
}
Also used : Context(com.quorum.gauge.common.Context) BigInteger(java.math.BigInteger) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Example 10 with Context

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

the class MultiTenancy method setLastCodeSizeFails.

@Step("`<clientName>` fails to invoke 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 setLastCodeSizeFails(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);
    assertThatThrownBy(() -> contractCodeReaderService.setLastCodeSize(source, reader.getContractAddress(), target.getContractAddress(), ethAccountAlias, privateFromAlias, List.of(privateForAlias)).doOnTerminate(Context::removeAccessToken).blockingSubscribe()).hasMessageContaining("not authorized");
}
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