use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method declineReferenceForChangeNumber.
@Test
public void declineReferenceForChangeNumber() throws Exception {
// You have a notary dsl with llc's property
// and only owner of trusted manager's contract can chamge the owner of property
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 llcProperty = Contract.fromDslFile(ROOT_PATH + "AbonementWithReferenceDSLTemplate.yml");
llcProperty.addSignerKey(llcPrivateKeys.iterator().next());
llcProperty.seal();
registerAndCheckApproved(llcProperty);
Contract llcProperty2 = llcProperty.createRevision(stepaPrivateKeys);
llcProperty2.getStateData().set("units", llcProperty.getStateData().getIntOrThrow("units") - 1);
llcProperty2.seal();
llcProperty2.check();
llcProperty2.traceErrors();
assertFalse(llcProperty2.isOk());
// bad situations
TransactionPack tp_before;
TransactionPack tp_after;
Contract jobCertificate;
// missing data.issuer
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);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// missing data.type
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);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// not registered
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);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// missing reference
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);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
// tp_before.addForeignReference(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// wrong issuer
jobCertificate = new Contract(stepaPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys);
jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita");
jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// wrong data.issuer
jobCertificate = new Contract(llcPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys);
jobCertificate.getDefinition().getData().set("issuer", "Not Roga & Kopita");
jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// wrong data.type
jobCertificate = new Contract(llcPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys);
jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita");
jobCertificate.getDefinition().getData().set("type", "Not chief accountant assignment");
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
// revoked reference
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.addPermission(new RevokePermission(jobCertificate.getOwner()));
jobCertificate.seal();
registerAndCheckApproved(jobCertificate);
Contract revokingJobCertificate = ContractsService.createRevocation(jobCertificate, stepaPrivateKeys.iterator().next());
revokingJobCertificate.check();
revokingJobCertificate.traceErrors();
registerAndCheckApproved(revokingJobCertificate);
tp_before = llcProperty2.getTransactionPack();
tp_before.getReferencedItems().clear();
tp_before.addReferencedItem(jobCertificate);
// here we "send" data and "got" it
tp_after = TransactionPack.unpack(tp_before.pack());
registerAndCheckDeclined(tp_after);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method registerParcelWithRealPayment.
@Test(timeout = 90000)
public void registerParcelWithRealPayment() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
stepaCoins.check();
stepaCoins.traceErrors();
PrivateKey ownerKey = new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey"));
Set<PublicKey> keys = new HashSet();
keys.add(ownerKey.getPublicKey());
Contract stepaTU = InnerContractsService.createFreshTU(100, keys, true);
stepaTU.check();
// stepaTU.setIsTU(true);
stepaTU.traceErrors();
node.registerItem(stepaTU);
ItemResult itemResult = node.waitItem(stepaTU.getId(), 18000);
assertEquals(ItemState.APPROVED, itemResult.state);
Parcel parcel = ContractsService.createParcel(stepaCoins, stepaTU, 1, stepaPrivateKeys, false);
parcel.getPayment().getContract().paymentCheck(config.getTransactionUnitsIssuerKey());
parcel.getPayment().getContract().traceErrors();
parcel.getPayload().getContract().check();
parcel.getPayload().getContract().traceErrors();
assertEquals(100 - 1, parcel.getPaymentContract().getStateData().getIntOrThrow("transaction_units"));
assertEquals(10000, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
assertTrue(parcel.getPaymentContract().isOk());
assertFalse(parcel.getPaymentContract().isLimitedForTestnet());
assertTrue(parcel.getPayloadContract().isOk());
assertFalse(parcel.getPayloadContract().isLimitedForTestnet());
System.out.println("Parcel: " + parcel.getId());
System.out.println("Payment contract: " + parcel.getPaymentContract().getId() + " is TU: " + parcel.getPaymentContract().isTU(config.getTransactionUnitsIssuerKey(), config.getTUIssuerName()));
System.out.println("Payload contract: " + parcel.getPayloadContract().getId() + " is TU: " + parcel.getPayloadContract().isTU(config.getTransactionUnitsIssuerKey(), config.getTUIssuerName()));
// reuse payment for another contract
Contract contract = new Contract(TestKeys.privateKey(12));
contract.seal();
Parcel parcel2 = new Parcel(contract.getTransactionPack(), parcel.getPayment());
node.registerParcel(parcel);
node.registerParcel(parcel2);
node.waitParcel(parcel.getId(), 8000);
node.waitParcel(parcel2.getId(), 8000);
// check payment and payload contracts
assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state);
assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
assertNotEquals(ItemState.APPROVED, node.waitItem(parcel2.getPayload().getContract().getId(), 8000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method referenceForChangeOwnerWithCreateContract.
@Test
public void referenceForChangeOwnerWithCreateContract() throws Exception {
// manager -
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
// issuer
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 = llcProperty.createRevision(stepaPrivateKeys);
llcProperty2.setOwnerKeys(thirdPartyPublicKeys);
llcProperty2.seal();
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 registerParcel.
@Test(timeout = 90000)
public void registerParcel() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
stepaCoins.check();
stepaCoins.traceErrors();
Parcel parcel = createParcelWithFreshTU(stepaCoins, stepaPrivateKeys);
parcel.getPayment().getContract().check();
parcel.getPayment().getContract().traceErrors();
parcel.getPayload().getContract().check();
parcel.getPayload().getContract().traceErrors();
assertTrue(parcel.getPaymentContract().isOk());
assertTrue(parcel.getPayloadContract().isOk());
System.out.println("Parcel: " + parcel.getId());
System.out.println("Payment contract: " + parcel.getPaymentContract().getId() + " is TU: " + parcel.getPaymentContract().isTU(config.getTransactionUnitsIssuerKey(), config.getTUIssuerName()));
System.out.println("Payload contract: " + parcel.getPayloadContract().getId() + " is TU: " + parcel.getPayloadContract().isTU(config.getTransactionUnitsIssuerKey(), config.getTUIssuerName()));
// LogPrinter.showDebug(true);
node.registerParcel(parcel);
// wait parcel
node.waitParcel(parcel.getId(), 8000);
// check payment and payload contracts
assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state);
assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method referenceForSplitJoinWithCreateContract.
@Test
public void referenceForSplitJoinWithCreateContract() 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.createTokenContract(llcPrivateKeys, stepaPublicKeys, "100000000000");
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.setMode(ListRole.Mode.ALL);
listRole.addRole(ownerRole);
listRole.addRequiredReference("certification_contract", Role.RequiredMode.ALL_OF);
llcProperty.getPermissions().remove("split_join");
llcProperty.getPermissions().remove("change_owner");
llcProperty.getPermissions().remove("revoke");
Binder params = new Binder();
params.set("min_value", 0.01);
params.set("min_unit", 0.001);
params.set("field_name", "amount");
List<String> listFields = new ArrayList<>();
listFields.add("state.origin");
params.set("join_match_fields", listFields);
SplitJoinPermission splitJoinPerm = new SplitJoinPermission(listRole, params);
llcProperty.addPermission(splitJoinPerm);
llcProperty.addSignerKey(llcPrivateKeys.iterator().next());
llcProperty.seal();
registerAndCheckApproved(llcProperty);
Contract llcProperty2 = ContractsService.createSplit(llcProperty, 100, "amount", stepaPrivateKeys, true);
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);
}
Aggregations