use of net.sergeych.tools.BufferedLogger in project universa by UniversaBlockchain.
the class MainTest method startNode.
@Test
public void startNode() throws Exception {
String path = new File("src/test_node_config_v2/node1").getAbsolutePath();
System.out.println(path);
String[] args = new String[] { "--test", "--config", path, "--nolog" };
Main main = new Main(args);
main.waitReady();
BufferedLogger l = main.logger;
Client client = new Client("http://localhost:8080", TestKeys.privateKey(3), main.getNodePublicKey(), null);
Binder data = client.command("status");
data.getStringOrThrow("status");
// assertThat(data.getListOrThrow("log").size(), greaterThan(3));
BasicHttpClient.Answer a = client.request("ping");
assertEquals("200: {ping=pong}", a.toString());
Contract c = new Contract();
c.setIssuerKeys(TestKeys.publicKey(3));
c.addSignerKey(TestKeys.privateKey(3));
c.registerRole(new RoleLink("owner", "issuer"));
c.registerRole(new RoleLink("creator", "issuer"));
c.setExpiresAt(ZonedDateTime.now().plusDays(2));
byte[] sealed = c.seal();
// Bytes.dump(sealed);
Contract c1 = new Contract(sealed);
assertArrayEquals(c.getLastSealedBinary(), c1.getLastSealedBinary());
main.cache.put(c);
assertNotNull(main.cache.get(c.getId()));
URL url = new URL("http://localhost:8080/contracts/" + c.getId().toBase64String());
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
assertEquals(200, con.getResponseCode());
byte[] data2 = Do.read(con.getInputStream());
assertArrayEquals(c.getPackedTransaction(), data2);
url = new URL("http://localhost:8080/network");
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
assertEquals(200, con.getResponseCode());
Binder bres = Boss.unpack((Do.read(con.getInputStream()))).getBinderOrThrow("response");
List<Binder> ni = bres.getBinders("nodes");
String pubUrls = ni.stream().map(x -> x.getStringOrThrow("url")).collect(Collectors.toList()).toString();
assertEquals("[http://localhost:8080, http://localhost:6002, http://localhost:6004, http://localhost:6006]", pubUrls);
main.shutdown();
main.logger.stopInterceptingStdOut();
;
main.logger.getCopy().forEach(x -> System.out.println(x));
}
Aggregations