@Test public void secureLoanTestRepaymentMintableSimple() 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.createMintableTokenContract(new HashSet<>(Do.listOf(TestKeys.privateKey(15))), new HashSet<>(Do.listOf(lenderKey.getPublicKey())), new BigDecimal("800"), new BigDecimal("0.1"), "uEUR", "UniEuro", "Coin description"); token.seal(); assertEquals(ts.client.register(token.getPackedTransaction(),8000).state,ItemState.APPROVED); Contract rest = ContractsService.createMintableTokenContract(new HashSet<>(Do.listOf(TestKeys.privateKey(15))), new HashSet<>(Do.listOf(borrowerKey.getPublicKey())), new BigDecimal("200"), new BigDecimal("0.1"), "uEUR", "UniEuro", "Coin description"); rest.seal(); assertEquals(ts.client.register(rest.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); PrivateKey issuerKey = TestKeys.privateKey(13); Contract[] res = SecureLoanHelper.initSecureLoan(Do.listOf(issuerKey.getPublicKey().getLongAddress()),null, lenderAddress, borrowerAddress, token, Duration.ofSeconds(300), collateral, "1000",true,null,token.getIssuer().getSimpleAddress(), (String) token.getDefinition().getData().get("currency")); Contract secureLoan = res[0]; secureLoan.seal(); Compound compound = new Compound(); compound.addContract("loan",secureLoan,null); compound.getCompoundContract().addSignatureToSeal(borrowerKey); compound.getCompoundContract().addSignatureToSeal(lenderKey); compound.getCompoundContract().addSignatureToSeal(issuerKey); ItemResult ir = ts.client.register(compound.getCompoundContract().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); assertEquals(ir.state,ItemState.APPROVED); res = SecureLoanHelper.repaySecureLoan(secureLoan,token); secureLoan = res[0]; compound = new Compound(); compound.addContract("loan",secureLoan,null); compound.getCompoundContract().addSignatureToSeal(borrowerKey); ir = ts.client.register(compound.getCompoundContract().getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = SecureLoanHelper.closeSecureLoan(secureLoan); secureLoan = res[0]; token = res[1]; collateral = res[2]; compound = new Compound(); compound.addContract("loan",secureLoan,null); compound.getCompoundContract().addSignatureToSeal(borrowerKey); compound.getCompoundContract().addSignatureToSeal(lenderKey); ir = ts.client.register(compound.getCompoundContract().getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); token = token.createRevision(lenderKey); token.setOwnerKeys(TestKeys.publicKey(5)); token.seal(); ir = ts.client.register(token.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); token = collateral.createRevision(borrowerKey); token.setOwnerKeys(TestKeys.publicKey(5)); token.seal(); ir = ts.client.register(token.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; }