Search in sources :

Example 6 with KeyRecord

use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.

the class ListRoleTest method shouldPerformRoleWithAnyMode.

@Test
public void shouldPerformRoleWithAnyMode() {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    ListRole roleList = new ListRole("listAnyMode", ListRole.Mode.ANY, Do.listOf(s1, s2));
    assertTrue(roleList.isAllowedForKeys(new HashSet<>(Do.listOf(keys.get(1).getPublicKey()))));
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with KeyRecord

use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.

the class RoleReferencesTest method serializeAll.

@Test
public void serializeAll() throws Exception {
    SimpleRole sr = new SimpleRole("tr1");
    sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    sr.addRequiredReference("ref", Role.RequiredMode.ALL_OF);
    Binder serialized = DefaultBiMapper.serialize(sr);
    Role r1 = DefaultBiMapper.deserialize(serialized);
    assertEquals(sr, r1);
    assertTrue(sr.getReferences(Role.RequiredMode.ANY_OF).isEmpty());
    assertEquals(sr.getReferences(Role.RequiredMode.ALL_OF).size(), 1);
    assertEquals(sr.getReferences(Role.RequiredMode.ALL_OF).iterator().next(), "ref");
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 8 with KeyRecord

use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.

the class RoleReferencesTest method isAllowed.

@Test
public void isAllowed() throws Exception {
    PublicKey key = keys.get(0).getPublicKey();
    Set<PublicKey> keySet = new HashSet<>();
    keySet.add(key);
    SimpleRole sr = new SimpleRole("tr1");
    sr.addKeyRecord(new KeyRecord(key));
    assertTrue(!sr.isAllowedForKeys(new HashSet<>()));
    assertTrue(sr.isAllowedForKeys(keySet));
    assertTrue(sr.isAllowedFor(keySet, new HashSet<>()));
    sr.addRequiredReference("ref1", Role.RequiredMode.ALL_OF);
    sr.addRequiredReference("ref2", Role.RequiredMode.ALL_OF);
    Set<String> allRef = new HashSet<>();
    allRef.add("ref1");
    assertTrue(!sr.isAllowedFor(keySet, allRef));
    allRef.add("ref2");
    assertTrue(sr.isAllowedFor(keySet, allRef));
    sr.addRequiredReference("ref3", Role.RequiredMode.ANY_OF);
    assertTrue(!sr.isAllowedFor(keySet, allRef));
    sr.addRequiredReference("ref4", Role.RequiredMode.ANY_OF);
    sr.addRequiredReference("ref5", Role.RequiredMode.ANY_OF);
    allRef.add("ref4");
    assertTrue(sr.isAllowedFor(keySet, allRef));
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) PublicKey(com.icodici.crypto.PublicKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with KeyRecord

use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.

the class RoleReferencesTest method serializeNone.

@Test
public void serializeNone() throws Exception {
    SimpleRole sr = new SimpleRole("tr1");
    sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    Binder serialized = DefaultBiMapper.serialize(sr);
    Role r1 = DefaultBiMapper.deserialize(serialized);
    assertEquals(sr, r1);
    assertTrue(r1.getReferences(Role.RequiredMode.ANY_OF).isEmpty());
    assertTrue(r1.getReferences(Role.RequiredMode.ALL_OF).isEmpty());
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 10 with KeyRecord

use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.

the class RoleReferencesTest method serializeAny.

@Test
public void serializeAny() throws Exception {
    SimpleRole sr = new SimpleRole("tr1");
    sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    sr.addRequiredReference("ref", Role.RequiredMode.ANY_OF);
    Binder serialized = DefaultBiMapper.serialize(sr);
    Role r1 = DefaultBiMapper.deserialize(serialized);
    assertEquals(sr, r1);
    assertTrue(sr.getReferences(Role.RequiredMode.ALL_OF).isEmpty());
    assertEquals(sr.getReferences(Role.RequiredMode.ANY_OF).size(), 1);
    assertEquals(sr.getReferences(Role.RequiredMode.ANY_OF).iterator().next(), "ref");
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Aggregations

KeyRecord (com.icodici.universa.contract.KeyRecord)24 Test (org.junit.Test)21 Contract (com.icodici.universa.contract.Contract)13 Binder (net.sergeych.tools.Binder)10 PrivateKey (com.icodici.crypto.PrivateKey)7 HashSet (java.util.HashSet)7 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)6 AbstractKey (com.icodici.crypto.AbstractKey)4 PublicKey (com.icodici.crypto.PublicKey)3 KeyAddress (com.icodici.crypto.KeyAddress)2 AnonymousId (com.icodici.universa.contract.AnonymousId)2 ItemResult (com.icodici.universa.node.ItemResult)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1 ZonedDateTime (java.time.ZonedDateTime)1 BeforeClass (org.junit.BeforeClass)1