Search in sources :

Example 1 with SimpleRole

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;
}
Also used : RoleLink(com.icodici.universa.contract.roles.RoleLink) ModifyDataPermission(com.icodici.universa.contract.permissions.ModifyDataPermission) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Binder(net.sergeych.tools.Binder) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) ChangeOwnerPermission(com.icodici.universa.contract.permissions.ChangeOwnerPermission) ListRole(com.icodici.universa.contract.roles.ListRole)

Example 2 with SimpleRole

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;
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) ListRole(com.icodici.universa.contract.roles.ListRole)

Example 3 with SimpleRole

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();
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Test(org.junit.Test)

Example 4 with SimpleRole

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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Test(org.junit.Test)

Example 5 with SimpleRole

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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Binder(net.sergeych.tools.Binder) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) ListRole(com.icodici.universa.contract.roles.ListRole) Test(org.junit.Test)

Aggregations

SimpleRole (com.icodici.universa.contract.roles.SimpleRole)23 PrivateKey (com.icodici.crypto.PrivateKey)22 Test (org.junit.Test)12 PublicKey (com.icodici.crypto.PublicKey)11 Binder (net.sergeych.tools.Binder)9 Contract (com.icodici.universa.contract.Contract)7 KeyRecord (com.icodici.universa.contract.KeyRecord)6 ListRole (com.icodici.universa.contract.roles.ListRole)6 ItemResult (com.icodici.universa.node.ItemResult)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 KeyAddress (com.icodici.crypto.KeyAddress)1 TransactionPack (com.icodici.universa.contract.TransactionPack)1 ChangeOwnerPermission (com.icodici.universa.contract.permissions.ChangeOwnerPermission)1 ModifyDataPermission (com.icodici.universa.contract.permissions.ModifyDataPermission)1 RoleLink (com.icodici.universa.contract.roles.RoleLink)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1