use of com.quorum.gauge.common.Context in project quorum-acceptance-tests by ConsenSys.
the class MultiTenancy method canNotReadContract.
@Step("`<clientNames>` can __NOT__ read <contractName> on `<node>`")
public void canNotReadContract(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);
assertThatThrownBy(() -> contractService.readSimpleContractValue(node, existingContract.getContractAddress()).doOnTerminate(Context::removeAccessToken).blockingSubscribe()).as(clientName).hasMessageContaining("Empty value (0x) returned from contract");
});
}
use of com.quorum.gauge.common.Context 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();
}
}
use of com.quorum.gauge.common.Context in project quorum-acceptance-tests by ConsenSys.
the class OAuth2Service method requestAccessToken.
public Observable<String> requestAccessToken(String clientId, List<String> targetAud, List<String> requestScopes) {
Context.removeAccessToken();
ClientCredentials cred = clientCredentials.get(clientId);
if (cred == null) {
throw new AccessControlException(clientId + " OAuth2 Client has not been setup");
}
RequestBody body = new FormBody.Builder().add("grant_type", "client_credentials").add("client_id", cred.clientId).add("client_secret", cred.clientSecret).add("scope", String.join(" ", requestScopes)).add("audience", String.join(" ", targetAud)).build();
Request req = new Request.Builder().url(oAuth2ServerProperty().getClientEndpoint() + "/oauth2/token").post(body).build();
return Observable.fromCallable(() -> httpClient.newCall(req).execute()).doOnError(e -> logger.error("Failed to retrieve access token", e)).map(r -> {
try {
assert r.body() != null;
if (!r.isSuccessful()) {
throw new RuntimeException("unsuccessful request: " + r.message() + ": " + r.body().string());
}
TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
};
Map<String, String> map = new ObjectMapper().readValue(r.body().byteStream(), typeRef);
return map.get("token_type") + " " + map.get("access_token");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
r.close();
}
}).onExceptionResumeNext(Observable.just("no_access_token_retrieved")).doOnNext(Context::storeAccessToken);
}
use of com.quorum.gauge.common.Context in project quorum-acceptance-tests by ConsenSys.
the class MultiTenancy method deploySimpleStorageContractWithFlag.
@Step("`<clientName>` deploys a <privacyFlag> `SimpleStorage` contract on `<node>` private from `<privateFrom>` using `<ethAccount>`, named <contractName>, private for <anotherClient>'s `<privateFor>`")
public void deploySimpleStorageContractWithFlag(String clientName, PrivacyFlag privacyFlag, Node node, String privateFrom, String ethAccount, String contractName, String anotherClient, String privateFor) {
List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
obtainAccessToken(clientName);
Optional<String> accessToken = haveValue(DataStoreFactory.getScenarioDataStore(), "access_token", String.class);
accessToken.ifPresent(Context::storeAccessToken);
Contract contract = contractService.createSimpleContract(42, node, ethAccount, privateFrom, privateForList, List.of(privacyFlag)).doOnTerminate(Context::removeAccessToken).blockingFirst();
DataStoreFactory.getScenarioDataStore().put(contractName, contract);
DataStoreFactory.getScenarioDataStore().put(contractName + "_privateFrom", privacyService.id(privateFrom));
DataStoreFactory.getScenarioDataStore().put(contractName + "_privacyFlag", privacyFlag);
}
use of com.quorum.gauge.common.Context in project quorum-acceptance-tests by ConsenSys.
the class MultiTenancy method deployPrivateContract.
private Observable<Optional<Contract>> deployPrivateContract(String clientName, QuorumNode node, String privateFrom, String privateFor, String contractId, WalletData wallet, String ethAccount) {
List<String> privateForList = Arrays.stream(privateFor.split(",")).map(String::trim).collect(Collectors.toList());
return requestAccessToken(clientName).flatMap(t -> {
String realContractId = contractId;
String delegateContractAddress = "";
if (realContractId.startsWith("SimpleStorageDelegate")) {
realContractId = "SimpleStorageDelegate";
String delegateContractName = contractId.replaceAll("^.+\\((.+)\\)$", "$1");
Contract delegateContractInstance = mustHaveValue(DataStoreFactory.getScenarioDataStore(), delegateContractName, Contract.class);
delegateContractAddress = delegateContractInstance.getContractAddress();
}
if (realContractId.startsWith("SneakyWrapper")) {
realContractId = "SneakyWrapper";
String delegateContractName = contractId.replaceAll("^.+\\((.+)\\)$", "$1");
Contract delegateContractInstance = mustHaveValue(DataStoreFactory.getScenarioDataStore(), delegateContractName, Contract.class);
delegateContractAddress = delegateContractInstance.getContractAddress();
}
Node source = networkProperty.getNode(node.name());
switch(realContractId) {
case "SimpleStorage":
if (wallet == null) {
return contractService.createSimpleContract(42, source, ethAccount, privateFrom, privateForList, null);
} else {
return rawContractService.createRawSimplePrivateContract(42, wallet, node, privateFrom, privateForList);
}
case "ClientReceipt":
if (wallet == null) {
return contractService.createClientReceiptPrivateSmartContract(source, ethAccount, privateFrom, privateForList);
} else {
return rawContractService.createRawClientReceiptPrivateContract(wallet, node, privateFrom, privateForList);
}
case "SimpleStorageDelegate":
if (wallet == null) {
return contractService.createSimpleDelegatePrivateContract(delegateContractAddress, source, ethAccount, privateFrom, privateForList);
} else {
return rawContractService.createRawSimpleDelegatePrivateContract(delegateContractAddress, wallet, node, privateFrom, privateForList);
}
case "SneakyWrapper":
if (wallet != null) {
return rawContractService.createRawSneakyWrapperPrivateContract(delegateContractAddress, wallet, node, privateFrom, privateForList);
}
case "ContractCodeReader":
if (wallet == null) {
return contractCodeReaderService.createPrivateContract(source, ethAccount, privateFrom, privateForList);
}
default:
return Observable.error(new UnsupportedOperationException(contractId + " is not supported"));
}
}).map(Optional::of).doOnError(e -> logger.debug("Deploying private contract: {}", e.getMessage(), e)).onErrorResumeNext(o -> {
return Observable.just(Optional.empty());
}).doOnTerminate(Context::removeAccessToken);
}
Aggregations