Search in sources :

Example 16 with Decimal

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

the class CLIMainTest method registerContractWithDefaultPayment.

@Test
public void registerContractWithDefaultPayment() 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();
    CLIMain.saveContract(contract, basePath + "contract_for_register_and_cost.unicon");
    System.out.println("--- get tu ---");
    String tuContract = getApprovedTUContract();
    Contract tu = CLIMain.loadContract(tuContract);
    System.out.println("check tu " + tu.getId().toBase64String());
    callMain2("--probe", tu.getId().toBase64String(), "--verbose");
    LogPrinter.showDebug(true);
    System.out.println("--- registering contract (with processing cost print) ---");
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--tu", tuContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "-wait", "5000");
    System.out.println(output);
    assertTrue(output.indexOf("paid contract " + contract.getId() + " submitted with result: ItemResult<APPROVED") >= 0);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 17 with Decimal

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

the class CLIMainTest method packContractWithCounterParts.

@Test
public void packContractWithCounterParts() throws Exception {
    String contractFileName = basePath + "coin1000.unicon";
    Contract contract = createCoin();
    contract.getStateData().set(FIELD_NAME, new Decimal(1000));
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    contract.seal();
    CLIMain.saveContract(contract, contractFileName);
    callMain2("--check", contractFileName, "-v");
    callMain2("-pack-with", contractFileName, "-add-sibling", basePath + "packedContract_new_item.unicon", "-add-revoke", basePath + "packedContract_revoke.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey", "-v");
    callMain("--check", contractFileName, "-v");
    System.out.println(output);
// assertEquals(0, errors.size());
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 18 with Decimal

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

the class CLIMainTest method registerContractWithPayment.

@Test
public void registerContractWithPayment() 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();
    CLIMain.saveContract(contract, basePath + "contract_for_register_and_cost.unicon");
    System.out.println("--- get tu ---");
    String tuContract = getApprovedTUContract();
    System.out.println("--- registering contract (with processing cost print) ---");
    LogPrinter.showDebug(true);
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--tu", tuContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "-amount", "2", "-wait", "5000");
    System.out.println(output);
    assertTrue(output.indexOf("registering the paid contract " + contract.getId() + " from " + basePath + "contract_for_register_and_cost.unicon" + " for 2 TU") >= 0);
    assertTrue(output.indexOf("paid contract " + contract.getId() + " submitted with result: ItemResult<APPROVED") >= 0);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 19 with Decimal

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

the class CLIMainTest method packContractWithCounterPartsWithName.

@Test
public void packContractWithCounterPartsWithName() throws Exception {
    String contractFileName = basePath + "coin100.unicon";
    String savingFileName = basePath + "packed.unicon";
    Contract contract = createCoin();
    contract.getStateData().set(FIELD_NAME, new Decimal(100));
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    contract.seal();
    CLIMain.saveContract(contract, contractFileName);
    callMain2("--check", contractFileName, "-v");
    callMain2("-pack-with", contractFileName, "-add-sibling", basePath + "contract2.unicon", "-add-revoke", basePath + "contract_for_revoke1.unicon", "-name", savingFileName, "-v");
    callMain("--check", savingFileName, "-v");
    System.out.println(output);
// assertEquals(0, errors.size());
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 20 with Decimal

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

the class SplitJoinPermission method checkSplitJoinCase.

private boolean checkSplitJoinCase(Contract changed) {
    Decimal splitJoinSum = Decimal.ZERO;
    for (Contract c : changed.getSiblings()) {
        splitJoinSum = splitJoinSum.add(new Decimal(c.getStateData().getString(fieldName)));
    }
    Decimal rSum = Decimal.ZERO;
    for (Approvable r : changed.getRevokingItems()) {
        if (r instanceof Contract) {
            Contract c = (Contract) r;
            if (!isMergeable(c) || !validateMergeFields(changed, c))
                return false;
            rSum = rSum.add(new Decimal(((Contract) r).getStateData().getString(fieldName)));
        }
    }
    return splitJoinSum.compareTo(rSum) == 0;
}
Also used : Decimal(com.icodici.universa.Decimal) Approvable(com.icodici.universa.Approvable) 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