Search in sources :

Example 1 with AbstractKey

use of com.icodici.crypto.AbstractKey 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 AbstractKey

use of com.icodici.crypto.AbstractKey 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)

Example 3 with AbstractKey

use of com.icodici.crypto.AbstractKey in project universa by UniversaBlockchain.

the class ListRoleTest method shouldNotPerformRoleWithQuorumMode.

@Test
public void shouldNotPerformRoleWithQuorumMode() {
    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("listQuorumMode");
    roleList.setQuorum(2);
    roleList.addAll(Do.listOf(s1, s2));
    c.registerRole(roleList);
    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 4 with AbstractKey

use of com.icodici.crypto.AbstractKey in project universa by UniversaBlockchain.

the class ListRoleTest method shouldPerformRoleWithAllMode.

@Test
public void shouldPerformRoleWithAllMode() {
    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");
    roleList.setMode(ListRole.Mode.ALL);
    roleList.addRole(s1).addRole(s2);
    HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(0).getPublicKey(), ListRoleTest.keys.get(1).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

AbstractKey (com.icodici.crypto.AbstractKey)4 Contract (com.icodici.universa.contract.Contract)4 KeyRecord (com.icodici.universa.contract.KeyRecord)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4