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);
}
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());
}
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);
}
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());
}
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;
}
Aggregations