use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class PermissionsTest method shouldNotModifySeveralStateDataValues.
@Test
public void shouldNotModifySeveralStateDataValues() 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();
String oldValue = "An example of smart contract.";
String newValue = "UniversaSmartContract";
String field = "description";
setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
oldValue = "blockchain-partnership.";
newValue = "blockchain-universa.";
field = "partner_name";
setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
d1.addToInt("transactional_units_left", -50);
d1.addToInt("direction", 5);
d1.addToInt("option", -1);
sealCheckTrace(c1, false);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class PermissionsTest method revokeWithReference.
@Test
public void revokeWithReference() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
stepaPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")));
Set<PublicKey> stepaPublicKeys = new HashSet<>();
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Set<String> references = new HashSet<>();
references.add("certification_contract");
Contract c = Contract.fromDslFile(rootPath + "NotaryWithReferenceDSLTemplate.yml");
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
Role r = c.getPermissions().getFirst("revoke").getRole();
assertThat(r, is(instanceOf(ListRole.class)));
assertFalse(r.isAllowedFor(stepaPublicKeys, null));
assertTrue(r.isAllowedFor(stepaPublicKeys, references));
System.out.println("revoke permission :" + c.getPermissions().get("revoke"));
c.seal();
c.check();
c.traceErrors();
assertTrue(c.isOk());
assertEquals(c, (c.getPermissions().getFirst("revoke").getRole()).getContract());
// Bad contract change: owner has no right to change owner ;)
Contract c1 = c.createRevision(TestKeys.privateKey(0));
c1.setOwnerKey(ownerKey2);
assertNotEquals(c.getOwner(), c1.getOwner());
c1.seal();
c1.check();
c1.traceErrors();
assertEquals(1, c1.getErrors().size());
ErrorRecord error = c1.getErrors().get(0);
assertEquals(Errors.FORBIDDEN, error.getError());
// bad contract change: good key but bad reference
Contract c2 = ContractsService.createRevocation(c, stepaPrivateKeys.iterator().next());
assertEquals(c2.getRevoking().get(0), c2.getRevoking().get(0).getPermissions().getFirst("revoke").getRole().getContract());
c2.seal();
c2.check();
c2.traceErrors();
assertEquals(1, c2.getErrors().size());
error = c2.getErrors().get(0);
assertEquals(Errors.FORBIDDEN, error.getError());
// good contract change: creator is an owner
Contract c3 = ContractsService.createRevocation(c, stepaPrivateKeys.iterator().next());
Reference ref = new Reference();
ref.name = "certification_contract";
ref.type = Reference.TYPE_EXISTING;
ref.addMatchingItem(new Contract());
c3.getRevoking().get(0).getReferences().put(ref.name, ref);
// assertEquals(c3.getRevoking().get(0), c3.getPermissions().getFirst("revoke").getRole().getContract());
System.out.println("-------------");
sealCheckTrace(c3, true);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class PermissionsTest method shouldNotModifyStateDataValues.
@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);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class PermissionsTest method shouldPopulateWithEmptyStateDataValues.
@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);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class PermissionsTest method shouldNotModifyDescEmptyStateDataValues.
@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);
}
Aggregations