use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method createRegisterTwoContractsCheckRevoke1.
@Test
public void createRegisterTwoContractsCheckRevoke1() 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");
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method revokeTwoContracts.
@Test
public void revokeTwoContracts() throws Exception {
String contractFileName1 = basePath + "contract_for_revoke1.unicon";
String contractFileName2 = basePath + "contract_for_revoke2.unicon";
System.out.println("---");
System.out.println("register contracts");
System.out.println("---");
String tuContract = getApprovedTUContract();
callMain2("--register", contractFileName1, contractFileName2, "--verbose", "--tu", tuContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey");
Thread.sleep(1500);
System.out.println("---");
System.out.println("check tu");
System.out.println("---");
tuContract = getApprovedTUContract();
Contract tu = CLIMain.loadContract(tuContract);
System.out.println("check tu " + tu.getId().toBase64String());
callMain2("--probe", tu.getId().toBase64String(), "--verbose");
System.out.println("---");
System.out.println("revoke contracts");
System.out.println("---");
callMain2("-revoke", contractFileName1, contractFileName2, "-v", "--tu", tuContract, "-k", rootPath + "keys/stepan_mamontov.private.unikey", "-k", PRIVATE_KEY_PATH);
Thread.sleep(1500);
System.out.println("---");
System.out.println("check contracts after revoke");
System.out.println("---");
Contract c1 = CLIMain.loadContract(contractFileName1);
callMain2("--probe", c1.getId().toBase64String(), "--verbose");
Contract c2 = CLIMain.loadContract(contractFileName2);
callMain("--probe", c2.getId().toBase64String(), "--verbose");
Contract tu2 = CLIMain.loadContract(tuContract);
System.out.println("check tu " + tu2.getId().toBase64String());
callMain2("--probe", tu2.getId().toBase64String(), "--verbose");
System.out.println(output);
assertEquals(0, errors.size());
assertTrue(output.indexOf(ItemState.REVOKED.name()) >= 1);
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method swapManyContractsViaTransactionAllGood.
// @Test
public void swapManyContractsViaTransactionAllGood() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
Contract delorean1 = Contract.fromDslFile(rootPath + "DeLoreanOwnership.yml");
Contract delorean2 = Contract.fromDslFile(rootPath + "DeLoreanOwnership.yml");
Contract delorean3 = Contract.fromDslFile(rootPath + "DeLoreanOwnership.yml");
List<Contract> deloreans = new ArrayList<>();
deloreans.add(delorean1);
deloreans.add(delorean2);
deloreans.add(delorean3);
Contract lamborghini1 = Contract.fromDslFile(rootPath + "LamborghiniOwnership.yml");
Contract lamborghini2 = Contract.fromDslFile(rootPath + "LamborghiniOwnership.yml");
List<Contract> lamborghinis = new ArrayList<>();
lamborghinis.add(lamborghini1);
lamborghinis.add(lamborghini2);
// ----- prepare contracts -----------
martyPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/marty_mcfly.private.unikey")));
for (PrivateKey pk : martyPrivateKeys) {
martyPublicKeys.add(pk.getPublicKey());
}
stepaPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
int i = 0;
for (Contract d : deloreans) {
i++;
d.addSignerKey(manufacturePrivateKey);
d.seal();
CLIMain.saveContract(d, rootPath + "delorean" + i + ".unicon");
callMain("--register", rootPath + "delorean" + i + ".unicon", "-wait", "5000");
}
i = 0;
for (Contract l : lamborghinis) {
i++;
l.addSignerKey(manufacturePrivateKey);
l.seal();
CLIMain.saveContract(l, rootPath + "lamborghini" + i + ".unicon");
callMain("--register", rootPath + "lamborghini" + i + ".unicon", "-wait", "5000");
}
// register swapped contracts using ContractsService
System.out.println("--- register swapped contracts using ContractsService ---");
Contract swapContract;
// first Marty create transaction, add both contracts and swap owners, sign own new contract
swapContract = ContractsService.startSwap(deloreans, lamborghinis, martyPrivateKeys, stepaPublicKeys);
ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys);
ContractsService.finishSwap(swapContract, martyPrivateKeys);
swapContract.check();
swapContract.traceErrors();
System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk() + " num new contracts: " + swapContract.getNewItems().size());
CLIMain.saveContract(swapContract, rootPath + "swapContract.unicon", true, true);
callMain("--register", rootPath + "swapContract.unicon", "-wait", "5000");
i = 0;
for (Contract c : swapContract.getNew()) {
i++;
CLIMain.saveContract(c, rootPath + "new" + i + ".unicon");
callMain("-e", rootPath + "new" + i + ".unicon", "-pretty");
}
// checkSwapResultSuccess(swapContract, delorean, lamborghini, martyPublicKeys, stepaPublicKeys);
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method anonymizeAllRoles.
@Test
public void anonymizeAllRoles() 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");
assertTrue(new File(basePath + "forRoleAnonymizing_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 contract = CLIMain.loadContract(basePath + "forRoleAnonymizing_anonymized.unicon", true);
assertFalse(contract.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(contract.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(contract.getCreator().getKeys().contains(key.getPublicKey()));
Contract anonPublishedContract = new Contract(contract.getLastSealedBinary());
assertFalse(anonPublishedContract.getOwner().getKeys().contains(ownerKey.getPublicKey()));
assertFalse(anonPublishedContract.getIssuer().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract.getCreator().getKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract.getSealedByKeys().contains(key.getPublicKey()));
assertFalse(anonPublishedContract.getSealedByKeys().contains(ownerKey.getPublicKey()));
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMainTest method testExportImportWithAddresses.
@Test
public void testExportImportWithAddresses() throws Exception {
callMain2("-create", rootPath + "simple_root_contract_v2.yml", "-name", basePath + "contractWithAddresses.unicon", "-k", rootPath + "_xer0yfe2nn1xthc.private.unikey");
Contract contract = CLIMain.loadContract(basePath + "contractWithAddresses.unicon", true);
Set<KeyAddress> keyAddresses = new HashSet<>();
keyAddresses.add(new KeyAddress(TestKeys.publicKey(0), 0, true));
SimpleRole sr1 = new SimpleRole("owner", keyAddresses);
contract.registerRole(sr1);
contract.addSignerKey(TestKeys.privateKey(0));
contract.seal();
CLIMain.saveContract(contract, basePath + "contractWithAddresses.unicon");
callMain("-e", basePath + "contractWithAddresses.unicon", "-name", basePath + "contractWithAddresses.json");
System.out.println(output);
assertTrue(output.indexOf("export as json ok") >= 0);
assertEquals(0, errors.size());
callMain("-i", basePath + "contractWithAddresses.json", "-name", basePath + "contractWithAddressesImported.unicon");
System.out.println(output);
assertTrue(output.indexOf("import from json ok") >= 0);
assertEquals(1, errors.size());
if (errors.size() > 0) {
assertEquals(Errors.NOT_SIGNED.name(), errors.get(0).get("code"));
}
Contract contractImported = CLIMain.loadContract(basePath + "contractWithAddressesImported.unicon", true);
assertTrue(contractImported.getOwner().getKeyAddresses().iterator().next().isMatchingKey(TestKeys.privateKey(0).getPublicKey()));
PrivateKey creatorPrivateKey = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
contractImported.addSignatureToSeal(creatorPrivateKey);
contractImported.addSignatureToSeal(TestKeys.privateKey(0));
assertTrue(contractImported.check());
Set<PrivateKey> signKeys = new HashSet<>();
signKeys.add(creatorPrivateKey);
signKeys.add(TestKeys.privateKey(0));
contractImported.setKeysToSignWith(signKeys);
byte[] sealedContract = contractImported.sealAsV2();
TransactionPack tp = new TransactionPack();
tp.addKeys(creatorPrivateKey.getPublicKey());
tp.addKeys(TestKeys.privateKey(0).getPublicKey());
Contract restoredContract = new Contract(sealedContract, tp);
assertTrue(restoredContract.check());
}
Aggregations