use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferAmountFromCoupleContracts.
@Test
public void shouldTransferAmountFromCoupleContracts() throws Exception {
Decimal valueToSend = new Decimal(70);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(50, 45));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(2, wallets.get(0).getContracts().size());
// gonna send 70 but I have 2 contracts (50, 45)
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
assertEquals(1, wallet.getContracts().size());
sealCheckTrace(contract, true);
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferSumOf7.
@Test
public void shouldTransferSumOf7() throws Exception {
Decimal valueToSend = new Decimal(280);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(12, wallets.get(0).getContracts().size());
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contract, true);
assertEquals(6, wallet.getContracts().size());
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferTheSameValue.
@Test
public void shouldTransferTheSameValue() throws Exception {
Decimal valueToSend = new Decimal(5);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(5));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(1, wallets.get(0).getContracts().size());
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contract, true);
assertEquals(0, wallet.getContracts().size());
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method splitJoinHasTwoDifferentCoinTypes.
@Test
public void splitJoinHasTwoDifferentCoinTypes() throws Exception {
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);
// set wrong revoking with the same amount
root = root.createRevision(ownerKey2);
root.seal();
Contract cr50 = createCoinWithAmount("50", FIELD_NAME);
// coin amount: 200 (revoking: 100 and 50 and 50 another different coin)
root.getStateData().set(FIELD_NAME, new Decimal(200));
root.addRevokingItems(c50_1);
root.addRevokingItems(cr50);
sealCheckTrace(root, false);
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class CLIMainTest method calculateContractProcessingCostFromBinary.
@Test
public void calculateContractProcessingCostFromBinary() throws Exception {
// Should use a binary contract, call -cost command and print cost of processing it.
Contract contract = createCoin();
contract.getStateData().set(FIELD_NAME, new Decimal(100));
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
contract.seal();
// sealCheckTrace(contract, true);
CLIMain.saveContract(contract, basePath + "contract_for_cost.unicon");
System.out.println("--- cost checking ---");
// Check 4096 bits signature (8) +
// Register a version (20)
int costShouldBe = (int) Math.floor(28 / Quantiser.quantaPerUTN) + 1;
callMain("--cost", basePath + "contract_for_cost.unicon");
System.out.println(output);
assertTrue(output.indexOf("Contract processing cost is " + costShouldBe + " TU") >= 0);
}
Aggregations