protected Contract createCoin(String yamlFilePath) throws IOException { Contract c = Contract.fromDslFile(yamlFilePath); c.setOwnerKey(ownerKey2); return c; }
protected static Contract createCoin(String yamlFilePath) throws IOException { Contract c = Contract.fromDslFile(yamlFilePath); c.setOwnerKey(ownerKey2); return c; }
protected synchronized Contract checkPayment_preparePaymentContract(Set<PrivateKey> privateKeys) throws Exception { Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml"); stepaCoins.addSignerKey(privateKeys.iterator().next()); stepaCoins.seal(); registerAndCheckApproved(stepaCoins); Parcel parcel = createParcelWithFreshU(stepaCoins, privateKeys); return parcel.getPaymentContract(); }
@Test public void createFromBinaryWithRealContract() throws Exception { String fileName = "./src/test_contracts/simple_root_contract.yml"; Contract c = Contract.fromDslFile(fileName); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(c, true); fileName = "./src/test_contracts/binaryContract.unc"; try(FileOutputStream stream = new FileOutputStream(fileName)) { stream.write(c.seal()); } readContract(fileName); }
private Contract basicContractCreation(final String fileName, final String keyFileName, final PrivateKey key) throws Exception { Contract c = Contract.fromDslFile(rootPath + fileName); c.setOwnerKey(key); c.addSignerKeyFromFile(rootPath + keyFileName); c.seal(); c.check(); c.traceErrors(); assertTrue(c.check()); return c; }
@Test public void checkContractCreatedAtFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract_future.yml"); futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); futureContract.seal(); futureContract.check(); futureContract.traceErrors(); System.out.println("Contract is valid: " + futureContract.isOk()); assertFalse(futureContract.isOk()); }
@Test public void checkRegisterContractCreatedAtFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract_future.yml"); futureContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey"); futureContract.seal(); futureContract.check(); futureContract.traceErrors(); System.out.println("Contract is valid: " + futureContract.isOk()); assertFalse(futureContract.isOk()); }
@Test public void checkContractCreatedAtPastTime() throws Exception{ Contract oldContract = Contract.fromDslFile(rootPath + "simple_root_contract_past.yml"); oldContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); oldContract.seal(); oldContract.check(); oldContract.traceErrors(); System.out.println("Contract is valid: " + oldContract.isOk()); assertFalse(oldContract.isOk()); }
@Test public void goodRevoke() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); c.setOwnerKeys(new KeyRecord(goodKey.getPublicKey())); c.seal(); Contract revokeContract = c.createRevocation(goodKey); revokeContract.check(); assertTrue(revokeContract.isOk()); // tc.traceErrors(); }
@Test public void checkRegisterContractExpiresAtDistantPastTime() throws Exception{ Contract oldContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml"); oldContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey"); oldContract.getDefinition().setExpiresAt(ZonedDateTime.of(LocalDateTime.MIN.truncatedTo(ChronoUnit.SECONDS), ZoneOffset.UTC)); oldContract.seal(); oldContract.check(); oldContract.traceErrors(); System.out.println("Contract is valid: " + oldContract.isOk()); assertFalse(oldContract.isOk()); }
@Test public void checkContractExpiresAtDistantPastTime() throws Exception{ Contract oldContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); oldContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); oldContract.getDefinition().setExpiresAt(ZonedDateTime.of(LocalDateTime.MIN.truncatedTo(ChronoUnit.SECONDS), ZoneOffset.UTC)); oldContract.seal(); oldContract.check(); oldContract.traceErrors(); System.out.println("Contract is valid: " + oldContract.isOk()); assertFalse(oldContract.isOk()); }
@Test public void serializeToBinder() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); Binder b = BossBiMapper.serialize(c); Contract c1 = DefaultBiMapper.deserialize(b); // System.out.println(yaml.dump(b)); // System.out.println(yaml.dump(c1.serializeToBinder())); assertProperSimpleRootContract(c1); Contract c2 = c.copy(); assertProperSimpleRootContract(c2); }
@Test public void checkContractExpiresAtDistantFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusYears(50)); futureContract.seal(); assertTrue(futureContract.check()); System.out.println("Contract is valid: " + futureContract.isOk()); }
@Test public void checkContractExpiresAtResentFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusMinutes(1)); futureContract.seal(); assertTrue(futureContract.check()); System.out.println("Contract is valid: " + futureContract.isOk()); }
@Test public void createFromSealedWithRealContract() throws Exception { String fileName = "./src/test_contracts/subscription.yml"; Contract c = Contract.fromDslFile(fileName); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(c, true); // Contract from seal byte[] seal = c.seal(); Contract sealedContract = new Contract(seal); sealedContract.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(sealedContract, true); }
@Test public void createFromSealedWithRealContractData() throws Exception { String fileName = "./src/test_contracts/subscription_with_data.yml"; Contract c = Contract.fromDslFile(fileName); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(c, true); // Contract from seal byte[] seal = c.seal(); Contract sealedContract = new Contract(seal); sealedContract.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(sealedContract, true); }
@Test public void checkRegisterContractExpiresAtReсentFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml"); futureContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey"); futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusMinutes(1)); futureContract.seal(); assertTrue(futureContract.check()); System.out.println("Contract is valid: " + futureContract.isOk()); registerAndCheckApproved(futureContract); }
@Test public void checkRegisterContractExpiresAtReсentPastTime() throws Exception{ Contract oldContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml"); oldContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey"); oldContract.getDefinition().setExpiresAt(oldContract.getCreatedAt().minusMinutes(1)); oldContract.seal(); oldContract.check(); oldContract.traceErrors(); System.out.println("Contract is valid: " + oldContract.isOk()); assertFalse(oldContract.isOk()); }
@Test public void checkContractExpiresAtResentPastTime() throws Exception{ Contract oldContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); oldContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); oldContract.getDefinition().setExpiresAt(oldContract.getCreatedAt().minusMinutes(1)); oldContract.seal(); oldContract.check(); oldContract.traceErrors(); System.out.println("Contract is valid: " + oldContract.isOk()); assertFalse(oldContract.isOk()); }
@Test public void getPath() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.seal(); assertNull(c.get("state.data.hello.world")); assertAlmostSame(ZonedDateTime.now(), c.get("definition.created_at")); assertAlmostSame(ZonedDateTime.now(), c.get("state.created_at")); assertEquals(c.getId(), c.get("id")); assertEquals(c.getId(), c.get("state.origin")); assertEquals(c.getId(), c.get("definition.origin")); assertEquals("access certificate", c.get("definition.data.type")); }