use of com.icodici.universa.contract.roles.SimpleRole in project universa by UniversaBlockchain.
the class MainTest method createNetConfigContract.
private Contract createNetConfigContract(List<NodeInfo> netConfig, PrivateKey issuerKey) throws IOException {
Contract contract = new Contract();
contract.setIssuerKeys(issuerKey.getPublicKey());
contract.registerRole(new RoleLink("creator", "issuer"));
ListRole listRole = new ListRole("owner");
for (NodeInfo ni : netConfig) {
SimpleRole role = new SimpleRole(ni.getName());
contract.registerRole(role);
role.addKeyRecord(new KeyRecord(ni.getPublicKey()));
listRole.addRole(role);
}
listRole.setQuorum(netConfig.size() - 1);
contract.registerRole(listRole);
RoleLink ownerLink = new RoleLink("ownerlink", "owner");
ChangeOwnerPermission changeOwnerPermission = new ChangeOwnerPermission(ownerLink);
HashMap<String, Object> fieldsMap = new HashMap<>();
fieldsMap.put("net_config", null);
Binder modifyDataParams = Binder.of("fields", fieldsMap);
ModifyDataPermission modifyDataPermission = new ModifyDataPermission(ownerLink, modifyDataParams);
contract.addPermission(changeOwnerPermission);
contract.addPermission(modifyDataPermission);
contract.setExpiresAt(ZonedDateTime.now().plusYears(40));
contract.getStateData().set("net_config", netConfig);
contract.addSignerKey(issuerKey);
contract.seal();
return contract;
}
use of com.icodici.universa.contract.roles.SimpleRole in project universa by UniversaBlockchain.
the class MainTest method createNetConfigContract.
private Contract createNetConfigContract(Contract contract, List<NodeInfo> netConfig, Collection<PrivateKey> currentConfigKeys) throws IOException {
contract = contract.createRevision();
ListRole listRole = new ListRole("owner");
for (NodeInfo ni : netConfig) {
SimpleRole role = new SimpleRole(ni.getName());
contract.registerRole(role);
role.addKeyRecord(new KeyRecord(ni.getPublicKey()));
listRole.addRole(role);
}
listRole.setQuorum(netConfig.size() - 1);
contract.registerRole(listRole);
contract.getStateData().set("net_config", netConfig);
List<KeyRecord> creatorKeys = new ArrayList<>();
for (PrivateKey key : currentConfigKeys) {
creatorKeys.add(new KeyRecord(key.getPublicKey()));
contract.addSignerKey(key);
}
contract.setCreator(creatorKeys);
contract.seal();
return contract;
}
use of com.icodici.universa.contract.roles.SimpleRole in project universa by UniversaBlockchain.
the class ContractsServiceTest method goodRevoke.
@Test
public void goodRevoke() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey()));
c.seal();
Contract revokeContract = c.createRevocation(goodKey);
assertTrue(revokeContract.check());
// tc.traceErrors();
}
use of com.icodici.universa.contract.roles.SimpleRole in project universa by UniversaBlockchain.
the class BaseNetworkTest method checkPayment_wrongIssuer.
@Test(timeout = 90000)
public void checkPayment_wrongIssuer() throws Exception {
Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
PrivateKey manufactureFakePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey"));
SimpleRole issuerRole = new SimpleRole("issuer");
KeyRecord kr = new KeyRecord(manufactureFakePrivateKey.getPublicKey());
issuerRole.addKeyRecord(kr);
payment.registerRole(issuerRole);
boolean res = payment.paymentCheck(config.getTransactionUnitsIssuerKey());
payment.traceErrors();
assertFalse(res);
}
use of com.icodici.universa.contract.roles.SimpleRole in project universa by UniversaBlockchain.
the class BaseNetworkTest method referenceForChangeOwnerWithCreateContract.
@Test
public void referenceForChangeOwnerWithCreateContract() throws Exception {
// manager -
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
// issuer
Set<PrivateKey> llcPrivateKeys = new HashSet<>();
Set<PrivateKey> thirdPartyPrivateKeys = new HashSet<>();
llcPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
thirdPartyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
Set<PublicKey> stepaPublicKeys = new HashSet<>();
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Set<PublicKey> thirdPartyPublicKeys = new HashSet<>();
for (PrivateKey pk : thirdPartyPrivateKeys) {
thirdPartyPublicKeys.add(pk.getPublicKey());
}
Contract jobCertificate = new Contract(llcPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys);
jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita");
jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
Contract llcProperty = ContractsService.createNotaryContract(llcPrivateKeys, stepaPublicKeys);
List<String> listConditions = new ArrayList<>();
listConditions.add("ref.definition.issuer == \"26RzRJDLqze3P5Z1AzpnucF75RLi1oa6jqBaDh8MJ3XmTaUoF8R\"");
listConditions.add("ref.definition.data.issuer == \"Roga & Kopita\"");
listConditions.add("ref.definition.data.type == \"chief accountant assignment\"");
Reference reference = new Reference(llcProperty);
reference.name = "certification_contract";
reference.type = Reference.TYPE_EXISTING;
Binder conditions = new Binder();
conditions.set("all_of", listConditions);
reference.setConditions(conditions);
reference.addMatchingItem(jobCertificate);
// llcProperty.getDefinition().getReferences().add(reference);
llcProperty.addReference(reference);
ListRole listRole = new ListRole("list_role");
SimpleRole ownerRole = new SimpleRole("owner", stepaPrivateKeys);
listRole.addRole(ownerRole);
listRole.addRequiredReference("certification_contract", Role.RequiredMode.ALL_OF);
llcProperty.getPermissions().remove("change_owner");
llcProperty.getPermissions().remove("revoke");
ChangeOwnerPermission changeOwnerPerm = new ChangeOwnerPermission(listRole);
llcProperty.addPermission(changeOwnerPerm);
RevokePermission revokePerm = new RevokePermission(listRole);
llcProperty.addPermission(revokePerm);
llcProperty.addSignerKey(llcPrivateKeys.iterator().next());
llcProperty.seal();
registerAndCheckApproved(llcProperty);
Contract llcProperty2 = llcProperty.createRevision(stepaPrivateKeys);
llcProperty2.setOwnerKeys(thirdPartyPublicKeys);
llcProperty2.seal();
llcProperty2.check();
llcProperty2.traceErrors();
assertFalse(llcProperty2.isOk());
TransactionPack tp_before = llcProperty2.getTransactionPack();
// tp_before.addReferencedItem(jobCertificate);
byte[] data = tp_before.pack();
TransactionPack tp_after = TransactionPack.unpack(data);
registerAndCheckApproved(tp_after);
}
Aggregations