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");
}
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");
}
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();
}
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);
}
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);
}
Aggregations