@Test public void ecsrowCancelAndTakePaymentFail() throws Exception { List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), false)); Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); Set<PrivateKey> issuerPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(0))); Set<PrivateKey> customerPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(1))); Set<PrivateKey> arbitratorPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(2))); Set<PrivateKey> executorPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(3))); Set<PublicKey> issuerPublicKeys = new HashSet<>(); for (PrivateKey pk : issuerPrivateKeys) { issuerPublicKeys.add(pk.getPublicKey()); } Set<PublicKey> customerPublicKeys = new HashSet<>(); for (PrivateKey pk : customerPrivateKeys) { customerPublicKeys.add(pk.getPublicKey()); } Set<PublicKey> executorPublicKeys = new HashSet<>(); for (PrivateKey pk : executorPrivateKeys) { executorPublicKeys.add(pk.getPublicKey()); } Set<PublicKey> arbitratorPublicKeys = new HashSet<>(); for (PrivateKey pk : arbitratorPrivateKeys) { arbitratorPublicKeys.add(pk.getPublicKey()); } Contract payment = InnerContractsService.createFreshU(100, customerPublicKeys, true); payment.check(); payment.traceErrors(); ItemResult itemResult = client.register(payment.getPackedTransaction(), 5000); System.out.println("payment : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); payment = payment.createRevision(customerPrivateKeys); Contract escrow = ContractsService.createEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); assertEquals(escrow.getDefinition().getData().getString("EscrowOrigin", "null"), escrow.getNew().get(0).getOrigin().toBase64String()); assertEquals(escrow.getNew().get(0).getStateData().getString("status", "null"), "opened"); boolean result = ContractsService.addPaymentToEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); assertTrue(result); assertTrue(payment.findReferenceByName("return_payment_to_customer", "transactional") != null); assertTrue(payment.findReferenceByName("send_payment_to_executor", "transactional") != null); escrow.check(); escrow.traceErrors(); itemResult = client.register(escrow.getPackedTransaction(), 5000); System.out.println("escrow : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); itemResult = main.node.waitItem(payment.getId(), 8000); assertEquals(ItemState.APPROVED, itemResult.state); Contract canceledEscrow = ContractsService.cancelEscrowContract(escrow); assertEquals(canceledEscrow.getStateData().getString("status", "null"), "canceled"); canceledEscrow.addSignatureToSeal(issuerPrivateKeys); canceledEscrow = Contract.fromPackedTransaction(canceledEscrow.getPackedTransaction()); canceledEscrow.addSignatureToSeal(customerPrivateKeys); canceledEscrow = Contract.fromPackedTransaction(canceledEscrow.getPackedTransaction()); canceledEscrow.addSignatureToSeal(arbitratorPrivateKeys); canceledEscrow.check(); canceledEscrow.traceErrors(); itemResult = client.register(canceledEscrow.getPackedTransaction(), 5000); System.out.println("canceledEscrow : " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); Contract newPayment = ContractsService.takeEscrowPayment(executorPrivateKeys, payment); newPayment.getTransactionPack().addReferencedItem(canceledEscrow); newPayment.check(); newPayment.traceErrors(); itemResult = client.register(newPayment.getPackedTransaction(), 5000); System.out.println("newPayment : " + itemResult); assertEquals(ItemState.DECLINED, itemResult.state); 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; }