Search in sources :

Example 96 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class CLIMainTest method anonymizeRoleForTwoContractsWithNames.

@Test
public void anonymizeRoleForTwoContractsWithNames() 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", "-role", "issuer", "-name", basePath + "myAnon1.unicon", "-name", basePath + "myAnon2.unicon");
    assertTrue(new File(basePath + "myAnon1.unicon").exists());
    assertTrue(new File(basePath + "myAnon2.unicon").exists());
    System.out.println(output);
    PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract contract1 = CLIMain.loadContract(basePath + "myAnon1.unicon", true);
    assertFalse(contract1.getIssuer().getKeys().contains(key.getPublicKey()));
    Contract anonPublishedContract1 = new Contract(contract1.getLastSealedBinary());
    assertFalse(anonPublishedContract1.getIssuer().getKeys().contains(key.getPublicKey()));
    assertFalse(anonPublishedContract1.getSealedByKeys().contains(key.getPublicKey()));
    Contract contract2 = CLIMain.loadContract(basePath + "myAnon2.unicon", true);
    assertFalse(contract2.getIssuer().getKeys().contains(key.getPublicKey()));
    Contract anonPublishedContract2 = new Contract(contract2.getLastSealedBinary());
    assertFalse(anonPublishedContract2.getIssuer().getKeys().contains(key.getPublicKey()));
    assertFalse(anonPublishedContract2.getSealedByKeys().contains(key.getPublicKey()));
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 97 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class CLIMainTest method anonymizeRoleAndSaveWithName.

@Test
public void anonymizeRoleAndSaveWithName() throws Exception {
    callMain2("-create", rootPath + "TokenDSLTemplate.yml", "-name", basePath + "forRoleAnonymizing.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey");
    assertTrue(new File(basePath + "forRoleAnonymizing.unicon").exists());
    callMain("-anonymize", basePath + "forRoleAnonymizing.unicon", "-role", "issuer", "-name", basePath + "myAnon.unicon");
    assertTrue(new File(basePath + "myAnon.unicon").exists());
    System.out.println(output);
    PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract contract = CLIMain.loadContract(basePath + "myAnon.unicon", true);
    assertFalse(contract.getIssuer().getKeys().contains(key.getPublicKey()));
    Contract anonPublishedContract = new Contract(contract.getLastSealedBinary());
    assertFalse(anonPublishedContract.getIssuer().getKeys().contains(key.getPublicKey()));
    assertFalse(anonPublishedContract.getSealedByKeys().contains(key.getPublicKey()));
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 98 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class CLIMainTest method registerContractAndPrintProcessingCost.

@Test
public void registerContractAndPrintProcessingCost() 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();
    // sealCheckTrace(contract, true);
    CLIMain.saveContract(contract, basePath + "contract_for_register_and_cost.unicon");
    System.out.println("--- registering contract (with processing cost print) ---");
    // Check 4096 bits signature (8) +
    // Register a version (20)
    int costShouldBe = (int) Math.floor(28 / Quantiser.quantaPerUTN) + 1;
    callMain("--register", basePath + "contract_for_register_and_cost.unicon", "--cost");
    System.out.println(output);
    assertTrue(output.indexOf("Contract processing cost is " + costShouldBe + " TU") >= 0);
}
Also used : Decimal(com.icodici.universa.Decimal) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 99 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class CLIMainTest method createRegisterCheckRevoke.

@Test
public void createRegisterCheckRevoke() throws Exception {
    String keyFileName = rootPath + "_xer0yfe2nn1xthc.private.unikey";
    String contractFileName = basePath + "contract7.unicon";
    callMain("-c", rootPath + "simple_root_contract_v2.yml", "-k", keyFileName, "-name", contractFileName);
    assertTrue(new File(contractFileName).exists());
    assertEquals(0, errors.size());
    Contract c = Contract.fromSealedFile(contractFileName);
    System.out.println(c.getId());
    // callMain2("--ch", contractFileName, "--verbose");
    callMain2("--register", contractFileName, "--verbose");
    for (int i = 0; i < 10; i++) {
        callMain2("--probe", c.getId().toBase64String());
        Thread.sleep(500);
    }
}
Also used : File(java.io.File) Contract(com.icodici.universa.contract.Contract) Test(org.junit.Test)

Example 100 with Contract

use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.

the class CLIMainTest method revokeContract.

@Test
public void revokeContract() throws Exception {
    String contractFileName = basePath + "contract_for_revoke3.unicon";
    String tuContract = getApprovedTUContract();
    callMain2("--register", contractFileName, "--verbose", "--tu", tuContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey");
    Contract c = CLIMain.loadContract(contractFileName);
    System.out.println("contract: " + c.getId().toBase64String());
    Thread.sleep(1500);
    System.out.println("probe before revoke");
    callMain2("--probe", c.getId().toBase64String(), "--verbose");
    Thread.sleep(500);
    tuContract = getApprovedTUContract();
    callMain2("-revoke", contractFileName, "-k", PRIVATE_KEY_PATH, "-v", "--tu", tuContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey");
    Thread.sleep(2500);
    System.out.println("probe after revoke");
    callMain("--probe", c.getId().toBase64String(), "--verbose");
    System.out.println(output);
    assertEquals(0, errors.size());
    assertTrue(output.indexOf(ItemState.REVOKED.name()) >= 0);
}
Also used : 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