public Binder toBinder() { return Binder.fromKeysValues( "state", state.name(), "haveCopy", haveCopy, "createdAt", createdAt, "expiresAt", expiresAt, "errors", DefaultBiMapper.serialize(errors), "isTestnet", isTestnet, "lockedById", lockedById, "extra", extraDataBinder ); }
private ItemResult itemResultOfError(Errors error, String object, String message) { Binder binder = new Binder(); binder.put("state",ItemState.UNDEFINED.name()); binder.put("haveCopy",false); binder.put("createdAt", new Date()); binder.put("expiresAt", new Date()); ArrayList<ErrorRecord> errorRecords = new ArrayList<>(); errorRecords.add(new ErrorRecord(error,object,message)); binder.put("errors",errorRecords); return new ItemResult(binder); }
@Test public void createAndRegisterTokenFromDSL() throws Exception { // You have a token dsl and want to release own tokens String uContract = getApprovedUContract(); callMain2("-create", rootPath + "TokenDSLTemplate.yml", "--output", basePath + "realToken.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey"); assertTrue (new File(basePath + "realToken.unicon").exists()); callMain("-register", basePath + "realToken.unicon", "-u", uContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "-wait", "2000"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
@Test public void createAndRegisterNotaryContractWithFileFromDSL() throws Exception { String uContract = getApprovedUContract(); callMain2("-create", rootPath + "notaryContractWithFile.yaml", "--output", basePath + "realNotaryContractWithFile.unicon", "-k", rootPath + "keys/marty_mcfly.private.unikey"); assertTrue (new File(basePath + "realNotaryContractWithFile.unicon").exists()); callMain("--register", basePath + "realNotaryContractWithFile.unicon", "--u", uContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "--wait", "1000"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
@Test public void createAndRegisterNotaryFromDSL() throws Exception { // You have a notary dsl and want to release notarized document for someone String uContract = getApprovedUContract(); callMain2("-create", rootPath + "NotaryDSLTemplate.yml", "--output", basePath + "realNotary.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey"); assertTrue (new File(basePath + "realNotary.unicon").exists()); callMain("--register", basePath + "realNotary.unicon", "--u", uContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "--wait", "1000"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
@Test public void createAndRegisterShareFromDSL() throws Exception { String uContract = getApprovedUContract(); callMain2("-create", rootPath + "ShareDSLTemplate.yml", "--output", basePath + "realShare.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey"); assertTrue (new File(basePath + "realShare.unicon").exists()); callMain("--register", basePath + "realShare.unicon", "--u", uContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "--wait", "3000"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
@Test public void probeFile() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); c.addSignerKeyFromFile(rootPath + "keys/u_key.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); // let's make this key among owners ((SimpleRole)c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey())); c.seal(); Files.write(Paths.get(basePath + "probeFile.unicon"),c.getPackedTransaction(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); System.out.println("---"); System.out.println("register contract"); System.out.println("---"); CLIMain.registerContract(c); Thread.sleep(1500); System.out.println("---"); System.out.println("check contract"); System.out.println("---"); callMain("--probe-file", basePath + "probeFile.unicon"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
@Test public void revokeContractWithoutKey() throws Exception { String contractFileName = basePath + "contract_for_revoke1.unicon"; String uContract = getApprovedUContract(); callMain2("--register", contractFileName, "--verbose", "--u", uContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey"); callMain2("-revoke", contractFileName, "-v"); Thread.sleep(1500); System.out.println("probe after revoke"); Contract c = CLIMain.loadContract(contractFileName); callMain("--probe", c.getId().toBase64String(), "--verbose"); System.out.println(output); assertEquals(0, errors.size()); assertTrue (output.indexOf(ItemState.REVOKED.name()) < 0); }
@Test public void revokeContract() throws Exception { String contractFileName = basePath + "contract_for_revoke3.unicon"; String uContract = getApprovedUContract(); callMain2("--register", contractFileName, "--verbose", "--u", uContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey"); Contract c = CLIMain.loadContract(contractFileName); System.out.println("contract: " + c.getId().toBase64String()); Thread.sleep(1500); System.out.println("probe before revoke"); callMain2("--probe", c.getId().toBase64String(), "--verbose"); Thread.sleep(500); uContract = getApprovedUContract(); callMain2("-revoke", contractFileName, "-k", PRIVATE_KEY_PATH, "-v", "--u", uContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey"); Thread.sleep(2500); System.out.println("probe after revoke"); callMain("--probe", c.getId().toBase64String(), "--verbose"); System.out.println(output); assertEquals(0, errors.size()); assertTrue (output.indexOf(ItemState.REVOKED.name()) >= 0); }
@Test public void createRegisterParcel() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); contract.seal(); String contractFileName = basePath + "createRegisterParcel.unicon"; new FileOutputStream(contractFileName).write(contract.getPackedTransaction()); String uContract = getApprovedUContract(); callMain("--create-parcel", contractFileName, "--verbose", "--u", uContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey"); callMain("--register-parcel", new FilenameTool(contractFileName).setExtension("uniparcel").toString()); Thread.sleep(1500); System.out.println("probe after register"); Contract c = CLIMain.loadContract(contractFileName); callMain("--probe", c.getId().toBase64String(), "--verbose"); System.out.println(output); assertEquals(0, errors.size()); assertTrue (output.indexOf(ItemState.APPROVED.name()) > 0); }
assertEquals(0, errors.size()); assertTrue (output.indexOf(ItemState.REVOKED.name()) >= 1);