private boolean checkContractCorrespondsToConfig(Contract contract, List<NodeInfo> netNodes) { //check if contract contains net config if(!checkIfContractContainsNetConfig(contract)) { return false; } //check if net config equals to current network configuration List<NodeInfo> contractNodes = DefaultBiMapper.getInstance().deserializeObject(contract.getStateData().get("net_config")); if(contractNodes.size() != netNodes.size() || !contractNodes.stream().allMatch(nodeInfo -> netNodes.contains(nodeInfo))) { return false; } return true; }
private Decimal getValue(Contract c, String fieldName) { return new Decimal(c.getStateData().getStringOrThrow(fieldName)); }
@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); }
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 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(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); }
private List<Contract> createListOfCoinsWithAmount(List<String> values) throws Exception { Contract money = createCoin(); money.getStateData().set(FIELD_NAME, new Decimal(100500)); money.addSignerKeyFromFile(PRIVATE_KEY_PATH); money.seal(); sealCheckTrace(money, true); List<Contract> res = new ArrayList<>(); for (String value : values) { Contract contract = ContractsService.createSplit(money, new BigDecimal(value), FIELD_NAME, new HashSet<PrivateKey>()); contract.addSignerKeyFromFile(PRIVATE_KEY_PATH); res.add(contract.getNew().get(0)); } return res; }
protected Contract createCoinWithAmount(String amount, String fieldName) throws Exception { Contract contract = createCoin(); contract.getStateData().set(fieldName, new Decimal(amount)); contract.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(contract, true); return contract; } }
@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(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_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 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()); }