Search in sources :

Example 1 with KeyRecord

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

the class ListRoleTest method shouldNotPerformRoleWithAllMode.

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

Example 2 with KeyRecord

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

the class ListRoleTest method shouldNotPerformRoleWithAnyMode.

@Test
public void shouldNotPerformRoleWithAnyMode() {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    ListRole roleList = new ListRole("listAnyMode");
    roleList.setMode(ListRole.Mode.ANY);
    roleList.addRole(s1).addRole(s2);
    assertFalse(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 3 with KeyRecord

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

the class ListRoleTest method serializeAny.

@Test
public void serializeAny() throws Exception {
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
    ListRole roleList = new ListRole("listAnyMode", ListRole.Mode.ANY, Do.listOf(s1, s2));
    Binder serialized = DefaultBiMapper.serialize(roleList);
    Role r1 = DefaultBiMapper.deserialize(serialized);
    assertEquals(r1, roleList);
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 4 with KeyRecord

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

the class ListRoleTest method serializeAll.

@Test
public void serializeAll() throws Exception {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    s1.addRequiredReference("refName", Role.RequiredMode.ALL_OF);
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    ListRole roleList = new ListRole("listAllMode", ListRole.Mode.ALL, Do.listOf(s1));
    c.registerRole(s1);
    c.registerRole(roleList);
    Binder serialized = DefaultBiMapper.serialize(roleList);
    Role r1 = DefaultBiMapper.deserialize(serialized);
    assertEquals(r1, roleList);
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 5 with KeyRecord

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

the class ListRoleTest method shouldPerformRoleWithQuorumMode.

@Test
public void shouldPerformRoleWithQuorumMode() {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    SimpleRole s3 = new SimpleRole("owner3");
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
    s3.addKeyRecord(new KeyRecord(keys.get(3).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    c.registerRole(s3);
    ListRole roleList = new ListRole("listQuorumMode", 2, Do.listOf(s1, s3, s2));
    HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(0).getPublicKey(), ListRoleTest.keys.get(2).getPublicKey()));
    assertTrue(roleList.isAllowedForKeys(keys));
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) AbstractKey(com.icodici.crypto.AbstractKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet) 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