@Test public void conversionSchemeUtoUTN() throws Exception { PrivateKey universaAdminKey = TestKeys.privateKey(10); PrivateKey utnIssuerKey = TestKeys.privateKey(11); PrivateKey uIssuerKey = new PrivateKey(Do.read(Config.uKeyPath)); PrivateKey userKey = TestKeys.privateKey(12); Set<PrivateKey> userKeys = new HashSet<>(); userKeys.add(userKey); SimpleRole universaAdmin = new SimpleRole("universa_admin"); universaAdmin.addKeyRecord(new KeyRecord(universaAdminKey.getPublicKey())); TestSpace testSpace = prepareTestSpace(userKey); testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); Set<PrivateKey> utnIssuer = new HashSet<>(); utnIssuer.add(utnIssuerKey); Set<PublicKey> ownerKeys = new HashSet<>(); ownerKeys.add(userKey.getPublicKey()); Contract utnContract = ContractsService.createTokenContract(utnIssuer, ownerKeys, new BigDecimal("100000")); @NonNull ItemResult ir = testSpace.client.register(utnContract.getPackedTransaction()); while (ir.state.isPending()) { Thread.sleep(500); ir = testSpace.client.getState(utnContract.getId()); } assertEquals(ir.state, ItemState.APPROVED); Contract compound = ContractsService.createSplit(utnContract, new BigDecimal("150"), "amount", new HashSet<>(), true); Contract paymentInUTNs = (Contract) compound.getNewItems().iterator().next(); paymentInUTNs.setOwnerKeys(universaAdminKey); BigDecimal utnsPayed = new BigDecimal(paymentInUTNs.getStateData().getString("amount")); int unitsToIssue = utnsPayed.intValue() * 100; Contract uContract = InnerContractsService.createFreshU(unitsToIssue, ownerKeys); Contract consent = ContractsService.addConsent(uContract, universaAdminKey.getPublicKey().getLongAddress()); uContract.seal(); compound.addNewItems(uContract); consent.addSignerKey(universaAdminKey); consent.seal(); compound.seal(); compound.addSignatureToSeal(userKeys); ir = testSpace.client.register(compound.getPackedTransaction()); while (ir.state.isPending()) { Thread.sleep(500); ir = testSpace.client.getState(compound.getId()); } assertEquals(ir.state, ItemState.DECLINED); compound.seal(); compound.addSignatureToSeal(userKeys); Contract batch = ContractsService.createBatch(userKeys, compound, consent); ir = testSpace.client.register(batch.getPackedTransaction()); while (ir.state.isPending()) { Thread.sleep(500); ir = testSpace.client.getState(batch.getId()); } assertEquals(ir.state, ItemState.APPROVED); Contract sampleContract = new Contract(userKey); sampleContract.seal(); Parcel parcel = ContractsService.createParcel(sampleContract, uContract, 1, userKeys); testSpace.client.registerParcelWithState(parcel.pack(), 5000); do { Thread.sleep(500); ir = testSpace.client.getState(sampleContract.getId()); } while (ir.state.isPending()); ItemResult pr = testSpace.client.getState(parcel.getPaymentContract().getId()); assertEquals(pr.state, ItemState.APPROVED); assertEquals(ir.state, ItemState.APPROVED); uContract = parcel.getPaymentContract(); Contract revocation = ContractsService.createRevocation(consent, universaAdminKey); ir = testSpace.client.register(revocation.getPackedTransaction()); while (ir.state.isPending()) { Thread.sleep(500); ir = testSpace.client.getState(revocation.getId()); } assertEquals(ir.state, ItemState.APPROVED); sampleContract = new Contract(userKey); sampleContract.seal(); parcel = ContractsService.createParcel(sampleContract, uContract, 1, userKeys); testSpace.client.registerParcelWithState(parcel.pack(), 5000); do { Thread.sleep(500); ir = testSpace.client.getState(sampleContract.getId()); } while (ir.state.isPending()); assertEquals(ir.state, ItemState.APPROVED); testSpace.nodes.forEach(n -> n.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; }