public String getNetVersion() { return getResult(); } }
@Test public void testNetVersion() throws Exception { NetVersion netVersion = web3j.netVersion().send(); assertFalse(netVersion.getNetVersion().isEmpty()); }
@Override public String execute(final JsonRequestFactories node) { try { final NetVersion result = node.net().netVersion().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getNetVersion(); } catch (final IOException e) { throw new RuntimeException(e); } } }
@Test public void testResolve() throws Exception { configureSyncing(false); configureLatestBlock(System.currentTimeMillis() / 1000); // block timestamp is in seconds NetVersion netVersion = new NetVersion(); netVersion.setResult(Byte.toString(ChainId.MAINNET)); String resolverAddress = "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a"; String contractAddress = "0x00000000000000000000000019e03255f667bdfd50a32722df860b1eeaf4d635"; EthCall resolverAddressResponse = new EthCall(); resolverAddressResponse.setResult(resolverAddress); EthCall contractAddressResponse = new EthCall(); contractAddressResponse.setResult(contractAddress); when(web3jService.send(any(Request.class), eq(NetVersion.class))) .thenReturn(netVersion); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(resolverAddressResponse); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(contractAddressResponse); assertThat(ensResolver.resolve("web3j.eth"), is("0x19e03255f667bdfd50a32722df860b1eeaf4d635")); }
@Test public void testNetVersion() throws IOException { buildResponse( "{\n" + " \"id\":67,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": \"59\"\n" + "}" ); NetVersion netVersion = deserialiseResponse(NetVersion.class); assertThat(netVersion.getNetVersion(), is("59")); }
@Test public void testReverseResolve() throws Exception { configureSyncing(false); configureLatestBlock(System.currentTimeMillis() / 1000); // block timestamp is in seconds NetVersion netVersion = new NetVersion(); netVersion.setResult(Byte.toString(ChainId.MAINNET)); String resolverAddress = "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a"; String contractName = "0x0000000000000000000000000000000000000000000000000000000000000020" + TypeEncoder.encode(new Utf8String("web3j.eth")); System.err.println(contractName); EthCall resolverAddressResponse = new EthCall(); resolverAddressResponse.setResult(resolverAddress); EthCall contractNameResponse = new EthCall(); contractNameResponse.setResult(contractName); when(web3jService.send(any(Request.class), eq(NetVersion.class))) .thenReturn(netVersion); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(resolverAddressResponse); when(web3jService.send(any(Request.class), eq(EthCall.class))) .thenReturn(contractNameResponse); assertThat(ensResolver.reverseResolve("0x19e03255f667bdfd50a32722df860b1eeaf4d635"), is("web3j.eth")); }
PublicResolver lookupResolver(String ensName) throws Exception { NetVersion netVersion = web3j.netVersion().send(); String registryContract = Contracts.resolveRegistryContract(netVersion.getNetVersion()); ENS ensRegistry = ENS.load( registryContract, web3j, transactionManager, DefaultGasProvider.GAS_PRICE, DefaultGasProvider.GAS_LIMIT); byte[] nameHash = NameHash.nameHashAsBytes(ensName); String resolverAddress = ensRegistry.resolver(nameHash).send(); PublicResolver resolver = PublicResolver.load( resolverAddress, web3j, transactionManager, DefaultGasProvider.GAS_PRICE, DefaultGasProvider.GAS_LIMIT); return resolver; }
if (netVersion != null) { Mockito.when(web3j.netVersion().sendAsync()).thenReturn(supplyAsync(() -> { NetVersion netVersionObject = new NetVersion(); netVersionObject.setResult(netVersion); return netVersionObject; }));
@InvokeOnHeader(Web3jConstants.NET_VERSION) void netVersion(Message message) throws IOException { Request<?, NetVersion> netVersionRequest = web3j.netVersion(); setRequestId(message, netVersionRequest); NetVersion response = netVersionRequest.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getNetVersion()); } }
public Web3j getWeb3j() { synchronized (DRIVER_LOAD_MUTEX) { if (web3j == null) { try { web3j = Web3j.build(new HttpService("http://" + getContainerIpAddress() + ":" + getMappedPort(port) + "/")); log.info("Start Web3j with net version: {}", web3j.netVersion().send().getNetVersion()); } catch (Exception e) { throw new RuntimeException("Could not get Web3j", e); } } } return web3j; }
.sendAsync() .thenApply(netVersion -> builder.withDetail("netVersion", netVersion.getNetVersion())));