Search in sources :

Example 81 with Binder

use of net.sergeych.tools.Binder 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 82 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class ListRoleTest method serializeWithMoreRoles.

@Test
public void serializeWithMoreRoles() {
    SimpleRole s1 = new SimpleRole("s1");
    SimpleRole s2 = new SimpleRole("s2");
    ListRole lr1 = new ListRole("lr1", ListRole.Mode.ALL, Do.listOf(s1, s2));
    ListRole lr2 = new ListRole("lr2", ListRole.Mode.ANY, Do.listOf(s1, s2));
    assertEquals(lr1.getRoles(), lr2.getRoles());
    Binder blr = BossBiMapper.serialize(lr1);
    ListRole slr1 = DefaultBiMapper.deserialize(blr);
    blr = BossBiMapper.serialize(lr1);
    ListRole slr2 = DefaultBiMapper.deserialize(blr);
    assertEquals(slr1.getRoles(), slr2.getRoles());
}
Also used : Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 83 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class RoleLinkTest method serialize.

@Test
public void serialize() throws Exception {
    RoleLink r1 = new RoleLink("name", "target");
    r1.addRequiredReference("ref", Role.RequiredMode.ALL_OF);
    Binder s = DefaultBiMapper.serialize(r1);
    RoleLink r2 = DefaultBiMapper.deserialize(s);
    assertEquals(r1, r2);
    assertEquals(r1.getName(), r2.getName());
}
Also used : Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 84 with Binder

use of net.sergeych.tools.Binder 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 85 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class YamlTest method createFromDsl.

@Test
public void createFromDsl() throws Exception {
    Yaml yaml = new Yaml();
    String fileName = rootPath + "simple_key.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getKeyRecords().size() == 1);
    }
    fileName = rootPath + "simple_keys.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getKeyRecords().size() == 2);
    }
    fileName = rootPath + "simple_no_type.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getKeyRecords().size() == 1);
    }
    fileName = rootPath + "simple_address.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getKeyAddresses().size() == 1);
    }
    fileName = rootPath + "simple_addresses.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getKeyAddresses().size() == 2);
    }
    fileName = rootPath + "simple_anonId.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getAnonymousIds().size() == 1);
    }
    fileName = rootPath + "simple_anonIds.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getAnonymousIds().size() == 2);
    }
    fileName = rootPath + "link.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof RoleLink);
    }
    fileName = rootPath + "list_all.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof ListRole);
    }
    fileName = rootPath + "list_any.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof ListRole);
    }
    fileName = rootPath + "list_quorum.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof ListRole);
    }
    fileName = rootPath + "simple_requires.yml";
    try (FileReader r = new FileReader(fileName)) {
        Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
        Role role = Role.fromDslBinder("role", binder);
        assertTrue(role instanceof SimpleRole);
        assertTrue(role.getReferences(Role.RequiredMode.ALL_OF).size() == 3);
        assertTrue(role.getReferences(Role.RequiredMode.ANY_OF).size() == 2);
    }
}
Also used : Binder(net.sergeych.tools.Binder) FileReader(java.io.FileReader) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Aggregations

Binder (net.sergeych.tools.Binder)136 Test (org.junit.Test)67 PrivateKey (com.icodici.crypto.PrivateKey)21 Contract (com.icodici.universa.contract.Contract)14 PublicKey (com.icodici.crypto.PublicKey)13 IOException (java.io.IOException)11 KeyRecord (com.icodici.universa.contract.KeyRecord)10 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)10 Yaml (org.yaml.snakeyaml.Yaml)9 Bytes (net.sergeych.utils.Bytes)8 Decimal (com.icodici.universa.Decimal)7 ListRole (com.icodici.universa.contract.roles.ListRole)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 XStream (com.thoughtworks.xstream.XStream)4 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)4 List (java.util.List)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)3 ItemResult (com.icodici.universa.node.ItemResult)3