Search in sources :

Example 16 with Contract

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

the class ResearchTest method registerSimpleContract_getStateOnly.

@Test
public void registerSimpleContract_getStateOnly() throws Exception {
    Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
    Set<PublicKey> stepaPublicKeys = new HashSet<>();
    stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
    for (PrivateKey pk : stepaPrivateKeys) {
        stepaPublicKeys.add(pk.getPublicKey());
    }
    Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
    stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
    stepaCoins.seal();
    ItemResult itemResult = nodeClient.getState(stepaCoins.getId());
    System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
    assertEquals(ItemState.APPROVED, itemResult.state);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet)

Example 17 with Contract

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

the class SplitJoinPermissionTest method shouldNotSplitWithAnotherIssuerSerialize.

@Test
public void shouldNotSplitWithAnotherIssuerSerialize() throws Exception {
    Contract c = createCoin();
    c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    sealCheckTrace(c, true);
    Contract c2 = c.splitValue(FIELD_NAME, new Decimal(50));
    c2.setIssuerKeys(ownerKey1.getPublicKey());
    sealCheckTrace(c2, false);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 18 with Contract

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

the class SplitJoinPermissionTest method shouldNotSplitWithWrongCreatedBySerialize.

@Test
public void shouldNotSplitWithWrongCreatedBySerialize() throws Exception {
    Contract c = createCoin();
    c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    sealCheckTrace(c, true);
    Contract c2 = c.split(1)[0];
    sealCheckTrace(c2, true);
    Binder sd2 = DefaultBiMapper.serialize(c2);
    Binder state = (Binder) sd2.get("state");
    assertNotNull(state);
    assertTrue(state.size() > 0);
    state.set("createdBy", "other");
    Contract dc2 = DefaultBiMapper.deserialize(sd2);
    sealCheckTrace(dc2, false);
    state.set("createdBy", "owner");
    Contract dc3 = DefaultBiMapper.deserialize(sd2);
    sealCheckTrace(dc3, false);
    state.remove("createdBy");
    Contract dc4 = DefaultBiMapper.deserialize(sd2);
    sealCheckTrace(dc4, false);
}
Also used : Binder(net.sergeych.tools.Binder) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 19 with Contract

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

the class SplitJoinPermissionTest method cheatCreateValue2.

@Test
public void cheatCreateValue2() throws Exception {
    Contract c = createCoin();
    c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    Binder d = c.getStateData();
    int a = 1000000;
    assertEquals(a, d.getIntOrThrow(FIELD_NAME));
    c.seal();
    assertTrue(c.check());
    Contract c1 = c.createRevision(ownerKey2);
    c1.getStateData().set(FIELD_NAME, "500.00000001");
    sealCheckTrace(c1, false);
}
Also used : Binder(net.sergeych.tools.Binder) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 20 with Contract

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

the class SplitJoinPermissionTest method shouldNotJoinWithWrongAmount.

@Test
public void shouldNotJoinWithWrongAmount() throws Exception {
    int amount = 1000000;
    int v = 1;
    Contract c = createCoin();
    c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    sealCheckTrace(c, true);
    // Split with 1
    Contract c2 = c.splitValue(FIELD_NAME, new Decimal(v));
    assertEquals(amount - v, c.getStateData().getIntOrThrow(FIELD_NAME));
    assertEquals(v, c2.getStateData().getIntOrThrow(FIELD_NAME));
    sealCheckTrace(c2, true);
    Contract c3 = c.createRevision(ownerKey2);
    c3.getRevokingItems().add(c2);
    // Trying to hack the join and get bigger amount
    c3.getStateData().set(FIELD_NAME, new Decimal(v + 1));
    assertEquals(amount - v, c.getStateData().getIntOrThrow(FIELD_NAME));
    assertEquals(v + 1, c3.getStateData().getIntOrThrow(FIELD_NAME));
    sealCheckTrace(c3, false);
}
Also used : Decimal(com.icodici.universa.Decimal) 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