Search in sources :

Example 36 with Contract

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

the class ListRoleTest method shouldPerformRoleWithQuorumMode.

@Test
public void shouldPerformRoleWithQuorumMode() {
    Contract c = new Contract();
    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(3).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    c.registerRole(s3);
    ListRole roleList = new ListRole("listQuorumMode", 2, Do.listOf(s1, s3, s2));
    HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(0).getPublicKey(), ListRoleTest.keys.get(2).getPublicKey()));
    assertTrue(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 37 with Contract

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

the class ListRoleTest method shouldPerformRoleWithAnyMode.

@Test
public void shouldPerformRoleWithAnyMode() {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    SimpleRole s2 = new SimpleRole("owner2");
    s1.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
    s2.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
    c.registerRole(s1);
    c.registerRole(s2);
    ListRole roleList = new ListRole("listAnyMode", ListRole.Mode.ANY, Do.listOf(s1, s2));
    assertTrue(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 38 with Contract

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

the class RoleLinkTest method detectsCirculars.

@Test
public void detectsCirculars() throws Exception {
    Contract c = new Contract();
    RoleLink r1 = new RoleLink("bar", "foo");
    RoleLink r2 = new RoleLink("foo", "bar");
    c.registerRole(r1);
    c.registerRole(r2);
    assertNull(r2.resolve());
}
Also used : Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 39 with Contract

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

the class RoleLinkTest method resolve.

@Test
public void resolve() throws Exception {
    Contract c = new Contract();
    SimpleRole s1 = new SimpleRole("owner");
    c.registerRole(s1);
    RoleLink r1 = new RoleLink("lover", "owner");
    c.registerRole(r1);
    RoleLink r2 = r1.linkAs("mucker");
    assertSame(s1, s1.resolve());
    assertSame(s1, r1.resolve());
    assertSame(s1, r2.resolve());
}
Also used : Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 40 with Contract

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

the class CLIMain method revokeContract.

/**
 * Revoke specified contract and create a revocation transactional contract.
 *
 * @param contract
 *
 * @return Parcel - revoking transaction contract.
 */
public static Parcel revokeContract(Contract contract, Contract tu, int amount, Set<PrivateKey> tuKeys, boolean withTestPayment, PrivateKey... key) throws IOException {
    report("keys num: " + key.length);
    Contract tc = ContractsService.createRevocation(contract, key);
    Parcel parcel = registerContract(tc, tu, amount, tuKeys, withTestPayment, 0);
    return parcel;
}
Also used : Parcel(com.icodici.universa.contract.Parcel) Contract(com.icodici.universa.contract.Contract)

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