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()))));
}
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");
}
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));
}
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());
}
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");
}
Aggregations