Search in sources :

Example 21 with Binder

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

the class PermissionsTest method shouldNotModifyDescEmptyStateDataValues.

@Test
public void shouldNotModifyDescEmptyStateDataValues() throws Exception {
    PrivateKey ownerKey2 = TestKeys.privateKey(1);
    Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
    Binder d = c.getStateData();
    Contract c1 = c.createRevision(ownerKey2);
    Binder d1 = c1.getStateData();
    final String oldValue = "An example of smart contract.";
    final String newValue = "wrong value.";
    final String field = "description";
    setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
    sealCheckTrace(c1, false);
}
Also used : Binder(net.sergeych.tools.Binder) PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 22 with Binder

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

the class PermissionsTest method shouldModifySeveralStateDataValues.

@Test
public void shouldModifySeveralStateDataValues() throws Exception {
    PrivateKey ownerKey2 = TestKeys.privateKey(1);
    Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
    Binder d = c.getStateData();
    Contract c1 = c.createRevision(ownerKey2);
    Binder d1 = c1.getStateData();
    String oldValue = "An example of smart contract.";
    String newValue = "UniversaSmartContract";
    String field = "description";
    setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
    oldValue = "blockchain-partnership.";
    newValue = "blockchain-universa.";
    field = "partner_name";
    setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
    d1.addToInt("direction", 3);
    sealCheckTrace(c1, true);
}
Also used : Binder(net.sergeych.tools.Binder) PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 23 with Binder

use of net.sergeych.tools.Binder 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 24 with Binder

use of net.sergeych.tools.Binder 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 25 with Binder

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

the class SplitJoinPermissionTest method testProperSum.

@Test
public void testProperSum() throws Exception {
    Contract c = createCoin();
    c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    Binder d = c.getStateData();
    int a = 1000000;
    assertEquals(a, d.getIntOrThrow(FIELD_NAME));
    sealCheckTrace(c, true);
    // bad split: no changes
    Contract c1 = c.createRevision(ownerKey2);
    sealCheckTrace(c1, false);
    // Good split
    Contract c2 = c1.splitValue(FIELD_NAME, new Decimal(500));
    assertEquals(a - 500, c1.getStateData().getIntOrThrow(FIELD_NAME));
    assertEquals(500, c2.getStateData().getIntOrThrow(FIELD_NAME));
    c1.getErrors().clear();
    sealCheckTrace(c1, true);
    // and it should be the same after seriazling to the transaction pack
    TransactionPack tp = new TransactionPack(c1);
    // tp.trace();
    TransactionPack tp2 = TransactionPack.unpack(new TransactionPack(c1).pack());
    // tp2.trace();
    Contract restored = tp2.getContract();
    restored.check();
    restored.traceErrors();
    assertTrue(restored.isOk());
// TODO: check that value can't be just changed
// TODO: check that the sum must be equal
// TODO: check children have different branches
// TODO: check smae branch spoofing
}
Also used : Binder(net.sergeych.tools.Binder) Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) TransactionPack(com.icodici.universa.contract.TransactionPack) 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