/** * Check matching fields of two contracts. * @param changed contract to check * @param c contract to check * @return true if all fields are matching, else false */ public boolean validateMergeFields(Contract changed, Contract c) { // check matching fields for (String name : mergeFields) { Object v1 = changed.get(name); Object v2 = c.get(name); if (!v1.equals(v2)) return false; } return true; }
contract.getRevoking().forEach(c -> { Decimal x; if(c.get(fieldName) != null) { x = new Decimal(c.get(fieldName).toString()); values.add(x); if (outcome.length() > 0) news.forEach(c -> { Decimal x; if(c.get(fieldName) != null) { if( c != contract ) outcome.append(" + "); x = new Decimal(c.get(fieldName).toString()); outcome.append(x.toString()); values.add(x.negate());
@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")); }
assertEquals(NSmartContract.SmartContractType.SLOT1.name(), smartContract.get("definition.extended_type"));
@Test public void goodSmartContractFromDSL() throws Exception { Contract smartContract = NSmartContract.fromDslFile(ROOT_PATH + "NotarySmartDSLTemplate.yml"); smartContract.addSignerKeyFromFile(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); registerAndCheckApproved(smartContract); ItemResult itemResult = node.waitItem(smartContract.getId(), 8000); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onCreatedResult").getString("status", null)); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onUpdateResult").getString("status", null)); }
@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); }
Object followerRoles = contract.get(section + ".data." + FOLLOWER_ROLES_FIELD_NAME); if (((followerRoles != null) && followerRoles instanceof Collection) && (((Collection)followerRoles).stream().anyMatch(r -> {
assertEquals(NSmartContract.SmartContractType.SLOT1.name(), smartContract.get("definition.extended_type"));
assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), smartContract.get("definition.extended_type"));
@Test public void goodNSmartContractFromDSL() throws Exception { Contract smartContract = NSmartContract.fromDslFile(ROOT_PATH + "NotaryNSmartDSLTemplate.yml"); smartContract.addSignerKeyFromFile(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); registerAndCheckApproved(smartContract); ItemResult itemResult = node.waitItem(smartContract.getId(), 8000); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onCreatedResult").getString("status", null)); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onUpdateResult").getString("status", null)); }
@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); }
right = rightOperandContract.get(rightOperand);
assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), smartContract.get("definition.extended_type"));
@Test public void goodNSmartContract() throws Exception { final PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey")); Contract smartContract = new NSmartContract(key); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); registerAndCheckApproved(smartContract); ItemResult itemResult = node.waitItem(smartContract.getId(), 8000); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onCreatedResult").getString("status", null)); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onUpdateResult").getString("status", null)); }
@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); }
@Test public void goodSmartContract() throws Exception { final PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey")); Contract smartContract = new NSmartContract(key); smartContract.seal(); smartContract.check(); smartContract.traceErrors(); assertTrue(smartContract.isOk()); assertTrue(smartContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type")); registerAndCheckApproved(smartContract); ItemResult itemResult = node.waitItem(smartContract.getId(), 8000); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onCreatedResult").getString("status", null)); // assertEquals("ok", itemResult.extraDataBinder.getBinder("onUpdateResult").getString("status", null)); }
@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 serializeNSmartContract() 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()); Binder b = BossBiMapper.serialize(smartContract); Contract desContract = DefaultBiMapper.deserialize(b); assertSameContracts(smartContract, desContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.get("definition.extended_type")); assertTrue(desContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); Contract copiedContract = smartContract.copy(); assertSameContracts(smartContract, copiedContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.get("definition.extended_type")); assertTrue(copiedContract instanceof NSmartContract); assertTrue(smartContract instanceof NContract); } }
@Test public void serializeSmartContract() 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()); Binder b = BossBiMapper.serialize(smartContract); Contract desContract = DefaultBiMapper.deserialize(b); assertSameContracts(smartContract, desContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.get("definition.extended_type")); assertTrue(desContract instanceof NSmartContract); assertTrue(desContract instanceof NContract); Contract copiedContract = smartContract.copy(); assertSameContracts(smartContract, copiedContract); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.get("definition.extended_type")); assertTrue(copiedContract instanceof NSmartContract); assertTrue(copiedContract instanceof NContract); } }