use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class PluginSecurity method invokeMultipleWithExpectation.
@Step("`<clientId>` sends a batch `<apis>` to `<node>` and expect: <table>")
public void invokeMultipleWithExpectation(String clientId, String apis, QuorumNetworkProperty.Node node, Table table) {
String token = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientId, String.class);
Context.storeAccessToken(token);
BatchRequest.Collector collector = BatchRequest.Collector.create();
Arrays.stream(apis.split(",")).map(String::trim).forEach(n -> collector.add(n, Collections.emptyList()));
Map<String, String> expect = table.getTableRows().stream().collect(Collectors.toMap(r -> StringUtils.removeEnd(StringUtils.removeStart(r.getCell("callApi"), "`"), "`"), r -> r.getCell("expectation")));
rpcService.call(node, collector).blockingForEach(batchResponse -> {
assertThat(batchResponse.getResponses()).as("Number of returned responses").hasSize(collector.size());
for (ObjectResponse res : batchResponse.getResponses()) {
assertThat(res.getId()).as("Response must have id").isNotZero();
Request r = collector.getByID(res.getId());
String policy = Optional.ofNullable(expect.get(r.getMethod())).orElseThrow(() -> new IllegalStateException("no such method in expectation table: " + r.getMethod()));
boolean expectAuthorized = "success".equalsIgnoreCase(policy);
String description = policy + ": " + r.getMethod() + "@" + node.getName();
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
}
});
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class PermissionService method NodeInfo.
public String NodeInfo(QuorumNetworkProperty.Node node) {
Request<?, NodeInfo> nodeInfoRequest = new Request<>("admin_nodeInfo", null, connectionFactory().getWeb3jService(node), NodeInfo.class);
NodeInfo nodeInfo = nodeInfoRequest.flowable().toObservable().blockingFirst();
return nodeInfo.getEnode();
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class RawContractService method signTransaction.
public Observable<FillTransactionResponse> signTransaction(QuorumNode from, PrivateFillTransaction tx) {
Web3j client = connectionFactory().getConnection(from);
Request<?, FillTransactionResponse> request = new Request<>("eth_signTransaction", Collections.singletonList(tx), connectionFactory().getWeb3jService(from), FillTransactionResponse.class);
return request.flowable().toObservable();
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ContractService method readSimpleContractValue.
/**
* Need to use EthCall to manipulate the error as webj3 doesn't
*
* @param node
* @param contractAddress
* @return
*/
public Observable<BigInteger> readSimpleContractValue(Node node, String contractAddress) {
Quorum client = connectionFactory().getConnection(node);
Function function = new Function(FUNC_GET, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
}));
return client.ethCoinbase().flowable().toObservable().map(Response::getResult).flatMap(address -> {
Request<?, EthCall> req = client.ethCall(Transaction.createEthCallTransaction(address, contractAddress, FunctionEncoder.encode(function)), DefaultBlockParameterName.LATEST);
return req.flowable().toObservable();
}).map(ec -> {
if (ec.hasError()) {
throw new ContractCallException(ec.getError().getMessage());
}
List<Type> values = FunctionReturnDecoder.decode(ec.getValue(), function.getOutputParameters());
Type result;
if (!values.isEmpty()) {
result = values.get(0);
} else {
throw new ContractCallException("Empty value (0x) returned from contract");
}
Object value = result.getValue();
if (BigInteger.class.isAssignableFrom(value.getClass())) {
return (BigInteger) value;
} else {
throw new ContractCallException("Unable to convert response: " + value + " to expected type: " + BigInteger.class.getSimpleName());
}
});
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ExtensionService method initiateContractExtension.
public Observable<QuorumExtendContract> initiateContractExtension(final QuorumNetworkProperty.Node node, final String addressToExtend, final QuorumNetworkProperty.Node newParty, final PrivacyFlag privacyFlag) {
String recipientKey = accountService.getDefaultAccountAddress(newParty).blockingFirst();
final List<String> privateFor = Stream.of(newParty).map(n -> privacyService.id(n)).collect(Collectors.toList());
final EnhancedPrivateTransaction transactionArgs = new EnhancedPrivateTransaction(accountService.getDefaultAccountAddress(node).blockingFirst(), null, null, null, BigInteger.ZERO, null, privacyService.id(node), privateFor, singletonList(privacyFlag));
final List<Object> arguments = Stream.of(addressToExtend, privacyService.id(newParty), recipientKey, transactionArgs).collect(Collectors.toList());
final Request<?, QuorumExtendContract> request = new Request<>("quorumExtension_extendContract", arguments, connectionFactory().getWeb3jService(node), QuorumExtendContract.class);
return request.flowable().toObservable();
}
Aggregations