use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class ListRoleTest method serializeQuorum.
@Test
public void serializeQuorum() throws Exception {
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(1).getPublicKey()));
ListRole roleList = new ListRole("listAnyMode", 2, Do.listOf(s1, s2, s3));
Binder serialized = DefaultBiMapper.serialize(roleList);
Role r1 = DefaultBiMapper.deserialize(serialized);
assertEquals(r1, roleList);
}
use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class RoleReferencesTest method serializeBoth.
@Test
public void serializeBoth() throws Exception {
SimpleRole sr = new SimpleRole("tr1");
sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
sr.addRequiredReference("ref1", Role.RequiredMode.ALL_OF);
sr.addRequiredReference("ref2", Role.RequiredMode.ANY_OF);
Binder serialized = DefaultBiMapper.serialize(sr);
Role r1 = DefaultBiMapper.deserialize(serialized);
assertEquals(sr, r1);
assertEquals(r1.getReferences(Role.RequiredMode.ALL_OF).size(), 1);
assertEquals(r1.getReferences(Role.RequiredMode.ANY_OF).size(), 1);
assertEquals(r1.getReferences(Role.RequiredMode.ALL_OF).iterator().next(), "ref1");
assertEquals(r1.getReferences(Role.RequiredMode.ANY_OF).iterator().next(), "ref2");
}
use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class SimpleRoleTest method serializeOne.
@Test
public void serializeOne() throws Exception {
SimpleRole sr = new SimpleRole("tr1");
sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
sr.addRequiredReference("ref1", Role.RequiredMode.ALL_OF);
sr.addRequiredReference("ref2", Role.RequiredMode.ALL_OF);
sr.addRequiredReference("ref3", Role.RequiredMode.ANY_OF);
Binder serialized = DefaultBiMapper.serialize(sr);
Role r1 = DefaultBiMapper.deserialize(serialized);
assertEquals(sr, r1);
}
use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class SimpleRole method initWithDsl.
@Override
public void initWithDsl(Binder serializedRole) {
boolean keysFound = true;
boolean addressesFound = true;
boolean anonIdsFound = true;
if (serializedRole.containsKey("keys")) {
List<Binder> list = serializedRole.getListOrThrow("keys");
for (Object keyRecord : list) {
addKeyRecord(new KeyRecord(Binder.of(keyRecord)));
}
} else if (serializedRole.containsKey("key")) {
addKeyRecord(new KeyRecord(serializedRole));
} else {
keysFound = false;
}
if (serializedRole.containsKey("addresses")) {
List<Binder> list = serializedRole.getListOrThrow("addresses");
for (Object address : list) {
keyAddresses.add(new KeyAddress(Binder.of(address)));
}
} else if (serializedRole.containsKey("uaddress")) {
keyAddresses.add(new KeyAddress(serializedRole));
} else {
addressesFound = false;
}
if (serializedRole.containsKey("anonIds")) {
List<Binder> list = serializedRole.getListOrThrow("anonIds");
for (Object anonId : list) {
anonymousIds.add(new AnonymousId(Binder.of(anonId)));
}
} else if (serializedRole.containsKey("anonymousId")) {
anonymousIds.add(new AnonymousId(serializedRole));
} else {
anonIdsFound = false;
}
if (!addressesFound && !anonIdsFound && !keysFound) {
// TODO: ?????? "binders" were in old code
initWithRecords(serializedRole.getListOrThrow("binders"));
}
}
Aggregations