use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class SimpleRole method initWithRecords.
private void initWithRecords(@NonNull Collection records) {
records.forEach(x -> {
KeyRecord kr = null;
AnonymousId anonId = null;
if (x instanceof KeyRecord)
kr = (KeyRecord) x;
else if (x instanceof PublicKey)
kr = new KeyRecord((PublicKey) x);
else if (x instanceof AnonymousId)
anonId = (AnonymousId) x;
else if (x instanceof PrivateKey)
kr = new KeyRecord(((PrivateKey) x).getPublicKey());
else if (x instanceof KeyAddress)
keyAddresses.add((KeyAddress) x);
else
throw new IllegalArgumentException("Cant create KeyRecord from " + x);
if (anonId != null)
anonymousIds.add(anonId);
else if (kr != null)
keyRecords.put(kr.getPublicKey(), kr);
});
}
use of com.icodici.universa.contract.KeyRecord 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.KeyRecord in project universa by UniversaBlockchain.
the class CLIMainTest method revokeCreatedContractWithRole.
@Test
public void revokeCreatedContractWithRole() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey()));
c.seal();
String contractFileName = basePath + "with_role_for_revoke.unicon";
CLIMain.saveContract(c, contractFileName);
System.out.println("---");
System.out.println("register contract");
System.out.println("---");
String tuContract = getApprovedTUContract();
// CLIMain.registerContract(c);
callMain2("--register", contractFileName, "--verbose", "--tu", tuContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey");
Thread.sleep(1500);
System.out.println("---");
System.out.println("check contract");
System.out.println("---");
callMain("--probe", c.getId().toBase64String());
System.out.println(output);
assertTrue(output.indexOf(ItemState.APPROVED.name()) >= 0);
tuContract = getApprovedTUContract();
callMain2("-revoke", contractFileName, "-k", PRIVATE_KEY_PATH, "-v", "--tu", tuContract, "--k", rootPath + "keys/stepan_mamontov.private.unikey");
Thread.sleep(1500);
System.out.println("---");
System.out.println("check contract after revoke");
System.out.println("---");
callMain("--probe", c.getId().toBase64String());
System.out.println(output);
assertTrue(output.indexOf(ItemState.REVOKED.name()) >= 0);
}
use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class ListRoleTest method shouldNotPerformRoleWithQuorumMode.
@Test
public void shouldNotPerformRoleWithQuorumMode() {
Contract c = new Contract();
SimpleRole s1 = new SimpleRole("owner");
SimpleRole s2 = new SimpleRole("owner2");
s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
s2.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
c.registerRole(s1);
c.registerRole(s2);
ListRole roleList = new ListRole("listQuorumMode");
roleList.setQuorum(2);
roleList.addAll(Do.listOf(s1, s2));
c.registerRole(roleList);
HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(1).getPublicKey()));
assertFalse(roleList.isAllowedForKeys(keys));
}
use of com.icodici.universa.contract.KeyRecord in project universa by UniversaBlockchain.
the class ListRoleTest method shouldPerformRoleWithAllMode.
@Test
public void shouldPerformRoleWithAllMode() {
Contract c = new Contract();
SimpleRole s1 = new SimpleRole("owner");
SimpleRole s2 = new SimpleRole("owner2");
s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
s2.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
c.registerRole(s1);
c.registerRole(s2);
ListRole roleList = new ListRole("listAllMode");
roleList.setMode(ListRole.Mode.ALL);
roleList.addRole(s1).addRole(s2);
HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(ListRoleTest.keys.get(0).getPublicKey(), ListRoleTest.keys.get(1).getPublicKey()));
assertTrue(roleList.isAllowedForKeys(keys));
}
Aggregations