use of org.web3j.protocol.core.Request in project web3j by web3j.
the class IpcServiceTest method testSend.
@Test
public void testSend() throws IOException {
when(ioFacade.read()).thenReturn("{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n");
ipcService.send(new Request(), Web3ClientVersion.class);
verify(ioFacade).write("{\"jsonrpc\":\"2.0\",\"method\":null,\"params\":null,\"id\":0}");
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class UnixDomainSocketTest method testSlowResponse.
@Test
public void testSlowResponse() throws Exception {
String response = "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n";
unixDomainSocket = new UnixDomainSocket(reader, writer, response.length());
final LinkedList<String> segments = new LinkedList<>();
// 1st part of response
segments.add(response.substring(0, 50));
// rest of response
segments.add(response.substring(50));
doAnswer(invocation -> {
String segment = segments.poll();
if (segment == null) {
return 0;
} else {
Object[] args = invocation.getArguments();
((CharBuffer) args[0]).append(segment);
return segment.length();
}
}).when(reader).read(any(CharBuffer.class));
IpcService ipcService = new IpcService() {
@Override
protected IOFacade getIO() {
return unixDomainSocket;
}
};
ipcService.send(new Request(), Web3ClientVersion.class);
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class WebSocketServiceTest method testBatchRequestReply.
@Test
public void testBatchRequestReply() throws Exception {
BatchRequest request = new BatchRequest(service);
request.add(new Request<>("web3_clientVersion", Collections.<String>emptyList(), service, Web3ClientVersion.class)).add(new Request<>("net_version", Collections.<String>emptyList(), service, NetVersion.class));
request.getRequests().get(0).setId(1L);
request.getRequests().get(1).setId(1L);
CompletableFuture<BatchResponse> reply = service.sendBatchAsync(request);
verify(webSocketClient).send("[" + "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":0}," + "{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":1}" + "]");
sendClientNetVersionReply();
assertTrue(reply.isDone());
BatchResponse response = reply.get();
assertEquals(response.getResponses().size(), 2);
assertTrue(response.getResponses().get(0) instanceof Web3ClientVersion);
Web3ClientVersion web3ClientVersion = (Web3ClientVersion) response.getResponses().get(0);
assertEquals(web3ClientVersion.getWeb3ClientVersion(), "Mist/v0.9.3/darwin/go1.4.1");
assertTrue(response.getResponses().get(1) instanceof NetVersion);
NetVersion netVersion = (NetVersion) response.getResponses().get(1);
assertEquals(netVersion.getNetVersion(), "59");
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class ClientTransactionManagerTest method sendCallErrorRevertByDataNull.
@Test
void sendCallErrorRevertByDataNull() throws IOException {
EthCall lookupDataHex = new EthCall();
Response.Error error = new Response.Error();
error.setCode(3);
error.setData(null);
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 sendCallErrorResponseNotRevert.
/**
* According to EIP 3668, error is a valid behavior in a new functionality.
*/
@Test
void sendCallErrorResponseNotRevert() throws IOException {
EthCall lookupDataHex = new EthCall();
Response.Error error = new Response.Error();
error.setCode(3);
error.setMessage("execution reverted");
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);
String result = clientTransactionManager.sendCall("0xAdress", "data", DefaultBlockParameter.valueOf("latest"));
assertEquals(responseData, result);
}
Aggregations