use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldNotSplitWithNegativeCount.
@Test
public void shouldNotSplitWithNegativeCount() throws Exception {
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(c, true);
try {
c.split(-1);
fail("Expected exception to be thrown.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().equalsIgnoreCase("split: count should be > 0"));
}
try {
c.split(0);
fail("Expected exception to be thrown.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().equalsIgnoreCase("split: count should be > 0"));
}
}
use of com.icodici.universa.contract.Contract 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
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldNotSplitWithWrongOriginSerialize.
@Test
public void shouldNotSplitWithWrongOriginSerialize() 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);
HashId origin = HashId.withDigest(Do.randomNegativeBytes(64));
Binder originB = DefaultBiMapper.serialize(origin);
state.set("origin", originB);
Contract dc2 = DefaultBiMapper.deserialize(sd2);
sealCheckTrace(dc2, false);
state.remove("origin");
Contract dc3 = DefaultBiMapper.deserialize(sd2);
sealCheckTrace(dc3, false);
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldSplitJoinHasEnoughSumRevoking.
@Test
public void shouldSplitJoinHasEnoughSumRevoking() throws Exception {
// 2 coins: 1st v: 50 (r: 50 and 50), 2nd v: 50 (r: 50 and 50)
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);
// good join
Contract finalC = c50_1.createRevision(ownerKey2);
finalC.seal();
finalC.getStateData().set(FIELD_NAME, new Decimal(100));
finalC.addRevokingItems(c50_1);
finalC.addRevokingItems(c1);
sealCheckTrace(finalC, true);
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class ResearchTest method registerSimpleContract.
@Test
public void registerSimpleContract() 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();
System.out.println("nodeClient.register(stepaCoins)...");
ItemResult itemResult = nodeClient.register(stepaCoins.getLastSealedBinary(), 5000);
System.out.println("nodeClient.register(stepaCoins)... done! itemResult: " + itemResult.state);
itemResult = nodeClient.getState(stepaCoins.getId());
System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
assertEquals(ItemState.APPROVED, itemResult.state);
}
Aggregations