Search in sources :

Example 91 with Contract

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);
}
Also used : File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 92 with Contract

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;
}
Also used : Contract(com.icodici.universa.contract.Contract)

Example 93 with Contract

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();
    }
}
Also used : File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 94 with Contract

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);
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) PrivateKey(com.icodici.crypto.PrivateKey) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 95 with Contract

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");
}
Also used : File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Aggregations

Contract (com.icodici.universa.contract.Contract)131 Test (org.junit.Test)67 Decimal (com.icodici.universa.Decimal)31 PrivateKey (com.icodici.crypto.PrivateKey)24 File (java.io.File)16 AsyncEvent (net.sergeych.tools.AsyncEvent)16 TimeoutException (java.util.concurrent.TimeoutException)14 Binder (net.sergeych.tools.Binder)14 KeyRecord (com.icodici.universa.contract.KeyRecord)13 HashSet (java.util.HashSet)9 Parcel (com.icodici.universa.contract.Parcel)8 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)7 Quantiser (com.icodici.universa.node2.Quantiser)7 PublicKey (com.icodici.crypto.PublicKey)6 TransactionPack (com.icodici.universa.contract.TransactionPack)6 IOException (java.io.IOException)6 BackingStoreException (java.util.prefs.BackingStoreException)6 OptionException (joptsimple.OptionException)6 HashId (com.icodici.universa.HashId)5 Arrays.asList (java.util.Arrays.asList)5