Search in sources :

Example 11 with Decimal

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));
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) TransactionPack(com.icodici.universa.contract.TransactionPack) Test(org.junit.Test)

Example 12 with Decimal

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));
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) TransactionPack(com.icodici.universa.contract.TransactionPack) Test(org.junit.Test)

Example 13 with Decimal

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));
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) TransactionPack(com.icodici.universa.contract.TransactionPack) Test(org.junit.Test)

Example 14 with Decimal

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);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 15 with Decimal

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);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Aggregations

Decimal (com.icodici.universa.Decimal)41 Contract (com.icodici.universa.contract.Contract)31 Test (org.junit.Test)30 Binder (net.sergeych.tools.Binder)7 TransactionPack (com.icodici.universa.contract.TransactionPack)5 PrivateKey (com.icodici.crypto.PrivateKey)4 Approvable (com.icodici.universa.Approvable)3 PublicKey (com.icodici.crypto.PublicKey)2 HashId (com.icodici.universa.HashId)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Permission (com.icodici.universa.contract.permissions.Permission)1 SplitJoinPermission (com.icodici.universa.contract.permissions.SplitJoinPermission)1 Quantiser (com.icodici.universa.node2.Quantiser)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1