@Test public void testSplitAndJoinApi() 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); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); Set<PrivateKey> issuerPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(1))); Set<PublicKey> ownerPublicKeys = new HashSet<>(asList(TestKeys.publicKey(2))); Set<PrivateKey> issuerPrivateKeys2 = new HashSet<>(asList(TestKeys.privateKey(2))); Contract contractC = ContractsService.createTokenContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("100")); contractC.check(); contractC.traceErrors(); ItemResult itemResult = client.register(contractC.getPackedTransaction(), 5000); System.out.println("contractC : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); Contract сontractA = ContractsService.createSplit(contractC, new BigDecimal("30"), "amount", issuerPrivateKeys2, true); Contract contractB = сontractA.getNew().get(0); assertEquals("70", сontractA.getStateData().get("amount").toString()); assertEquals("30", contractB.getStateData().get("amount").toString()); itemResult = client.register(сontractA.getPackedTransaction(), 5000); System.out.println("сontractA : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); assertEquals("70", сontractA.getStateData().get("amount").toString()); assertEquals("30", contractB.getStateData().get("amount").toString()); assertEquals(ItemState.REVOKED, main.node.waitItem(contractC.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(сontractA.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(contractB.getId(), 5000).state); Contract contractC2 = ContractsService.createJoin(сontractA, contractB, "amount", issuerPrivateKeys2); contractC2.check(); contractC2.traceErrors(); assertTrue(contractC2.isOk()); itemResult = client.register(contractC2.getPackedTransaction(), 5000); System.out.println("contractC2 : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); assertEquals(new Decimal(100), contractC2.getStateData().get("amount")); assertEquals(ItemState.REVOKED, main.node.waitItem(contractC.getId(), 5000).state); assertEquals(ItemState.REVOKED, main.node.waitItem(сontractA.getId(), 5000).state); assertEquals(ItemState.REVOKED, main.node.waitItem(contractB.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(contractC2.getId(), 5000).state); mm.forEach(x -> x.shutdown()); }
public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); static final String NODE_VERSION; final Reporter reporter; final BufferedLogger logger; public NetConfig netConfig; public NetworkV2 network; final Config config; public NodeInfo myInfo; public Node node; public ItemCache cache; public ParcelCache parcelCache; public PaidOperationCache paidOperationCache; }