use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method swapSplitJoinMissingSign.
@Test(timeout = 90000)
public void swapSplitJoinMissingSign() 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);
// remove sign!!
martyCoinsSplit.getKeysToSignWith().clear();
martyCoinsSplit.removeAllSignatures();
martyCoinsSplit.seal();
Contract martyCoinsSplitToStepa = martyCoinsSplit.getNew().get(0);
Contract stepaCoinsSplit = ContractsService.createSplit(stepaCoins, 30, "amount", stepaPrivateKeys);
Contract stepaCoinsSplitToMarty = stepaCoinsSplit.getNew().get(0);
martyCoinsSplit.check();
martyCoinsSplit.traceErrors();
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());
registerAndCheckDeclined(swapContract);
assertEquals(ItemState.UNDEFINED, node.waitItem(martyCoinsSplit.getId(), 5000).state);
assertEquals(ItemState.UNDEFINED, node.waitItem(stepaCoinsSplit.getId(), 5000).state);
assertEquals(ItemState.UNDEFINED, node.waitItem(martyCoinsSplitToStepa.getId(), 5000).state);
assertEquals(ItemState.UNDEFINED, node.waitItem(stepaCoinsSplitToMarty.getId(), 5000).state);
assertEquals(ItemState.APPROVED, node.waitItem(martyCoins.getId(), 5000).state);
assertEquals(ItemState.APPROVED, node.waitItem(stepaCoins.getId(), 5000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method declineParcelWithNotRegisteredPayment.
@Test(timeout = 90000)
public void declineParcelWithNotRegisteredPayment() 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 manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
Contract stepaTU = Contract.fromDslFile(ROOT_PATH + "StepaTU.yml");
stepaTU.addSignerKey(manufacturePrivateKey);
stepaTU.seal();
stepaTU.check();
// stepaTU.setIsTU(true);
stepaTU.traceErrors();
// registerAndCheckApproved(stepaTU);
Parcel parcel = ContractsService.createParcel(stepaCoins, stepaTU, 50, stepaPrivateKeys);
assertTrue(parcel.getPaymentContract().isOk());
assertTrue(parcel.getPayloadContract().isOk());
node.registerParcel(parcel);
// wait parcel
node.waitParcel(parcel.getId(), 8000);
// check payment and payload contracts
assertEquals(ItemState.DECLINED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state);
assertEquals(ItemState.UNDEFINED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method createNotaryContractAllGood.
@Test(timeout = 90000)
public void createNotaryContractAllGood() 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 notaryContract = ContractsService.createNotaryContract(martyPrivateKeys, stepaPublicKeys);
notaryContract.check();
notaryContract.traceErrors();
registerAndCheckApproved(notaryContract);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method declineParcelWithTestAndRealPayment.
@Test(timeout = 90000)
public void declineParcelWithTestAndRealPayment() 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.setExpiresAt(ZonedDateTime.now().plusMonths(1));
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
stepaCoins.check();
stepaCoins.traceErrors();
Contract stepaTU = InnerContractsService.createFreshTU(100, stepaPublicKeys, true);
stepaTU.check();
// stepaTU.setIsTU(true);
stepaTU.traceErrors();
node.registerItem(stepaTU);
ItemResult itemResult = node.waitItem(stepaTU.getId(), 18000);
assertEquals(ItemState.APPROVED, itemResult.state);
Contract paymentDecreased = stepaTU.createRevision(stepaPrivateKeys);
paymentDecreased.getStateData().set("test_transaction_units", stepaTU.getStateData().getIntOrThrow("test_transaction_units") - 1);
paymentDecreased.getStateData().set("transaction_units", stepaTU.getStateData().getIntOrThrow("transaction_units") - 1);
paymentDecreased.seal();
Parcel parcel = new Parcel(stepaCoins.getTransactionPack(), paymentDecreased.getTransactionPack());
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 - 1, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
assertFalse(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.DECLINED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state);
assertEquals(ItemState.UNDEFINED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class BaseNetworkTest method swapContractsViaTransactionOneWrongSign3.
@Test(timeout = 90000)
public void swapContractsViaTransactionOneWrongSign3() 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);
// WRONG SIGN!
PrivateKey wrongSign = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
swapContract = startSwap_wrongKey(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys, wrongSign);
// then Marty send new revisions to Stepa
// and Stepa sign own new contract, Marty's new contract
swapContract = imitateSendingTransactionToPartner(swapContract);
ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys);
// 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);
}
Aggregations