use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ExtensionService method cancelExtension.
public Observable<QuorumCancel> cancelExtension(final QuorumNetworkProperty.Node node, final String address, final Set<QuorumNetworkProperty.Node> allNodes, final PrivacyFlag privacyFlag) {
final List<String> privateFor = allNodes.stream().filter(n -> !n.equals(node)).map(n -> privacyService.id(n)).collect(Collectors.toList());
final PrivateTransaction transactionArgs = new EnhancedPrivateTransaction(accountService.getDefaultAccountAddress(node).blockingFirst(), null, null, null, BigInteger.ZERO, null, privacyService.id(node), privateFor, singletonList(privacyFlag));
return new Request<>("quorumExtension_cancelExtension", Stream.of(address, transactionArgs).collect(Collectors.toList()), connectionFactory().getWeb3jService(node), QuorumCancel.class).flowable().toObservable();
}
use of org.web3j.protocol.core.Request in project besu by hyperledger.
the class PrivCallAcceptanceTest method privCall.
@Nonnull
private Request<Object, EthCall> privCall(final String privacyGroupId, final Contract eventEmitter, final boolean useInvalidParameters, final boolean useInvalidContractAddress) {
final Uint256 invalid = new Uint256(BigInteger.TEN);
@SuppressWarnings("rawtypes") final List<Type> inputParameters = useInvalidParameters ? Arrays.asList(invalid) : Collections.emptyList();
final Function function = new Function("value", inputParameters, Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
}));
final String encoded = FunctionEncoder.encode(function);
final HttpService httpService = new HttpService("http://" + minerNode.getBesu().getHostName() + ":" + minerNode.getBesu().getJsonRpcPort().get());
final String validContractAddress = eventEmitter.getContractAddress();
final String invalidContractAddress = constructInvalidString(validContractAddress);
final String contractAddress = useInvalidContractAddress ? invalidContractAddress : validContractAddress;
final Transaction transaction = Transaction.createEthCallTransaction(null, contractAddress, encoded);
return new Request<>("priv_call", Arrays.asList(privacyGroupId, transaction, "latest"), httpService, EthCall.class);
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class ClientTransactionManagerTest method sendCallErrorRevertByCode.
@Test
void sendCallErrorRevertByCode() throws IOException {
EthCall lookupDataHex = new EthCall();
Response.Error error = new Response.Error();
error.setCode(10);
error.setData(responseData);
lookupDataHex.setError(error);
Request request = mock(Request.class);
when(request.send()).thenReturn(lookupDataHex);
when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameter.class))).thenReturn(request);
assertThrows(ContractCallException.class, () -> clientTransactionManager.sendCall("0xAdress", "data", DefaultBlockParameter.valueOf("latest")));
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class ClientTransactionManagerTest method sendCallErrorSuccess.
@Test
void sendCallErrorSuccess() throws IOException {
EthCall lookupDataHex = new EthCall();
lookupDataHex.setResult(responseData);
Request request = mock(Request.class);
when(request.send()).thenReturn(lookupDataHex);
when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameter.class))).thenReturn(request);
String result = clientTransactionManager.sendCall("0xAdress", "data", DefaultBlockParameter.valueOf("latest"));
assertEquals(responseData, result);
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class HttpServiceTest method httpWebException.
@Test
public void httpWebException() throws IOException {
String content = "400 error";
Response response = new Response.Builder().code(400).message("").body(ResponseBody.create(content, null)).request(new okhttp3.Request.Builder().url(HttpService.DEFAULT_URL).build()).protocol(Protocol.HTTP_1_1).build();
OkHttpClient httpClient = Mockito.mock(OkHttpClient.class);
Mockito.when(httpClient.newCall(Mockito.any())).thenAnswer(invocation -> {
Call call = Mockito.mock(Call.class);
Mockito.when(call.execute()).thenReturn(response);
return call;
});
HttpService mockedHttpService = new HttpService(httpClient);
Request<String, EthBlockNumber> request = new Request<>("eth_blockNumber1", Collections.emptyList(), mockedHttpService, EthBlockNumber.class);
try {
mockedHttpService.send(request, EthBlockNumber.class);
} catch (ClientConnectionException e) {
assertEquals(e.getMessage(), "Invalid response received: " + response.code() + "; " + content);
return;
}
fail("No exception");
}
Aggregations