use of com.icodici.universa.Decimal 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.Decimal 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);
}
use of com.icodici.universa.Decimal 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.Decimal 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.Decimal in project universa by UniversaBlockchain.
the class WalletTest method shouldSplitAndMergeOne.
@Test
public void shouldSplitAndMergeOne() throws Exception {
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(100, 200));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
// want to send 250
Wallet wallet = wallets.get(0);
Contract output = wallet.buildContractWithValue("amount", new Decimal(250));
output.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(output, true);
Contract contract = wallet.getContracts().get(0);
sealCheckTrace(contract, true);
assertEquals("50", contract.getState().getData().get("amount"));
}
Aggregations