use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method referenceForChangeNumber.
@Test
public void referenceForChangeNumber() 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 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 = 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());
TransactionPack tp_before = llcProperty2.getTransactionPack();
tp_before.addReferencedItem(jobCertificate);
byte[] data = tp_before.pack();
// here we "send" data and "got" it
TransactionPack tp_after = TransactionPack.unpack(data);
registerAndCheckApproved(tp_after);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method registerParcelWithTestPayment.
@Test(timeout = 90000)
public void registerParcelWithTestPayment() 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.setExpiresAt(ZonedDateTime.now().plusMonths(1));
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, true);
parcel.getPayment().getContract().paymentCheck(config.getTransactionUnitsIssuerKey());
parcel.getPayment().getContract().traceErrors();
parcel.getPayload().getContract().check();
parcel.getPayload().getContract().traceErrors();
assertEquals(100, parcel.getPaymentContract().getStateData().getIntOrThrow("transaction_units"));
assertEquals(10000 - 1, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
assertTrue(parcel.getPaymentContract().isOk());
assertTrue(parcel.getPaymentContract().isLimitedForTestnet());
assertTrue(parcel.getPayloadContract().isOk());
assertTrue(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()));
// 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 swapSplitJoinAllGood.
@Test(timeout = 60000)
public void swapSplitJoinAllGood() 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<>();
martyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
for (PrivateKey pk : martyPrivateKeys) {
martyPublicKeys.add(pk.getPublicKey());
}
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Contract martyCoins = Contract.fromDslFile(ROOT_PATH + "martyCoins.yml");
martyCoins.addSignerKey(martyPrivateKeys.iterator().next());
martyCoins.seal();
martyCoins.check();
martyCoins.traceErrors();
registerAndCheckApproved(martyCoins);
Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
stepaCoins.check();
stepaCoins.traceErrors();
registerAndCheckApproved(stepaCoins);
System.out.println("--- coins created ---");
// 100 - 30 = 70
Contract martyCoinsSplit = ContractsService.createSplit(martyCoins, 30, "amount", martyPrivateKeys);
Contract martyCoinsSplitToStepa = martyCoinsSplit.getNew().get(0);
Contract stepaCoinsSplit = ContractsService.createSplit(stepaCoins, 30, "amount", stepaPrivateKeys);
Contract stepaCoinsSplitToMarty = stepaCoinsSplit.getNew().get(0);
martyCoinsSplitToStepa.check();
martyCoinsSplitToStepa.traceErrors();
stepaCoinsSplitToMarty.check();
stepaCoinsSplitToMarty.traceErrors();
// register swapped contracts using ContractsService
System.out.println("--- register swapped contracts using ContractsService ---");
Contract swapContract;
swapContract = ContractsService.startSwap(martyCoinsSplitToStepa, stepaCoinsSplitToMarty, martyPrivateKeys, stepaPublicKeys, false);
ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys);
ContractsService.finishSwap(swapContract, martyPrivateKeys);
swapContract.getNewItems().clear();
swapContract.addNewItems(martyCoinsSplit, stepaCoinsSplit);
swapContract.seal();
swapContract.addSignatureToSeal(martyPrivateKeys);
swapContract.check();
swapContract.traceErrors();
System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk());
registerAndCheckApproved(swapContract);
assertEquals(ItemState.APPROVED, node.waitItem(martyCoinsSplit.getId(), 5000).state);
assertEquals(ItemState.APPROVED, node.waitItem(stepaCoinsSplit.getId(), 5000).state);
assertEquals(ItemState.APPROVED, node.waitItem(martyCoinsSplitToStepa.getId(), 5000).state);
assertEquals(ItemState.APPROVED, node.waitItem(stepaCoinsSplitToMarty.getId(), 5000).state);
assertEquals(ItemState.REVOKED, node.waitItem(martyCoins.getId(), 5000).state);
assertEquals(ItemState.REVOKED, node.waitItem(stepaCoins.getId(), 5000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method checkCreateTwoSignedContractAllGood.
private void checkCreateTwoSignedContractAllGood(boolean newRev) throws Exception {
if (node == null) {
System.out.println("network not inited");
return;
}
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 baseContract = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
baseContract.addSignerKey(manufacturePrivateKey);
baseContract.seal();
System.out.println("Base contract contract is valid: " + baseContract.isOk());
if (newRev)
registerAndCheckApproved(baseContract);
Contract twoSignContract = ContractsService.createTwoSignedContract(baseContract, martyPrivateKeys, stepaPublicKeys, newRev);
twoSignContract = imitateSendingTransactionToPartner(twoSignContract);
twoSignContract.addSignatureToSeal(stepaPrivateKeys);
twoSignContract.check();
twoSignContract.traceErrors();
registerAndCheckDeclined(twoSignContract);
twoSignContract = imitateSendingTransactionToPartner(twoSignContract);
twoSignContract.addSignatureToSeal(martyPrivateKeys);
twoSignContract.check();
twoSignContract.traceErrors();
System.out.println("Contract with two signature is valid: " + twoSignContract.isOk());
registerAndCheckApproved(twoSignContract);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method declineParcelWithTestPaymentButTooFatherExpiration.
@Test(timeout = 90000)
public void declineParcelWithTestPaymentButTooFatherExpiration() 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.setExpiresAt(ZonedDateTime.now().plusYears(2));
stepaCoins.seal();
stepaCoins.check();
stepaCoins.traceErrors();
assertTrue(stepaCoins.getExpiresAt().isAfter(ZonedDateTime.now().plusYears(1)));
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, true);
parcel.getPayment().getContract().paymentCheck(config.getTransactionUnitsIssuerKey());
parcel.getPayment().getContract().traceErrors();
parcel.getPayload().getContract().check();
parcel.getPayload().getContract().traceErrors();
assertEquals(100, parcel.getPaymentContract().getStateData().getIntOrThrow("transaction_units"));
assertEquals(10000 - 1, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
assertTrue(parcel.getPaymentContract().isOk());
assertTrue(parcel.getPaymentContract().isLimitedForTestnet());
assertFalse(parcel.getPayloadContract().isOk());
assertTrue(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()));
// 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.DECLINED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
}
Aggregations