@Test public void secureLoanTestDefault() throws Exception{ TestSpace ts = prepareTestSpace(); ts.nodes.forEach(n->n.config.setIsFreeRegistrationsAllowedFromYaml(true)); PrivateKey lenderKey = TestKeys.privateKey(1); PrivateKey borrowerKey = TestKeys.privateKey(2); KeyAddress lenderAddress = lenderKey.getPublicKey().getLongAddress(); KeyAddress borrowerAddress = borrowerKey.getPublicKey().getLongAddress(); Contract token = ContractsService.createTokenContract(new HashSet<>(Do.listOf(TestKeys.privateKey(15))),new HashSet<>(Do.listOf(lenderKey.getPublicKey())),new BigDecimal("1000")); token.seal(); assertEquals(ts.client.register(token.getPackedTransaction(),8000).state,ItemState.APPROVED); token = ContractsService.createSplit(token,new BigDecimal("200"),"amount",new HashSet<>(Do.listOf(lenderKey))); token.setCreatorKeys(lenderKey.getPublicKey()); Contract rest = (Contract) token.getNewItems().iterator().next(); rest.setCreatorKeys(lenderKey.getPublicKey()); rest.setOwnerKeys(borrowerAddress); rest.seal(); token.seal(); ItemResult ir = ts.client.register(token.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); Contract collateral = new Contract(TestKeys.privateKey(15)); collateral.setOwnerKeys(borrowerKey); collateral.getStateData().put("description","This is very valuable contract"); collateral.seal(); assertEquals(ts.client.register(collateral.getPackedTransaction(),8000).state,ItemState.APPROVED); Contract[] res = SecureLoanHelper.initSecureLoan(null,lenderAddress, borrowerAddress, token, Duration.ofSeconds(3), collateral, "1000",false,token.getOrigin(),null,null); Contract secureLoan = res[0]; secureLoan.addSignatureToSeal(borrowerKey); secureLoan.addSignatureToSeal(lenderKey); ir = ts.client.register(secureLoan.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); Contract col1 = collateral.createRevision(borrowerKey,lenderKey); col1.setOwnerKeys(TestKeys.publicKey(4)); col1.seal(); col1.getTransactionPack().addReferencedItem(secureLoan); ir = ts.client.register(col1.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.DECLINED); Contract defaultAttempt = SecureLoanHelper.defaultSecureLoan(secureLoan)[0]; defaultAttempt.addSignatureToSeal(lenderKey); ir = ts.client.register(defaultAttempt.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.DECLINED); Thread.sleep(6000); res = SecureLoanHelper.defaultSecureLoan(secureLoan); secureLoan = res[0]; collateral = res[1]; secureLoan.addSignatureToSeal(lenderKey); ir = ts.client.register(secureLoan.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); Contract col2 = collateral.createRevision(lenderKey); col2.setOwnerKeys(TestKeys.publicKey(4)); col2.seal(); col2 = Contract.fromPackedTransaction(col2.getPackedTransaction()); assertTrue(col2.check()); ir = ts.client.register(col2.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); ts.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; }