@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 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 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 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 createNotaryContract() throws Exception { if(node == null) { System.out.println("network not inited"); return; } Contract c = Contract.fromDslFile(ROOT_PATH + "notary_4096.yaml"); c.addSignerKeyFromFile(ROOT_PATH + "keys/romanuskov_4096.private.unikey"); c.seal(); c.check(); c.traceErrors(); assertTrue(c.isOk()); registerAndCheckApproved(c); }
@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 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 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 checkContractExpiresAtDistantFutureTime() throws Exception{ Contract futureContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml"); futureContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey"); futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusYears(50)); futureContract.seal(); assertTrue(futureContract.check()); System.out.println("Contract is valid: " + futureContract.isOk()); registerAndCheckApproved(futureContract); }
@Test public void modifyExpiresAtAllowed() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); contract.getStateData().put("field_to_be_changed", "value1"); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"), new Binder()); modifyDataPermission.addField("/expires_at", null); contract.addPermission(modifyDataPermission); contract.seal(); Contract changed = contract.createRevision(); changed.addSignerKey(TestKeys.privateKey(0)); changed.setExpiresAt(ZonedDateTime.now().plusDays(1)); changed.seal(); changed.check(); assertTrue(changed.isOk()); }
@Test public void goodSmartContractFromDSL() throws Exception { Contract smartContract = NSmartContract.fromDslFile(rootPath + "NotarySmartDSLTemplate.yml"); smartContract.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey"); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); }
@Test public void goodNSmartContractFromDSL() throws Exception { Contract smartContract = NSmartContract.fromDslFile(rootPath + "NotaryNSmartDSLTemplate.yml"); smartContract.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey"); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); }
@Test public void goodNSmartContract() throws Exception { final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey")); Contract smartContract = new NSmartContract(key); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); }
@Test public void goodSmartContract() throws Exception { final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey")); Contract smartContract = new NSmartContract(key); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); }