@Test public void testGetContractAPIforManyActive() throws Exception { List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), "_permanet", false)); Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); main.config.getKeysWhiteList().add(TestKeys.publicKey(20)); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); assertTrue(main.config.isPermanetMode()); for (int i = 1; i < 4; i++) assertTrue(mm.get(i).config.isPermanetMode()); main.config.setPermanetMode(false); assertTrue(main.config.isPermanetMode()); 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))); List<Contract> splits = new ArrayList<>(); Integer amountTokens = 1000; Contract tokenContract = ContractsService.createTokenContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("1000")); tokenContract.check(); tokenContract.traceErrors(); HashId origin = tokenContract.getId(); ItemResult itemResult = client.register(tokenContract.getPackedTransaction(), 5000); System.out.println("tokenContract : " + itemResult + " = " + amountTokens.toString()); assertEquals(ItemState.APPROVED, itemResult.state); for (Integer i = 1; i < 41; i++) { Contract contractRemainder = ContractsService.createSplit(tokenContract, new BigDecimal(i), "amount", issuerPrivateKeys2, true); Contract contractSplit = contractRemainder.getNew().get(0); amountTokens -= i; splits.add(contractSplit); itemResult = client.register(contractRemainder.getPackedTransaction(), 5000); System.out.println("contractRemainder : " + itemResult + " = " + amountTokens.toString()); assertEquals(ItemState.APPROVED, itemResult.state); assertEquals(amountTokens.toString(), contractRemainder.getStateData().get("amount").toString()); assertEquals(i.toString(), contractSplit.getStateData().get("amount").toString()); assertEquals(ItemState.REVOKED, main.node.waitItem(tokenContract.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(contractRemainder.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(contractSplit.getId(), 5000).state); tokenContract = contractRemainder; } Binder result = client.getContract(origin); List<byte[]> allKeepingIds = result.getListOrThrow("contractIds"); assertFalse(result.containsKey("packedContract")); assertEquals(allKeepingIds.size(), splits.size() + 1); final HashId hash = tokenContract.getId(); assertTrue(allKeepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id))); splits.forEach(s -> assertTrue(allKeepingIds.stream().anyMatch(id -> Arrays.equals(s.getId().getDigest(), id)))); result = client.getContract(origin, 10); List<byte[]> keepingIds = result.getListOrThrow("contractIds"); assertFalse(result.containsKey("packedContract")); assertEquals(keepingIds.size(), 10); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id))); for (int i = splits.size() - 1; i > splits.size() - 10; i--) { final HashId hashSplit = splits.get(i).getId(); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id))); } mm.forEach(x -> x.config.setQueryContractsLimit(20)); result = client.getContract(origin); keepingIds = result.getListOrThrow("contractIds"); assertFalse(result.containsKey("packedContract")); assertEquals(keepingIds.size(), 20); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id))); for (int i = splits.size() - 1; i > splits.size() - 20; i--) { final HashId hashSplit = splits.get(i).getId(); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id))); } result = client.getContract(origin, 30); keepingIds = result.getListOrThrow("contractIds"); assertFalse(result.containsKey("packedContract")); assertEquals(keepingIds.size(), 20); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id))); for (int i = splits.size() - 1; i > splits.size() - 20; i--) { final HashId hashSplit = splits.get(i).getId(); assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id))); } 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; }