Search in sources :

Example 26 with Decimal

use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.

the class CLIMainTest method registerContractAndPrintProcessingCostBreakWhileUnpacking.

@Test
public void registerContractAndPrintProcessingCostBreakWhileUnpacking() throws Exception {
    // Should register contracts and use -cost as key to 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_register_and_cost.unicon");
    System.out.println("--- registering contract (with processing cost print) ---");
    // Check 4096 bits signature (8) +
    // Register a version (20)
    int costShouldBe = 28;
    Contract.setTestQuantaLimit(1);
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--cost");
    System.out.println(output);
    assertTrue(output.indexOf("ERROR: QUANTIZER_COST_LIMIT") >= 0);
    Contract.setTestQuantaLimit(-1);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 27 with Decimal

use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.

the class CLIMainTest method registerContractAndPrintProcessingCost.

@Test
public void registerContractAndPrintProcessingCost() throws Exception {
    // Should register contracts and use -cost as key to 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_register_and_cost.unicon");
    System.out.println("--- registering contract (with processing cost print) ---");
    // Check 4096 bits signature (8) +
    // Register a version (20)
    int costShouldBe = (int) Math.floor(28 / Quantiser.quantaPerUTN) + 1;
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--cost");
    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)

Example 28 with Decimal

use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.

the class CLIMainTest method registerManyContractAndPrintProcessingCost.

@Test
public void registerManyContractAndPrintProcessingCost() throws Exception {
    for (int i = 0; i < 2; i++) {
        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_register_and_cost" + i + ".unicon");
    }
    System.out.println("--- registering contract (with processing cost print) ---");
    // Check 4096 bits signature (8) +
    // Register a version (20)
    int costShouldBe = (int) Math.floor(28 / Quantiser.quantaPerUTN) + 1;
    callMain("--register", basePath + "contract_for_register_and_cost0.unicon", basePath + "contract_for_register_and_cost1.unicon", "--cost");
    System.out.println(output);
    assertTrue(output.indexOf("Contract processing cost is " + costShouldBe + " TU") >= 1);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 29 with Decimal

use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.

the class CLIMainTest method registerContractAndPrintProcessingCostBreak.

@Test
public void registerContractAndPrintProcessingCostBreak() throws Exception {
    // Should register contracts and use -cost as key to 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_register_and_cost.unicon");
    System.out.println("--- registering contract (with processing cost print) ---");
    // Check 4096 bits signature (8) +
    // Register a version (20)
    int costShouldBe = 28;
    Contract.setTestQuantaLimit(15);
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--cost");
    System.out.println(output);
    assertTrue(output.indexOf("ERROR: QUANTIZER_COST_LIMIT") >= 0);
    Contract.setTestQuantaLimit(-1);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 30 with Decimal

use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.

the class CLIMainTest method createListOfCoinsWithAmount.

private List<Contract> createListOfCoinsWithAmount(List<Integer> values) throws Exception {
    List<Contract> contracts = new ArrayList<>();
    for (Integer value : values) {
        Contract contract = createCoin();
        contract.getStateData().set(FIELD_NAME, new Decimal(value));
        contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
        contract.seal();
        sealCheckTrace(contract, true);
        contracts.add(contract);
    }
    return contracts;
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract)

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