public synchronized Parcel createParcelWithFreshU(Contract c, Set<PrivateKey> keys) throws Exception { Set<PublicKey> ownerKeys = new HashSet(); keys.stream().forEach(key -> ownerKeys.add(key.getPublicKey())); Contract stepaU = InnerContractsService.createFreshU(100000000, ownerKeys); stepaU.check(); //stepaU.setIsU(true); stepaU.traceErrors(); node.registerItem(stepaU); ItemResult itemResult = node.waitItem(stepaU.getId(), 18000); assertEquals(ItemState.APPROVED, itemResult.state); return ContractsService.createParcel(c, stepaU, 150, keys); }
@Test(timeout = 20000) public void checkPayment_revision1() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); final Field field = payment.getState().getClass().getDeclaredField("revision"); field.setAccessible(true); field.set(payment.getState(), 1); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test(timeout = 90000) public void checkPayment_originMismatch() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); final Field field2 = payment.getRevoking().get(0).getState().getClass().getDeclaredField("origin"); field2.setAccessible(true); field2.set(payment.getRevoking().get(0).getState(), payment.getId()); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
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 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(timeout = 90000) public void checkPayment_good() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertTrue(res); }
@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()); }
protected void sealCheckTrace(Contract c, boolean isOk) { c.seal(); try { c.check(); } catch (Quantiser.QuantiserException e) { e.printStackTrace(); } c.traceErrors(); if (isOk) assertTrue(c.isOk()); else assertFalse(c.isOk()); }
protected static void sealCheckTrace(Contract c, boolean isOk) { c.seal(); try { c.check(); } catch (Quantiser.QuantiserException e) { e.printStackTrace(); } c.traceErrors(); if (isOk) assertTrue(c.isOk()); else assertFalse(c.isOk()); }
@Test(timeout = 90000) public void checkPayment_wrongUtype() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getStateData().set("transaction_units", "33"); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test(timeout = 90000) public void checkPayment_missingDecrementPermission() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getPermissions().remove("decrement_permission"); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test(timeout = 90000) public void checkPayment_minusU() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getStateData().set("transaction_units", -1); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@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(timeout = 90000) public void checkPayment_wrongUname() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getStateData().set("transaction_units", payment.getStateData().get("transaction_units")); payment.getStateData().remove("transaction_units"); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test(timeout = 90000) public void checkPayment_wrongIssuer() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); PrivateKey manufactureFakePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")); SimpleRole issuerRole = new SimpleRole("issuer"); KeyRecord kr = new KeyRecord(manufactureFakePrivateKey.getPublicKey()); issuerRole.addKeyRecord(kr); payment.registerRole(issuerRole); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@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); }