Search in sources :

Example 21 with KeyRecord

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);
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 22 with KeyRecord

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");
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 23 with KeyRecord

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);
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 24 with KeyRecord

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"));
    }
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) KeyAddress(com.icodici.crypto.KeyAddress) AnonymousId(com.icodici.universa.contract.AnonymousId)

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