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