@Test public void escrowHelperTest() throws Exception { KeyAddress issuerAddress = TestKeys.publicKey(9).getShortAddress(); KeyAddress contractorAddress = TestKeys.publicKey(10).getShortAddress(); KeyAddress customerAddress = TestKeys.publicKey(11).getShortAddress(); KeyAddress arbitratorAddress = TestKeys.publicKey(12).getShortAddress(); KeyAddress storageServiceAddress = TestKeys.publicKey(13).getShortAddress(); PrivateKey issuerKey = TestKeys.privateKey(9); PrivateKey contractorKey = TestKeys.privateKey(10); PrivateKey customerKey = TestKeys.privateKey(11); PrivateKey arbitratorKey = TestKeys.privateKey(12); PrivateKey storageServiceKey = TestKeys.privateKey(13); TestSpace ts = prepareTestSpace(); ts.nodes.forEach(n->{n.config.setIsFreeRegistrationsAllowedFromYaml(true); n.config.getAddressesWhiteList().add(ts.client.getSession().getPrivateKey().getPublicKey().getLongAddress());}); Contract payment; Contract escrow; ItemResult ir; Contract[] res; payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),Binder.of("data","asdasd123"),Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofDays(500),payment)[0]; escrow.addSignatureToSeal(issuerKey); escrow.addSignatureToSeal(customerKey); ir = ts.client.register(escrow.getPackedTransaction(),8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = EscrowHelper.completeEscrow(escrow,Binder.of("description","Completion details"))[0]; Compound compound = new Compound(); compound.addContract("escrow",escrow,null); compound.getCompoundContract().addSignatureToSeal(contractorKey); compound.getCompoundContract().addSignatureToSeal(storageServiceKey); ir = ts.client.register(compound.getCompoundContract().getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = compound.getContract("escrow"); res = EscrowHelper.closeByCustomer(escrow); escrow = res[0]; compound = new Compound(); compound.addContract("escrow",escrow,null); compound.getCompoundContract().addSignatureToSeal(customerKey); compound.getCompoundContract().addSignatureToSeal(storageServiceKey); ir = ts.client.register(compound.getCompoundContract().getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = compound.getContract("escrow"); res = EscrowHelper.obtainPaymentOnClosedEscrow(escrow); payment = res[0]; payment.addSignatureToSeal(contractorKey); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = payment.createRevision(contractorKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),null,Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofDays(500),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = EscrowHelper.completeEscrow(escrow,Binder.of("description","Completion details"))[0]; escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(storageServiceKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = EscrowHelper.closeByArbitration(escrow); escrow = res[0]; escrow.addSignatureToSeal(arbitratorKey); escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(storageServiceKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = EscrowHelper.obtainPaymentOnClosedEscrow(escrow); payment = res[0]; payment.addSignatureToSeal(contractorKey); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = payment.createRevision(contractorKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),Binder.of("aaa","111"),Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofDays(500),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = EscrowHelper.completeEscrow(escrow,Binder.of("description","Completion details"))[0]; escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(storageServiceKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = EscrowHelper.cancelEscrow(escrow); escrow = res[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = res[1]; payment = payment.createRevision(customerKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),null,Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofDays(500),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); escrow = EscrowHelper.completeEscrow(escrow,Binder.of("description","Completion details"))[0]; escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(storageServiceKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = EscrowHelper.cancelEscrow(escrow); escrow = res[0]; escrow.addSignatureToSeal(arbitratorKey); escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(storageServiceKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = res[1]; payment = payment.createRevision(customerKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),null,Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofDays(500),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); res = EscrowHelper.cancelEscrow(escrow); escrow = res[0]; escrow.addSignatureToSeal(contractorKey); escrow.addSignatureToSeal(customerKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = res[1]; payment = payment.createRevision(customerKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); payment.getTransactionPack().addReferencedItem(escrow); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),null,Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofSeconds(3),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.assignEscrow(escrow,contractorAddress,Binder.of("description","Assignment is done with additional info..."))[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(contractorKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); Thread.sleep(3000); res = EscrowHelper.cancelEscrow(escrow); escrow = res[0]; escrow.addSignatureToSeal(customerKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = res[1]; payment = payment.createRevision(customerKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = new Contract(customerKey); payment.seal(); assertEquals(ts.client.register(payment.getPackedTransaction(),8000).state,ItemState.APPROVED); escrow = EscrowHelper.initEscrow(Do.listOf(issuerAddress),null,Binder.of("description","This is description the work to be done"),customerAddress,arbitratorAddress,storageServiceAddress,Duration.ofSeconds(30000),payment)[0]; escrow.addSignatureToSeal(customerKey); escrow.addSignatureToSeal(issuerKey); assertEquals(ts.client.register(escrow.getPackedTransaction(),8000).state,ItemState.APPROVED); res = EscrowHelper.cancelEscrow(escrow); escrow = res[0]; escrow.addSignatureToSeal(customerKey); ir = ts.client.register(escrow.getPackedTransaction(), 8000); System.out.println(ir); assertEquals(ir.state,ItemState.APPROVED); payment = res[1]; payment = payment.createRevision(customerKey); payment.setOwnerKeys(TestKeys.publicKey(20)); payment.seal(); ir = ts.client.register(payment.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; }