use of com.icodici.universa.ErrorRecord in project universa by UniversaBlockchain.
the class ClientHTTPServer method itemResultOfError.
private ItemResult itemResultOfError(Errors error, String object, String message) {
Binder binder = new Binder();
binder.put("state", ItemState.UNDEFINED.name());
binder.put("haveCopy", false);
binder.put("createdAt", new Date());
binder.put("expiresAt", new Date());
ArrayList<ErrorRecord> errorRecords = new ArrayList<>();
errorRecords.add(new ErrorRecord(error, object, message));
binder.put("errors", errorRecords);
return new ItemResult(binder);
}
use of com.icodici.universa.ErrorRecord in project universa by UniversaBlockchain.
the class ContractTest method checkCreatingRootContract.
@Test
public void checkCreatingRootContract() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
boolean ok = c.check();
assertFalse(ok);
List<ErrorRecord> errors = c.getErrors();
// It is just ok but not signed
assertEquals(1, errors.size());
assertEquals(errors.get(0).getError(), Errors.NOT_SIGNED);
c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
c.getErrors().clear();
ok = c.check();
if (errors.isEmpty()) {
assertTrue(ok);
assertTrue(c.isOk());
} else {
for (ErrorRecord e : errors) {
System.out.println(e);
fail("errors in contract");
}
}
assertTrue(c.check());
Files.write(Paths.get(rootPath + "simple_root_contract.unc"), c.seal());
Yaml yaml = new Yaml();
Files.write(Paths.get(rootPath + "simple_root_contract.raw.yaml"), yaml.dump(DefaultBiMapper.serialize(c)).getBytes());
}
use of com.icodici.universa.ErrorRecord in project universa by UniversaBlockchain.
the class PermissionsTest method changeOwnerWithReference.
@Test
public void changeOwnerWithReference() 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("change_owner").getRole();
assertThat(r, is(instanceOf(ListRole.class)));
assertFalse(r.isAllowedFor(stepaPublicKeys, null));
assertTrue(r.isAllowedFor(stepaPublicKeys, references));
System.out.println("Owner now :" + c.getOwner());
System.out.println("change owner permission :" + c.getPermissions().get("change_owner"));
c.seal();
c.check();
c.traceErrors();
assertTrue(c.isOk());
assertEquals(c, (c.getPermissions().getFirst("change_owner").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 = c.createRevision(stepaPrivateKeys);
c2.setOwnerKey(ownerKey3);
assertEquals(c2, c2.getPermissions().getFirst("change_owner").getRole().getContract());
assertNotEquals(c.getOwner(), c2.getOwner());
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 = c.createRevision(stepaPrivateKeys);
c3.setOwnerKey(ownerKey3);
Reference ref = new Reference();
ref.name = "certification_contract";
ref.type = Reference.TYPE_EXISTING;
ref.addMatchingItem(new Contract());
c3.getReferences().put(ref.name, ref);
assertEquals(c3, c3.getPermissions().getFirst("change_owner").getRole().getContract());
assertNotEquals(c.getOwner(), c3.getOwner());
sealCheckTrace(c3, true);
}
Aggregations