use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ContractTest method testRoleFailures.
// @Test
// public void shouldFindWithValidReference() throws Exception {
// Contract c = Contract.fromDslFile(rootPath + "references/subscriptionReference.yml");
// Contract c2 = Contract.fromDslFile(rootPath + "references/subscriptionRoot.yml");
//
// List<Contract> contracts = c2.extractByValidReference(Arrays.asList(c));
// assertNotNull(contracts);
// assertEquals(1, contracts.size());
// }
//
// @Test
// public void shouldFindWithValidReferenceSeal() throws Exception {
// Contract c = Contract.fromDslFile(rootPath + "references/subscriptionReference.yml");
// Contract c2 = Contract.fromDslFile(rootPath + "references/subscriptionRoot.yml");
//
// c = new Contract(c.seal());
// c2 = new Contract(c2.seal());
//
// List<Contract> contracts = c2.extractByValidReference(Arrays.asList(c));
// assertNotNull(contracts);
// assertEquals(1, contracts.size());
// }
@Test
public void testRoleFailures() throws Exception {
final PrivateKey key = new PrivateKey(2048);
final PublicKey publicKey = key.getPublicKey();
{
// Missing issuer
final Contract c = new Contract(key);
c.getRoles().remove("issuer");
c.seal();
c.check();
assertFalse(c.isOk());
assertNull(c.getIssuer());
assertFalse(c.getOwner().isValid());
assertFalse(c.getCreator().isValid());
}
{
// Missing creator
final Contract c = new Contract(key);
c.getRoles().remove("creator");
c.seal();
c.check();
assertFalse(c.isOk());
assertTrue(c.getIssuer().isValid());
assertTrue(c.getOwner().isValid());
assertNull(c.getCreator());
}
{
// Missing owner
final Contract c = new Contract(key);
c.getRoles().remove("owner");
c.seal();
c.check();
assertFalse(c.isOk());
assertTrue(c.getIssuer().isValid());
assertNull(c.getOwner());
assertTrue(c.getCreator().isValid());
}
{
// Test chain of links (good), then test breaking it (bad).
// issuer:key, creator->owner, owner->issuer
final Contract c = new Contract(key);
c.getRoles().remove("creator");
c.registerRole(new RoleLink("creator", "owner"));
c.seal();
c.check();
assertTrue(c.isOk());
assertTrue(c.getIssuer().isValid());
assertTrue(c.getOwner().isValid());
assertTrue(c.getCreator().isValid());
// Let's break the link in the middle
c.getRoles().remove("owner");
// We haven't called `check` once again, so it's still ok
assertTrue(c.isOk());
// and now it is no more ok.
c.check();
assertFalse(c.isOk());
assertTrue(c.getIssuer().isValid());
assertNull(c.getOwner());
assertFalse(c.getCreator().isValid());
assertFalse(c.getErrors().isEmpty());
}
{
// Test loop of links (bad).
// issuer->creator, creator->owner, owner->issuer
final Contract c = new Contract(key);
c.getRoles().clear();
c.registerRole(new RoleLink("issuer", "creator"));
c.registerRole(new RoleLink("creator", "owner"));
c.registerRole(new RoleLink("owner", "issuer"));
c.seal();
// and now it is no more ok.
c.check();
assertFalse(c.isOk());
assertFalse(c.getIssuer().isValid());
assertFalse(c.getOwner().isValid());
assertFalse(c.getCreator().isValid());
}
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method swapContractsViaTransactionOneWrongSign2.
@Test(timeout = 90000)
public void swapContractsViaTransactionOneWrongSign2() throws Exception {
if (node == null) {
System.out.println("network not inited");
return;
}
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
Contract delorean = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
Contract lamborghini = Contract.fromDslFile(ROOT_PATH + "LamborghiniOwnership.yml");
prepareContractsForSwap(martyPrivateKeys, martyPublicKeys, stepaPrivateKeys, stepaPublicKeys, delorean, lamborghini);
// 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(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys);
// then Marty send new revisions to Stepa
// and Stepa sign own new contract, Marty's new contract
swapContract = imitateSendingTransactionToPartner(swapContract);
// ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys);
// WRONG SIGN!
PrivateKey wrongSign = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
signPresentedSwap_wrongKey(swapContract, stepaPrivateKeys, wrongSign);
// then Stepa send draft transaction back to Marty
// and Marty sign Stepa's new contract and send to approving
swapContract = imitateSendingTransactionToPartner(swapContract);
ContractsService.finishSwap(swapContract, martyPrivateKeys);
swapContract.check();
swapContract.traceErrors();
System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk());
registerAndCheckDeclined(swapContract);
checkSwapResultDeclined(swapContract, delorean, lamborghini, martyPublicKeys, stepaPublicKeys);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method changeOwnerWithAnonId2.
@Test(timeout = 90000)
public void changeOwnerWithAnonId2() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
martyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) stepaPublicKeys.add(pk.getPublicKey());
for (PrivateKey pk : martyPrivateKeys) martyPublicKeys.add(pk.getPublicKey());
PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
Contract c1 = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
c1.addSignerKey(key);
c1.seal();
c1.check();
c1.traceErrors();
registerAndCheckApproved(c1);
//
AnonymousId stepaAnonId = AnonymousId.fromBytes(stepaPublicKeys.iterator().next().createAnonymousId());
Contract anonOwnerContract = c1.createRevision(key);
anonOwnerContract.setOwnerKey(stepaAnonId);
anonOwnerContract.seal();
anonOwnerContract.check();
anonOwnerContract.traceErrors();
registerAndCheckApproved(anonOwnerContract);
assertTrue(anonOwnerContract.getOwner().getAnonymousIds().iterator().next().equals(stepaAnonId));
assertEquals(0, anonOwnerContract.getOwner().getKeys().size());
//
Contract anonSignedContract = anonOwnerContract.createRevision();
anonSignedContract.setOwnerKeys(martyPublicKeys);
anonSignedContract.setCreatorKeys(stepaAnonId);
anonSignedContract.addSignerKey(stepaPrivateKeys.iterator().next());
anonSignedContract.seal();
anonSignedContract.check();
anonSignedContract.traceErrors();
Contract afterSend = imitateSendingTransactionToPartner(anonSignedContract);
registerAndCheckApproved(afterSend);
assertEquals(0, afterSend.getOwner().getAnonymousIds().size());
assertTrue(afterSend.getOwner().isAllowedForKeys(martyPublicKeys));
Contract anonPublishedContract = new Contract(anonSignedContract.getLastSealedBinary());
ItemResult itemResult = node.waitItem(anonPublishedContract.getId(), 8000);
assertEquals(ItemState.APPROVED, itemResult.state);
assertFalse(anonPublishedContract.getSealedByKeys().contains(stepaPublicKeys.iterator().next()));
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method referenceForRevokeWithCreateContract.
@Test
public void referenceForRevokeWithCreateContract() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PrivateKey> llcPrivateKeys = new HashSet<>();
Set<PrivateKey> thirdPartyPrivateKeys = new HashSet<>();
llcPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
thirdPartyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
Set<PublicKey> stepaPublicKeys = new HashSet<>();
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Set<PublicKey> thirdPartyPublicKeys = new HashSet<>();
for (PrivateKey pk : thirdPartyPrivateKeys) {
thirdPartyPublicKeys.add(pk.getPublicKey());
}
Contract jobCertificate = new Contract(llcPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys);
jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita");
jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
Contract llcProperty = ContractsService.createNotaryContract(llcPrivateKeys, stepaPublicKeys);
List<String> listConditions = new ArrayList<>();
listConditions.add("ref.definition.issuer == \"26RzRJDLqze3P5Z1AzpnucF75RLi1oa6jqBaDh8MJ3XmTaUoF8R\"");
listConditions.add("ref.definition.data.issuer == \"Roga & Kopita\"");
listConditions.add("ref.definition.data.type == \"chief accountant assignment\"");
Reference reference = new Reference(llcProperty);
reference.name = "certification_contract";
reference.type = Reference.TYPE_EXISTING;
Binder conditions = new Binder();
conditions.set("all_of", listConditions);
reference.setConditions(conditions);
reference.addMatchingItem(jobCertificate);
// llcProperty.getDefinition().getReferences().add(reference);
llcProperty.addReference(reference);
ListRole listRole = new ListRole("list_role");
SimpleRole ownerRole = new SimpleRole("owner", stepaPrivateKeys);
listRole.addRole(ownerRole);
listRole.addRequiredReference("certification_contract", Role.RequiredMode.ALL_OF);
llcProperty.getPermissions().remove("change_owner");
llcProperty.getPermissions().remove("revoke");
ChangeOwnerPermission changeOwnerPerm = new ChangeOwnerPermission(listRole);
llcProperty.addPermission(changeOwnerPerm);
RevokePermission revokePerm = new RevokePermission(listRole);
llcProperty.addPermission(revokePerm);
llcProperty.addSignerKey(llcPrivateKeys.iterator().next());
llcProperty.seal();
registerAndCheckApproved(llcProperty);
Contract llcProperty2 = ContractsService.createRevocation(llcProperty, stepaPrivateKeys.iterator().next());
llcProperty2.check();
llcProperty2.traceErrors();
// assertFalse(llcProperty2.isOk());
TransactionPack tp_before = llcProperty2.getTransactionPack();
// tp_before.addReferencedItem(jobCertificate);
byte[] data = tp_before.pack();
TransactionPack tp_after = TransactionPack.unpack(data);
registerAndCheckApproved(tp_after);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method createShareContractAllGood.
@Test(timeout = 90000)
public void createShareContractAllGood() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
martyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) stepaPublicKeys.add(pk.getPublicKey());
Contract shareContract = ContractsService.createShareContract(martyPrivateKeys, stepaPublicKeys, "100");
shareContract.check();
shareContract.traceErrors();
registerAndCheckApproved(shareContract);
}
Aggregations