Search in sources :

Example 1 with DataStore

use of com.thoughtworks.gauge.datastore.DataStore in project quorum-acceptance-tests by ConsenSys.

the class ContractExtension method acceptExtension.

@Step("<newNode> accepts the offer to extend the contract <contractName>")
public void acceptExtension(final QuorumNetworkProperty.Node newNode, final String contractName) {
    final DataStore store = DataStoreFactory.getScenarioDataStore();
    final PrivacyFlag privacyFlag = mustHaveValue(store, "privacyFlag", PrivacyFlag.class);
    final String contractAddress = mustHaveValue(store, contractName + "extensionAddress", String.class);
    final Set<QuorumNetworkProperty.Node> allNodes = mustHaveValue(store, "extensionAllNodes", Set.class);
    final QuorumVoteOnContract result = this.extensionService.acceptExtension(newNode, true, contractAddress, allNodes, privacyFlag).blockingFirst();
    if (result.getError() != null) {
        logger.error(result.getError().toString());
    }
    assertThat(result.getError()).isNull();
    final Optional<TransactionReceipt> transactionReceipt = transactionService.pollTransactionReceipt(newNode, result.getResult());
    assertThat(transactionReceipt.isPresent()).isTrue();
    assertThat(transactionReceipt.get().getStatus()).isEqualTo("0x1");
}
Also used : DataStore(com.thoughtworks.gauge.datastore.DataStore) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Step(com.thoughtworks.gauge.Step)

Example 2 with DataStore

use of com.thoughtworks.gauge.datastore.DataStore in project quorum-acceptance-tests by ConsenSys.

the class ContractExtension method updatePartiesForContract.

@Step("<node> requests parties are updated for contract <contractName>")
public void updatePartiesForContract(final QuorumNetworkProperty.Node node, final String contractName) {
    final DataStore store = DataStoreFactory.getScenarioDataStore();
    final PrivacyFlag privacyFlag = mustHaveValue(store, "privacyFlag", PrivacyFlag.class);
    final String contractAddress = mustHaveValue(store, contractName + "extensionAddress", String.class);
    final Set<QuorumNetworkProperty.Node> allNodes = mustHaveValue(store, "extensionAllNodes", Set.class);
    final QuorumUpdateParties result = this.extensionService.updateParties(node, contractAddress, allNodes, privacyFlag).blockingFirst();
    assertThat(result.getError()).isNull();
    final Optional<TransactionReceipt> transactionReceipt = transactionService.pollTransactionReceipt(node, result.getResult());
    assertThat(transactionReceipt.isPresent()).isTrue();
    assertThat(transactionReceipt.get().getStatus()).isEqualTo("0x1");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : DataStore(com.thoughtworks.gauge.datastore.DataStore) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Step(com.thoughtworks.gauge.Step)

Example 3 with DataStore

use of com.thoughtworks.gauge.datastore.DataStore in project quorum-acceptance-tests by ConsenSys.

the class ContractExtension method rejectExtension.

@Step("<node> rejects contract extension of <contractName>")
public void rejectExtension(final QuorumNetworkProperty.Node node, final String contractName) {
    final DataStore store = DataStoreFactory.getScenarioDataStore();
    final PrivacyFlag privacyFlag = mustHaveValue(store, "privacyFlag", PrivacyFlag.class);
    final String contractAddress = mustHaveValue(store, contractName + "extensionAddress", String.class);
    final Set<QuorumNetworkProperty.Node> allNodes = mustHaveValue(store, "extensionAllNodes", Set.class);
    final QuorumVoteOnContract voteResult = this.extensionService.acceptExtension(node, false, contractAddress, allNodes, privacyFlag).blockingFirst();
    assertThat(voteResult.getError()).isNull();
    final Optional<TransactionReceipt> transactionReceipt = transactionService.pollTransactionReceipt(node, voteResult.getResult());
    assertThat(transactionReceipt.isPresent()).isTrue();
    assertThat(transactionReceipt.get().getStatus()).isEqualTo("0x1");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : DataStore(com.thoughtworks.gauge.datastore.DataStore) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Step(com.thoughtworks.gauge.Step)

Example 4 with DataStore

use of com.thoughtworks.gauge.datastore.DataStore in project quorum-acceptance-tests by ConsenSys.

the class ContractExtension method extensionCompleted.

@Step("Wait for <contractName> to disappear from active extension in <node>")
public void extensionCompleted(final String contractName, final QuorumNetworkProperty.Node node) {
    final Contract contract = mustHaveValue(contractName, Contract.class);
    Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
    accessToken.ifPresent(Context::storeAccessToken);
    try {
        int count = 0;
        while (true) {
            count++;
            final QuorumActiveExtensionContracts result = this.extensionService.getExtensionContracts(node).blockingFirst();
            final Optional<Map<Object, Object>> first = result.getResult().stream().filter(contractStatus -> contractStatus.containsValue(contract.getContractAddress())).findFirst();
            if ((!first.isPresent()) || (count > 25)) {
                break;
            } else {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        final DataStore store = DataStoreFactory.getScenarioDataStore();
        final String contractAddress = mustHaveValue(store, contractName + "extensionAddress", String.class);
        String status = extensionService.getExtensionStatus(node, contractAddress);
        int i = 0;
        if (!status.equals("DONE")) {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
                status = extensionService.getExtensionStatus(node, contractAddress);
                if ((i > 25) || status.equals("DONE")) {
                    break;
                }
            }
        }
        assertThat(status).describedAs("Extension must be successfully completed").isEqualTo("DONE");
    } finally {
        Context.removeAccessToken();
    }
}
Also used : Context(com.quorum.gauge.common.Context) Contract(org.web3j.tx.Contract) AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExtensionService(com.quorum.gauge.services.ExtensionService) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Stream(java.util.stream.Stream) DataStore(com.thoughtworks.gauge.datastore.DataStore) Context(com.quorum.gauge.common.Context) Service(org.springframework.stereotype.Service) com.quorum.gauge.ext.contractextension(com.quorum.gauge.ext.contractextension) Map(java.util.Map) Optional(java.util.Optional) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) DataStore(com.thoughtworks.gauge.datastore.DataStore) Contract(org.web3j.tx.Contract) Map(java.util.Map) Step(com.thoughtworks.gauge.Step)

Example 5 with DataStore

use of com.thoughtworks.gauge.datastore.DataStore in project quorum-acceptance-tests by ConsenSys.

the class EstimateGas method updateContractUsingEstimatedGas.

@Step("Update contract <contractName> with value <value>, from <from> to <privateFor> using estimated gas")
public void updateContractUsingEstimatedGas(final String contractName, final int value, final QuorumNode from, final QuorumNode privateFor) {
    final DataStore specStore = DataStoreFactory.getSpecDataStore();
    final DataStore scenarioStore = DataStoreFactory.getScenarioDataStore();
    final Contract contract = mustHaveValue(specStore, contractName, Contract.class);
    final String contractAddress = contract.getContractAddress();
    final EthEstimateGas estimatedGasResult = mustHaveValue(scenarioStore, "estimatedValue", EthEstimateGas.class);
    final BigInteger estimatedGasLimit = estimatedGasResult.getAmountUsed();
    final TransactionReceipt receipt = contractService.updateSimpleContractWithGasLimit(from, Arrays.asList(privateFor), contractAddress, estimatedGasLimit, value, Arrays.asList(PrivacyFlag.StandardPrivate)).blockingFirst();
    assertThat(receipt.isStatusOK()).isTrue();
}
Also used : DataStore(com.thoughtworks.gauge.datastore.DataStore) EthEstimateGas(org.web3j.protocol.core.methods.response.EthEstimateGas) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) BigInteger(java.math.BigInteger) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step)

Aggregations

DataStore (com.thoughtworks.gauge.datastore.DataStore)9 Step (com.thoughtworks.gauge.Step)8 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)7 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)5 Context (com.quorum.gauge.common.Context)3 Contract (org.web3j.tx.Contract)3 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)2 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)2 ExtensionService (com.quorum.gauge.services.ExtensionService)2 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)2 BigInteger (java.math.BigInteger)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 Ints (com.google.common.primitives.Ints)1 Node (com.quorum.gauge.common.QuorumNetworkProperty.Node)1