Search in sources :

Example 71 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class BaseNetworkTest method registerParcelWithTestTUButRealPayment.

@Test(timeout = 90000)
public void registerParcelWithTestTUButRealPayment() 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);
    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());
    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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 72 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class BaseNetworkTest method swapContractsViaTransactionOneWrongSign1.

@Test(timeout = 90000)
public void swapContractsViaTransactionOneWrongSign1() 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);
    // 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);
    // WRONG SIGN!
    PrivateKey wrongSign = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
    finishSwap_wrongKey(swapContract, martyPrivateKeys, wrongSign);
    // 
    swapContract.check();
    swapContract.traceErrors();
    System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk());
    registerAndCheckDeclined(swapContract);
    checkSwapResultDeclined(swapContract, delorean, lamborghini, martyPublicKeys, stepaPublicKeys);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 73 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class BaseNetworkTest method referenceForRevoke.

@Test
public void referenceForRevoke() 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 + "NotaryWithReferenceDSLTemplate.yml");
    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();
    // here we "send" data and "got" it
    TransactionPack tp_after = TransactionPack.unpack(data);
    registerAndCheckApproved(tp_after);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 74 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class BaseNetworkTest method declineReferenceForChangeOwner.

@Test
public void declineReferenceForChangeOwner() 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 + "NotaryWithReferenceDSLTemplate.yml");
    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());
    // 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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 75 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class BaseNetworkTest method declineParcelWithTestPaymentBut4096Key.

@Test(timeout = 90000)
public void declineParcelWithTestPaymentBut4096Key() 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());
    }
    PrivateKey coinsKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
    Contract coins = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
    coins.addSignerKey(coinsKey);
    coins.seal();
    coins.check();
    coins.traceErrors();
    assertFalse(coinsKey.getPublicKey().getBitStrength() == 2048);
    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(coins, 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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Aggregations

PublicKey (com.icodici.crypto.PublicKey)84 PrivateKey (com.icodici.crypto.PrivateKey)75 Test (org.junit.Test)57 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)17 HashSet (java.util.HashSet)14 Binder (net.sergeych.tools.Binder)13 ListRole (com.icodici.universa.contract.roles.ListRole)11 Role (com.icodici.universa.contract.roles.Role)7 Contract (com.icodici.universa.contract.Contract)6 KeyAddress (com.icodici.crypto.KeyAddress)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)4 KeyRecord (com.icodici.universa.contract.KeyRecord)3 ChangeOwnerPermission (com.icodici.universa.contract.permissions.ChangeOwnerPermission)3 Permission (com.icodici.universa.contract.permissions.Permission)3 TimeoutException (java.util.concurrent.TimeoutException)3 Decimal (com.icodici.universa.Decimal)2 ErrorRecord (com.icodici.universa.ErrorRecord)2 HashId (com.icodici.universa.HashId)2 Quantiser (com.icodici.universa.node2.Quantiser)2 List (java.util.List)2