@Test public void testPermanetApiGetBodyResync() 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> privateKeys = new HashSet<>(asList(TestKeys.privateKey(0))); Set<PublicKey> publicKeys = new HashSet<>(); for (PrivateKey pk : privateKeys) { publicKeys.add(pk.getPublicKey()); } Contract parcelContract = Contract.fromDslFile(ROOT_PATH + "LamborghiniOwnership.yml"); PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey")); parcelContract.setOwnerKeys(TestKeys.privateKey(1).getPublicKey()); parcelContract.addSignerKey(manufacturePrivateKey); parcelContract.seal(); parcelContract.check(); parcelContract.traceErrors(); Parcel parcel = createParcelWithFreshU(client, parcelContract, privateKeys); client.registerParcelWithState(parcel.pack(), 8000); ItemResult itemResult = client.getState(parcel.getPayloadContract().getId()); System.out.println("root : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); Thread.sleep(2000); HashId origin = parcelContract.getId(); Db db = ((PostgresLedger) main.node.getLedger()).getDb(); try (PreparedStatement statement = db.statement("delete from kept_items where origin = ?")) { statement.setBytes(1, origin.getDigest()); db.updateWithStatement(statement); } catch (Exception e) { e.printStackTrace(); throw e; } assertNull(main.node.getLedger().getKeepingItem(parcelContract.getId())); byte[] keeping = client.getBody(parcel.getPayloadContract().getId()); assertNotNull(keeping); assertTrue(Arrays.equals(parcel.getPayloadContract().getPackedTransaction(), keeping)); Contract revisionContract = parcelContract.createRevision(manufacturePrivateKey); revisionContract.setOwnerKeys(TestKeys.privateKey(2).getPublicKey()); revisionContract.addSignerKey(TestKeys.privateKey(1)); revisionContract.seal(); revisionContract.check(); revisionContract.traceErrors(); parcel = createParcelWithFreshU(client, revisionContract, privateKeys); client.registerParcelWithState(parcel.pack(), 8000); itemResult = client.getState(parcel.getPayloadContract().getId()); System.out.println("revision : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); itemResult = client.getState(parcelContract.getId()); System.out.println("root : " + itemResult); assertEquals(ItemState.REVOKED, itemResult.state); Thread.sleep(2000); try (PreparedStatement statement = db.statement("delete from kept_items where origin = ?")) { statement.setBytes(1, origin.getDigest()); db.updateWithStatement(statement); } catch (Exception e) { e.printStackTrace(); throw e; } assertNull(main.node.getLedger().getKeepingItem(parcelContract.getId())); assertNull(main.node.getLedger().getKeepingItem(revisionContract.getId())); byte[] keeping_root = client.getBody(parcelContract.getId()); byte[] keeping_revision = client.getBody(revisionContract.getId()); assertNotNull(keeping_root); assertNotNull(keeping_revision); assertTrue(Arrays.equals(parcelContract.getPackedTransaction(), keeping_root)); assertTrue(Arrays.equals(revisionContract.getPackedTransaction(), keeping_revision)); Thread.sleep(2000); 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; }