@Test public void secureLoanTestRepayment() 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())),"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(lenderAddress); Contract rest = (Contract) token.getNewItems().iterator().next(); rest.setCreatorKeys(lenderAddress); rest.setOwnerKeys(borrowerAddress); rest.seal(); token.seal(); assertEquals(ts.client.register(token.getPackedTransaction(),8000).state,ItemState.APPROVED); Contract collateral = new Contract(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(Binder.of("description","bla bla bla"),lenderAddress, borrowerAddress, token, Duration.ofSeconds(30), collateral, "1000",false,token.getOrigin(),null,null); Contract secureLoan = res[0]; secureLoan.addSignatureToSeal(borrowerKey); secureLoan.addSignatureToSeal(lenderKey); ItemResult ir = ts.client.register(secureLoan.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); token = res[1]; token = token.createRevision(borrowerKey); token.addRevokingItems(rest); token.getStateData().set("amount","1000"); token.seal(); ir = ts.client.register(token.getPackedTransaction(),8000); System.out.println(ir); res = SecureLoanHelper.repaySecureLoan(secureLoan,token); secureLoan = res[0]; secureLoan.addSignatureToSeal(borrowerKey); ir = ts.client.register(secureLoan.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); Contract tokenAtempt = token.createRevision(lenderKey); tokenAtempt.setOwnerKeys(TestKeys.publicKey(5)); tokenAtempt.seal(); tokenAtempt.getTransactionPack().addReferencedItem(secureLoan); ir = ts.client.register(tokenAtempt.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.DECLINED); Contract collateralAtempt = collateral.createRevision(borrowerKey); collateralAtempt.setOwnerKeys(TestKeys.publicKey(5)); collateralAtempt.seal(); collateralAtempt.getTransactionPack().addReferencedItem(secureLoan); ir = ts.client.register(collateralAtempt.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.DECLINED); res = SecureLoanHelper.closeSecureLoan(secureLoan); secureLoan = res[0]; token = res[1]; collateral = res[2]; secureLoan.addSignatureToSeal(lenderKey); secureLoan.addSignatureToSeal(borrowerKey); ir = ts.client.register(secureLoan.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); tokenAtempt = token.createRevision(lenderKey); tokenAtempt.setOwnerKeys(TestKeys.publicKey(5)); tokenAtempt.seal(); ir = ts.client.register(tokenAtempt.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); collateralAtempt = collateral.createRevision(borrowerKey); collateralAtempt.setOwnerKeys(TestKeys.publicKey(5)); collateralAtempt.seal(); ir = ts.client.register(collateralAtempt.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; }