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);
}
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));
}
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()))));
}
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"));
}
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);
}
Aggregations