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