use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method prepareRoot.
@BeforeClass
public static void prepareRoot() throws Exception {
createLocalNetwork();
ownerKey1 = TestKeys.privateKey(3);
ownerKey2 = TestKeys.privateKey(1);
ownerKey3 = TestKeys.privateKey(2);
// new File(rootPath + "/simple_root_contract.unicon").delete();
assertTrue(new File(rootPath + "/simple_root_contract.yml").exists());
assertTrue(new File(rootPath + "/simple_root_contract_v2.yml").exists());
CLIMain.setTestMode();
CLIMain.setTestRootPath(rootPath);
CLIMain.setNodeUrl("http://localhost:8080");
File file = new File(basePath);
if (!file.exists()) {
file.mkdir();
}
ZonedDateTime zdt = ZonedDateTime.now().plusHours(1);
String field = "definition.expires_at";
String value = "definition.expires_at:\n" + " seconds: " + zdt.toEpochSecond() + "\n" + " __type: unixtime";
callMain("-c", "-v", rootPath + "simple_root_contract_v2.yml", "-name", basePath + "contract1.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey", "-set", field, "-value", value);
callMain("-c", rootPath + "simple_root_contract_v2.yml", "-name", basePath + "contract2.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey", "-set", field, "-value", value);
callMain("-c", rootPath + "simple_root_contract_v2.yml", "-name", basePath + "contract3.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey", "-set", field, "-value", value);
callMain("-c", rootPath + "simple_root_contract_v2.yml", "-name", basePath + "contract_to_export.unicon", "-set", field, "-value", value);
Contract c1 = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c1.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey1 = c1.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c1.getRole("owner")).addKeyRecord(new KeyRecord(goodKey1.getPublicKey()));
c1.seal();
CLIMain.saveContract(c1, basePath + "contract_for_revoke1.unicon");
Contract c2 = Contract.fromDslFile(rootPath + "another_root_contract_v2.yml");
c2.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey2 = c2.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c2.getRole("owner")).addKeyRecord(new KeyRecord(goodKey2.getPublicKey()));
c2.seal();
CLIMain.saveContract(c2, basePath + "contract_for_revoke2.unicon");
Contract c3 = Contract.fromDslFile(rootPath + "simple_root_contract_v2.yml");
c3.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey3 = c3.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c3.getRole("owner")).addKeyRecord(new KeyRecord(goodKey3.getPublicKey()));
c3.seal();
CLIMain.saveContract(c3, basePath + "contract_for_revoke3.unicon");
callMain("-e", basePath + "contract1.unicon", "-name", basePath + "contract_to_import.json");
callMain("-e", basePath + "contract1.unicon", "-name", basePath + "contract_to_import.xml");
callMain("-e", basePath + "contract1.unicon", "-name", basePath + "contract_to_import.XML");
callMain("-e", basePath + "contract1.unicon", "-name", basePath + "contract_to_import.yaml");
callMain("-i", basePath + "contract_to_import.json", "-name", basePath + "not_signed_contract.unicon");
Path path = Paths.get(rootPath + "packedContract.unicon");
byte[] data = Files.readAllBytes(path);
Set<PrivateKey> keys = new HashSet<>();
keys.add(new PrivateKey(Do.read(PRIVATE_KEY_PATH)));
Contract contract = createCoin100apiv3();
contract.addSignerKey(keys.iterator().next());
contract.seal();
CLIMain.saveContract(contract, basePath + "packedContract.unicon");
callMain("--register", basePath + "packedContract.unicon", "--wait", "5000");
Contract packedContract = ContractsService.createSplit(contract, 1, FIELD_NAME, keys);
packedContract.addSignerKey(keys.iterator().next());
packedContract.seal();
CLIMain.saveContract(packedContract, basePath + "packedContract.unicon", true, true);
// try (FileOutputStream fs = new FileOutputStream(basePath + "packedContract.unicon")) {
// fs.write(data);
// fs.close();
// }
path = Paths.get(rootPath + "packedContract.unicon");
data = Files.readAllBytes(path);
try (FileOutputStream fs = new FileOutputStream(basePath + "packedContract2.unicon")) {
fs.write(data);
fs.close();
}
path = Paths.get(rootPath + "packedContract_new_item.unicon");
data = Files.readAllBytes(path);
try (FileOutputStream fs = new FileOutputStream(basePath + "packedContract_new_item.unicon")) {
fs.write(data);
fs.close();
}
path = Paths.get(rootPath + "packedContract_revoke.unicon");
data = Files.readAllBytes(path);
try (FileOutputStream fs = new FileOutputStream(basePath + "packedContract_revoke.unicon")) {
fs.write(data);
fs.close();
}
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method anonymizeAllRolesForTwoContracts.
@Test
public void anonymizeAllRolesForTwoContracts() throws Exception {
callMain2("-create", rootPath + "TokenDSLTemplate.yml", "-name", basePath + "forRoleAnonymizing1.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey");
callMain2("-create", rootPath + "TokenDSLTemplate.yml", "-name", basePath + "forRoleAnonymizing2.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey");
assertTrue(new File(basePath + "forRoleAnonymizing1.unicon").exists());
assertTrue(new File(basePath + "forRoleAnonymizing2.unicon").exists());
callMain("-anonymize", basePath + "forRoleAnonymizing1.unicon", basePath + "forRoleAnonymizing2.unicon");
assertTrue(new File(basePath + "forRoleAnonymizing1_anonymized.unicon").exists());
assertTrue(new File(basePath + "forRoleAnonymizing2_anonymized.unicon").exists());
System.out.println(output);
PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
Contract contract1 = CLIMain.loadContract(basePath + "forRoleAnonymizing1_anonymized.unicon", true);
assertFalse(contract1.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(contract1.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(contract1.getCreator().getKeys().contains(key.getPublicKey()));
Contract anonPublishedContract1 = new Contract(contract1.getLastSealedBinary());
assertFalse(anonPublishedContract1.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(anonPublishedContract1.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract1.getCreator().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract1.getSealedByKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract1.getSealedByKeys().contains(ownerKey.getPublicKey()));
Contract contract2 = CLIMain.loadContract(basePath + "forRoleAnonymizing1_anonymized.unicon", true);
assertFalse(contract2.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(contract2.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(contract2.getCreator().getKeys().contains(key.getPublicKey()));
Contract anonPublishedContract2 = new Contract(contract2.getLastSealedBinary());
assertFalse(anonPublishedContract2.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(anonPublishedContract2.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract2.getCreator().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract2.getSealedByKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract2.getSealedByKeys().contains(ownerKey.getPublicKey()));
}
use of com.icodici.universa.contract.Contract 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.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method createRegisterTwoContractsCheckRevoke4.
@Test
public void createRegisterTwoContractsCheckRevoke4() throws Exception {
String keyFileName = rootPath + "_xer0yfe2nn1xthc.private.unikey";
callMain("-c", rootPath + "simple_root_contract_v2.yml", "-k", keyFileName, "-name", basePath + "simple_root_contract_v2.unicon");
String contractFileName = basePath + "simple_root_contract_v2.unicon";
assertTrue(new File(contractFileName).exists());
assertEquals(0, errors.size());
callMain("-c", rootPath + "another_root_contract_v2.yml", "-k", keyFileName, "-name", basePath + "another_root_contract_v2.unicon");
String contractFileName2 = basePath + "another_root_contract_v2.unicon";
assertTrue(new File(contractFileName2).exists());
assertEquals(0, errors.size());
Contract c = Contract.fromSealedFile(contractFileName);
System.out.println("first contract: " + c.getId());
Contract c2 = Contract.fromSealedFile(contractFileName2);
System.out.println("second contract: " + c.getId());
callMain2("--register", "--verbose", contractFileName + "," + contractFileName2);
}
use of com.icodici.universa.contract.Contract 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);
}
Aggregations