use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method createRegisterTwoContractsCheckRevoke3.
@Test
public void createRegisterTwoContractsCheckRevoke3() 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 createCoin.
protected static Contract createCoin(String yamlFilePath) throws IOException {
Contract c = Contract.fromDslFile(yamlFilePath);
c.setOwnerKey(ownerKey2);
return c;
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method checkContractInPathRecursively.
@Test
public void checkContractInPathRecursively() throws Exception {
// Create contract files (coins and some non-coins)
File dirFile = new File(rootPath + "contract_subfolder/");
if (!dirFile.exists())
dirFile.mkdir();
dirFile = new File(rootPath + "contract_subfolder/contract_subfolder_level2/");
if (!dirFile.exists())
dirFile.mkdir();
List<Integer> coinValues = Arrays.asList(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(coinValues);
for (Contract coin : listOfCoinsWithAmount) {
int rnd = new Random().nextInt(2);
String dir = "";
switch(rnd) {
case 0:
dir += "contract_subfolder/";
break;
case 1:
dir += "contract_subfolder/contract_subfolder_level2/";
break;
}
CLIMain.saveContract(coin, rootPath + dir + "Coin_" + coin.getStateData().getIntOrThrow(FIELD_NAME) + ".unicon");
}
Contract nonCoin = Contract.fromDslFile("./src/test_files/simple_root_contract_v2.yml");
nonCoin.seal();
CLIMain.saveContract(nonCoin, rootPath + "contract_subfolder/NonCoin.unicon");
CLIMain.saveContract(nonCoin, rootPath + "contract_subfolder/contract_subfolder_level2/NonCoin.unicon");
// check contracts
callMain("-ch", rootPath, "-v", "-r");
System.out.println(output);
// assertEquals(5, errors.size());
// Clean up files
File[] filesToRemove = new File(rootPath + "contract_subfolder/").listFiles();
for (File file : filesToRemove) {
file.delete();
}
filesToRemove = new File(rootPath + "contract_subfolder/contract_subfolder_level2/").listFiles();
for (File file : filesToRemove) {
file.delete();
}
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method checkSessionReusing.
@Test
public void checkSessionReusing() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey()));
c.seal();
CLIMain.setVerboseMode(true);
Thread.sleep(1000);
CLIMain.clearSession();
System.out.println("---session cleared---");
CLIMain.registerContract(c);
Thread.sleep(1000);
CLIMain.setNodeUrl("http://localhost:8080");
System.out.println("---session should be reused from variable---");
CLIMain.registerContract(c);
CLIMain.saveSession();
Thread.sleep(1000);
CLIMain.clearSession(false);
CLIMain.setNodeUrl("http://localhost:8080");
System.out.println("---session should be reused from file---");
CLIMain.registerContract(c);
CLIMain.saveSession();
Thread.sleep(1000);
// CLIMain.clearSession(false);
//
// CLIMain.setNodeUrl(null);
//
// System.out.println("---session should be created for remote network---");
//
// CLIMain.registerContract(c);
//
// CLIMain.saveSession();
CLIMain.breakSession(-1);
Thread.sleep(2000);
CLIMain.clearSession(false);
CLIMain.setNodeUrl("http://localhost:8080");
System.out.println("---broken session should be recreated---");
CLIMain.registerContract(c);
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method createRegisterTwoContractsCheckRevoke2.
@Test
public void createRegisterTwoContractsCheckRevoke2() 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", contractFileName + "," + contractFileName2, "--verbose");
}
Aggregations