Main createMainFromDb(String dbUrl, boolean nolog) throws InterruptedException { String[] args = new String[]{"--test","--database", dbUrl, nolog ? "--nolog" : ""}; List<Main> mm = new ArrayList<>(); Thread thread = new Thread(() -> { try { Main m = new Main(args); try { m.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } //m.config.getKeysWhiteList().add(m.config.getUIssuerKey()); m.waitReady(); mm.add(m); } catch (InterruptedException e) { e.printStackTrace(); } }); thread.setName("Node Server: " + dbUrl); thread.start(); while (mm.size() == 0) { Thread.sleep(100); } return mm.get(0); }
public static void destroyLocalNetwork() { localNodes.forEach(x->x.shutdown()); }
Runtime.getRuntime().addShutdownHook(hookThread = new Thread(() -> shutdown())); usage(null); log(NAME_STRING); loadNodeConfig(); loadNetConfig(); log("ledger constructed"); Object[] result = ledger.loadConfig(); myInfo = (NodeInfo) result[0]; log("key loaded: " + nodeKey.info()); log("node local URL: " + myInfo.publicUrlString()); log("node info: " + myInfo.toBinder()); setVerboseLevel(lvlId); } else if(options.has("udp-verbose")) { String lvl = (String) options.valueOf("udp-verbose"); setUDPVerboseLevel(lvlId); } else if(options.has("restart-socket")) { restartUDPAdapter(); } else if(options.has("shutdown")) { shutdown(); } else { System.err.println("Neither config no database option passed, leaving");
TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); testSpace.nodes.get(testSpace.nodes.size()-1).shutdown(); Contract contractMoney = ContractsService.createTokenContract( new HashSet<>(Arrays.asList(TestKeys.privateKey(1))), testSpace.nodes.get(i).shutdown(); Thread.sleep(2000); testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.get(testSpace.clients.size()-1).setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); testSpace.clients.get(testSpace.clients.size()-1).resyncItem(contractMoney.getId()); long millisToWait = 60000; testSpace.nodes.forEach(n->n.shutdown());
System.out.println(path); String[] args = new String[]{"--test", "--config", path, "--nolog"}; Main main = new Main(args); main.waitReady(); BufferedLogger l = main.logger; "http://localhost:8080", TestKeys.privateKey(3), main.getNodePublicKey(), null ); main.shutdown(); main.logger.stopInterceptingStdOut(); main.logger.getCopy().forEach(x -> System.out.println(x));
System.out.println(">> before restart state: " + itemResult2); main.restartUDPAdapter(); main.waitReady(); assertEquals (ItemState.APPROVED, itemResult2.state); mm.forEach(x -> x.shutdown());
ItemResult itemResult = client.getState(parcel.getPayloadContract().getId()); main.setUDPVerboseLevel(DatagramAdapter.VerboseLevel.BASE); System.out.println("---------- verbose base ---------------"); main.setUDPVerboseLevel(DatagramAdapter.VerboseLevel.NOTHING); main.setUDPVerboseLevel(DatagramAdapter.VerboseLevel.DETAILED); System.out.println("---------- verbose detailed ---------------"); main.setUDPVerboseLevel(DatagramAdapter.VerboseLevel.NOTHING); System.out.println("---------- verbose nothing ---------------"); mm.forEach(x -> x.shutdown());
public static void main(String[] args) { new Main(args); }
@Ignore @Test public void registerFromFile() throws Exception { TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.forEach(m -> m.config.setIsFreeRegistrationsAllowedFromYaml(true)); Path path = Paths.get("/tmp/not3.unicon"); byte[] testTransactionPackBytes = Files.readAllBytes(path); Contract contract = Contract.fromPackedTransaction(testTransactionPackBytes); System.out.println("======================"); System.out.println("check(): " + contract.check()); System.out.println("------- errors -------"); contract.traceErrors(); int i = 0; for (Approvable a : contract.getNewItems()) { Contract nc = (Contract) a; System.out.println("------- errors n"+i+" ----"); System.out.println(" check: " + nc.check()); nc.traceErrors(); ++i; } System.out.println("======================"); System.out.println("hashId: " + contract.getId().toBase64String()); testSpace.node.setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); ItemResult itemResult = testSpace.client.register(testTransactionPackBytes, 5000); ItemResult itemResult2 = testSpace.client.getState(contract.getId()); System.out.println("itemResult: " + itemResult); System.out.println("itemResult2: " + itemResult2); testSpace.nodes.forEach(m -> m.shutdown()); }
@Test public void freeRegistrationsAllowedFromCoreVersion() throws Exception { List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), false)); Main main = mm.get(0); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); Contract contract = new Contract(TestKeys.privateKey(0)); contract.seal(); ItemState expectedState = ItemState.UNDEFINED; if (Core.VERSION.contains("private")) expectedState = ItemState.APPROVED; System.out.println("Core.VERSION: " + Core.VERSION); System.out.println("expectedState: " + expectedState); ItemResult itemResult = client.register(contract.getPackedTransaction(), 5000); System.out.println("itemResult: " + itemResult); assertEquals(expectedState, itemResult.state); mm.forEach(x -> x.shutdown()); }
Main createMain(String name, String postfix, boolean nolog) throws InterruptedException { String path = new File("src/test_node_config_v2" + postfix + "/" + name).getAbsolutePath(); System.out.println(path); String[] args = new String[]{"--test", "--config", path, nolog ? "--nolog" : ""}; List<Main> mm = new ArrayList<>(); Thread thread = new Thread(() -> { try { Main m = new Main(args); try { m.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } //m.config.getKeysWhiteList().add(m.config.getUIssuerKey()); m.waitReady(); mm.add(m); } catch (InterruptedException e) { e.printStackTrace(); } }); thread.setName("Node Server: " + name); thread.start(); while (mm.size() == 0) { Thread.sleep(100); } return mm.get(0); }
testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); testSpace.nodes.forEach(m -> ((PostgresLedger)m.node.getLedger()).enableCache(false)); testSpace.nodes.get(testSpace.nodes.size()-1).shutdown(); testSpace.nodes.get(i).shutdown(); Thread.sleep(2000); testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.get(testSpace.clients.size()-1).setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); testSpace.clients.get(testSpace.clients.size()-1).resyncItem(rev1.getId()); long millisToWait = 60000; assertNull(ledger.getEnvironment(rev1.getId())); testSpace.nodes.forEach(n->n.shutdown());
System.out.println("\n"); mm.forEach(x -> x.shutdown());
static Main createMain(String name,boolean nolog) throws InterruptedException { String path = new File("src/test_node_config_v2/"+name).getAbsolutePath(); System.out.println(path); String[] args = new String[]{"--test", "--config", path, nolog ? "--nolog" : ""}; Main main = new Main(args); try { main.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } try { //main.config.getKeysWhiteList().add(CLIMain.getPrivateKey().getPublicKey()); main.config.getAddressesWhiteList().add(new KeyAddress(CLIMain.getPrivateKey().getPublicKey(), 0, true)); } catch (IOException e) { e.printStackTrace(); } //main.config.getKeysWhiteList().add(main.config.getUIssuerKey()); main.waitReady(); return main; }
TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); testSpace.nodes.get(testSpace.nodes.size()-1).shutdown(); testSpace.nodes.get(i).shutdown(); Thread.sleep(2000); testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.get(testSpace.clients.size()-1).setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); Contract joinAll = splitNest.createRevision(); joinAll.getStateData().set("amount", "9000"); testSpace.nodes.forEach(n -> n.shutdown());
ItemResult itemResult = client.getState(parcel.getPayloadContract().getId()); main.setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); System.out.println("---------- verbose base ---------------"); assertEquals (DatagramAdapter.VerboseLevel.BASE, main.node.getVerboseLevel()); main.setVerboseLevel(DatagramAdapter.VerboseLevel.NOTHING); System.out.println("---------- verbose nothing ---------------"); assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.node.getVerboseLevel()); mm.forEach(x -> x.shutdown());
System.out.println("\n"); mm.forEach(x -> x.shutdown());