/** * Create new revision to be changed, signed sealed and then ready to approve. Created "revision" contract is a copy * of this contract, with all fields and references correctly set. After this call one need to change mutable * fields, add signing keys, seal it and then apss to Universa network for approval. * * @param keys initially added and signer keys. Role "creator" is set to these keys for new revision * @return new revision of this contract, identical to this one, to be modified. */ public synchronized Contract createRevision(Collection<PrivateKey> keys) { return createRevision(keys, null); }
/** * Create new revision to be changed, signed sealed and then ready to approve. Created "revision" contract is a copy * of this contract, with all fields and references correctly set. After this call one need to change mutable * fields, add signing keys, seal it and then apss to Universa network for approval. * * @param keys initially added and signer keys. Role "creator" is set to these keys for new revision * @return new revision of this contract, identical to this one, to be modified. */ public Contract createRevision(PrivateKey... keys) { return createRevision(null, keys); }
/** * Create new revision to be changed, signed sealed and then ready to approve. Created "revision" contract is a copy * of this contract, with all fields and references correctly set. After this call one need to change mutable * fields, add signing keys, seal it and then apss to Universa network for approval. * * @return new revision of this contract, identical to this one, to be modified. */ public Contract createRevision() { return createRevision((Transactional)null); }
/** * Create new revision to be changed, signed sealed and then ready to approve. Created "revision" contract is a copy * of this contract, with all fields and references correctly set. After this call one need to change mutable * fields, add signing keys, seal it and then apss to Universa network for approval. * * @param keys initially added and signer keys. Role "creator" is set to these keys for new revision * @param transactional is {@link Transactional} section to create new revision with * @return new revision of this contract, identical to this one, to be modified. */ public Contract createRevision(Transactional transactional, PrivateKey... keys) { return createRevision(Do.list(keys), transactional); }
public JSApiContract createRevision() { return new JSApiContract(this.currentContract.createRevision()); }
public Contract createUnsPayment() throws IOException { PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")); Set<PublicKey> keys = new HashSet(); keys.add(ownerKey.getPublicKey()); Contract stepaU = InnerContractsService.createFreshU(100000000, keys); Contract paymentDecreased = stepaU.createRevision(ownerKey); paymentDecreased.getStateData().set("transaction_units", stepaU.getStateData().getIntOrThrow("transaction_units") - 2000); paymentDecreased.seal(); return paymentDecreased; } }
public Contract createSlotPayment() throws IOException { PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")); Set<PublicKey> keys = new HashSet(); keys.add(ownerKey.getPublicKey()); Contract stepaU = InnerContractsService.createFreshU(100000000, keys); Contract paymentDecreased = stepaU.createRevision(ownerKey); paymentDecreased.getStateData().set("transaction_units", stepaU.getStateData().getIntOrThrow("transaction_units") - 100); paymentDecreased.seal(); return paymentDecreased; } }
@Test public void shouldModifyStateDataValues() throws Exception { Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "An example of smart contract."; final String newValue = "UniversaSmartContract"; final String field = "description"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, true); }
@Test public void shouldModifyAnyValueForKey() throws Exception { Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "35"; final String newValue = "303434935245"; final String field = "units"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, true); }
@Test public void shouldPopulateWithEmptyStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "An example of smart contract."; final String newValue = ""; final String field = "description"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, true); }
@Test public void shouldModifyDescNullStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "An example of smart contract."; final String newValue = null; final String field = "description"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, true); }
@Test public void shouldNotModifyStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "1"; final String newValue = "2"; final String field = "option"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, false); }
@Test public void shouldNotPopulateWithNullStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "2"; final String newValue = null; final String field = "direction"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, false); }
@Test public void shouldNotPopulateWithEmptyStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "2"; final String newValue = ""; final String field = "direction"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, false); }
@Test public void shouldNotModifyDescEmptyStateDataValues() throws Exception { PrivateKey ownerKey2 = TestKeys.privateKey(1); Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2); Binder d = c.getStateData(); Contract c1 = c.createRevision(ownerKey2); Binder d1 = c1.getStateData(); final String oldValue = "An example of smart contract."; final String newValue = "wrong value."; final String field = "description"; setAndCheckOldNewValues(d, d1, oldValue, newValue, field); sealCheckTrace(c1, false); }
@Test public void splitLessThanMinValue() throws Exception { Contract root = createCoinWithAmount("200", FIELD_NAME); root = root.createRevision(); root.addSignerKeyFromFile(PRIVATE_KEY_PATH); Contract c1 = root.splitValue(FIELD_NAME, new Decimal("0.00001")); root.addSignerKey(ownerKey2); c1.addSignerKey(ownerKey2); sealCheckTrace(c1, false); sealCheckTrace(root, false); }
public TestContracts invoke() throws EncryptionError, Quantiser.QuantiserException { r0 = new Contract(TestKeys.privateKey(0)); r0.seal(); c = r0.createRevision(TestKeys.privateKey(0)); n0 = new Contract(TestKeys.privateKey(0)); n1 = new Contract(TestKeys.privateKey(0)); c.addNewItems(n0); c.addNewItems(n1); c.seal(); return this; } }
@Test public void cheatCreateValue2() throws Exception { Contract c = createCoin(); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); Binder d = c.getStateData(); int a = 1000000; assertEquals(a, d.getIntOrThrow(FIELD_NAME)); c.seal(); assertTrue(c.check()); Contract c1 = c.createRevision(ownerKey2); c1.getStateData().set(FIELD_NAME, "500.00000001"); sealCheckTrace(c1, false); }
@Test public void defaultParameters() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); contract.getStateData().put("field1", "33.000000000000000001"); ChangeNumberPermission changeNumberPermission = new ChangeNumberPermission(contract.getRole("owner"), Binder.of("field_name", "field1")); contract.addPermission(changeNumberPermission); contract.seal(); Contract changed = contract.createRevision(); changed.addSignerKey(TestKeys.privateKey(0)); changed.getStateData().set("field1", "33.000000000000000002"); changed.seal(); changed.check(); assertTrue(changed.isOk()); }
@Test public void modifyDataDeclined() 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()); contract.addPermission(modifyDataPermission); contract.seal(); Contract changed = contract.createRevision(); changed.addSignerKey(TestKeys.privateKey(0)); changed.getStateData().set("field_to_be_changed", "value2"); changed.seal(); changed.check(); assertTrue(!changed.isOk()); }