Search in sources :

Example 31 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class SplitJoinPermissionTest method splitJoinHasTwoDifferentCoinTypes.

@Test
public void splitJoinHasTwoDifferentCoinTypes() throws Exception {
    Contract root = createCoinWithAmount("200", FIELD_NAME);
    Contract c1 = root.splitValue(FIELD_NAME, new Decimal(100));
    sealCheckTrace(c1, true);
    // c1 split 50 50
    c1 = c1.createRevision(ownerKey2);
    c1.seal();
    Contract c50_1 = c1.splitValue(FIELD_NAME, new Decimal(50));
    sealCheckTrace(c50_1, true);
    // set wrong revoking with the same amount
    root = root.createRevision(ownerKey2);
    root.seal();
    Contract cr50 = createCoinWithAmount("50", FIELD_NAME);
    // coin amount: 200 (revoking: 100 and 50 and 50 another different coin)
    root.getStateData().set(FIELD_NAME, new Decimal(200));
    root.addRevokingItems(c50_1);
    root.addRevokingItems(cr50);
    sealCheckTrace(root, false);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 32 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class ListRoleTest method shouldNotPerformRoleWithAllMode.

@Test
public void shouldNotPerformRoleWithAllMode() {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    ListRole roleList = new ListRole("listAllMode", ListRole.Mode.ALL, Do.listOf(s1, s2));
    HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(1).getPublicKey()));
    assertFalse(roleList.isAllowedForKeys(keys));
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) AbstractKey(com.icodici.crypto.AbstractKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class ListRoleTest method shouldNotPerformRoleWithAnyMode.

@Test
public void shouldNotPerformRoleWithAnyMode() {
    Contract c = new Contract();
    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()));
    c.registerRole(s1);
    c.registerRole(s2);
    ListRole roleList = new ListRole("listAnyMode");
    roleList.setMode(ListRole.Mode.ANY);
    roleList.addRole(s1).addRole(s2);
    assertFalse(roleList.isAllowedForKeys(new HashSet<>(Do.listOf(keys.get(1).getPublicKey()))));
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with Contract

use of com.icodici.universa.contract.Contract 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 35 with Contract

use of com.icodici.universa.contract.Contract 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)

Aggregations

Contract (com.icodici.universa.contract.Contract)131 Test (org.junit.Test)67 Decimal (com.icodici.universa.Decimal)31 PrivateKey (com.icodici.crypto.PrivateKey)24 File (java.io.File)16 AsyncEvent (net.sergeych.tools.AsyncEvent)16 TimeoutException (java.util.concurrent.TimeoutException)14 Binder (net.sergeych.tools.Binder)14 KeyRecord (com.icodici.universa.contract.KeyRecord)13 HashSet (java.util.HashSet)9 Parcel (com.icodici.universa.contract.Parcel)8 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)7 Quantiser (com.icodici.universa.node2.Quantiser)7 PublicKey (com.icodici.crypto.PublicKey)6 TransactionPack (com.icodici.universa.contract.TransactionPack)6 IOException (java.io.IOException)6 BackingStoreException (java.util.prefs.BackingStoreException)6 OptionException (joptsimple.OptionException)6 HashId (com.icodici.universa.HashId)5 Arrays.asList (java.util.Arrays.asList)5