Search in sources :

Example 31 with Binder

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

the class ListRoleTest method serializeContractWithListRole.

@Test
public void serializeContractWithListRole() throws Exception {
    Contract c = Contract.fromDslFile("./src/test_contracts/simple_root_contract.yml");
    SimpleRole s1 = new SimpleRole("role");
    ListRole listRole = new ListRole("owner", 1, Do.listOf(s1));
    c.registerRole(listRole);
    Binder b = BossBiMapper.serialize(c);
    Contract c1 = DefaultBiMapper.deserialize(b);
    assertEquals(c.getRole("owner"), c1.getRole("owner"));
}
Also used : Binder(net.sergeych.tools.Binder) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 32 with Binder

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

the class ListRoleTest method serializeAny.

@Test
public void serializeAny() throws Exception {
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
    ListRole roleList = new ListRole("listAnyMode", ListRole.Mode.ANY, Do.listOf(s1, s2));
    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 33 with Binder

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

the class ListRoleTest method serializeAll.

@Test
public void serializeAll() throws Exception {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    s1.addRequiredReference("refName", Role.RequiredMode.ALL_OF);
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    ListRole roleList = new ListRole("listAllMode", ListRole.Mode.ALL, Do.listOf(s1));
    c.registerRole(s1);
    c.registerRole(roleList);
    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) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 34 with Binder

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

Example 35 with Binder

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