Search in sources :

Example 51 with PrivateKey

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

the class BaseNetworkTest method testLedgerLocks.

@Ignore("Stress test")
@Test(timeout = 900000)
public void testLedgerLocks() throws Exception {
    ExtendedSignatureTest.parallelize(Executors.newCachedThreadPool(), 4, () -> {
        try {
            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 manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "keys/tu_key.private.unikey"));
            int N = 100;
            for (int i = 0; i < N; i++) {
                Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
                stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
                stepaCoins.seal();
                Parcel parcel = createParcelWithClassTU(stepaCoins, stepaPrivateKeys);
                synchronized (tuContractLock) {
                    tuContract = parcel.getPaymentContract();
                }
                System.out.println("-------------- register parcel " + parcel.getId() + " (iteration " + i + ") ------------");
                node.registerParcel(parcel);
                for (Node n : nodes) {
                    n.waitParcel(parcel.getId(), 15000);
                    ItemResult itemResult = n.waitItem(stepaCoins.getId(), 15000);
                }
                ItemState itemState1 = node.waitItem(parcel.getPaymentContract().getRevoking().get(0).getId(), 15000).state;
                ItemState itemState2 = node.getLedger().getRecord(parcel.getPaymentContract().getRevoking().get(0).getId()).getState();
                System.out.println("--- check item " + parcel.getPaymentContract().getRevoking().get(0).getId() + " --- iteration " + i);
                System.out.println("state from node: " + itemState1);
                System.out.println("state from ledger: " + itemState2);
                assertEquals(itemState1, itemState2);
                assertEquals(ItemState.REVOKED, itemState1);
                assertEquals(ItemState.REVOKED, itemState2);
            }
        } catch (Exception e) {
            System.out.println("exception: " + e.toString());
        }
    });
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) TimeoutException(java.util.concurrent.TimeoutException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 52 with PrivateKey

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

the class BaseNetworkTest method swapManyContractsViaTransactionAllGood.

@Test(timeout = 90000)
public void swapManyContractsViaTransactionAllGood() 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 delorean1 = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
    Contract delorean2 = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
    Contract delorean3 = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
    List<Contract> deloreans = new ArrayList<>();
    deloreans.add(delorean1);
    deloreans.add(delorean2);
    deloreans.add(delorean3);
    Contract lamborghini1 = Contract.fromDslFile(ROOT_PATH + "LamborghiniOwnership.yml");
    Contract lamborghini2 = Contract.fromDslFile(ROOT_PATH + "LamborghiniOwnership.yml");
    List<Contract> lamborghinis = new ArrayList<>();
    lamborghinis.add(lamborghini1);
    lamborghinis.add(lamborghini2);
    // ----- prepare contracts -----------
    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());
    }
    PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
    for (Contract d : deloreans) {
        d.addSignerKey(manufacturePrivateKey);
        d.seal();
        registerAndCheckApproved(d);
    }
    for (Contract l : lamborghinis) {
        l.addSignerKey(manufacturePrivateKey);
        l.seal();
        registerAndCheckApproved(l);
    }
    // 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(deloreans, lamborghinis, 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);
    swapContract.check();
    swapContract.traceErrors();
    System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk() + " num new contracts: " + swapContract.getNewItems().size());
    registerAndCheckApproved(swapContract);
    for (Contract d : deloreans) {
        assertEquals(ItemState.REVOKED, node.waitItem(d.getId(), 5000).state);
        System.out.println("delorean is " + node.waitItem(d.getId(), 5000).state);
    }
    for (Contract l : lamborghinis) {
        assertEquals(ItemState.REVOKED, node.waitItem(l.getId(), 5000).state);
        System.out.println("lamborghini is " + node.waitItem(l.getId(), 5000).state);
    }
    for (Approvable a : swapContract.getNewItems()) {
        assertEquals(ItemState.APPROVED, node.waitItem(a.getId(), 5000).state);
        System.out.println("new is " + node.waitItem(a.getId(), 5000).state);
    }
// checkSwapResultSuccess(swapContract, delorean, lamborghini, martyPublicKeys, stepaPublicKeys);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 53 with PrivateKey

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

the class BaseNetworkTest method changeOwnerWithAddress.

@Test(timeout = 90000)
public void changeOwnerWithAddress() 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);
    // 
    KeyAddress stepaAddress = stepaPublicKeys.iterator().next().getShortAddress();
    Contract anonOwnerContract = c1.createRevisionWithAddress(Arrays.asList(key));
    anonOwnerContract.addSignerKey(key);
    anonOwnerContract.setOwnerKey(stepaAddress);
    anonOwnerContract.seal();
    anonOwnerContract.check();
    anonOwnerContract.traceErrors();
    Contract anonAfterSend = imitateSendingTransactionToPartner(anonOwnerContract);
    registerAndCheckApproved(anonAfterSend);
    assertTrue(anonAfterSend.getOwner().getKeyAddresses().iterator().next().equals(stepaAddress));
    assertEquals(0, anonAfterSend.getOwner().getKeys().size());
    // 
    Contract anonSignedContract = anonAfterSend.createRevisionWithAddress(stepaPrivateKeys);
    anonSignedContract.addSignerKeys(stepaPrivateKeys);
    anonSignedContract.setOwnerKeys(martyPublicKeys);
    anonSignedContract.seal();
    anonSignedContract.check();
    anonSignedContract.traceErrors();
    Contract afterSend = imitateSendingTransactionToPartner(anonSignedContract);
    registerAndCheckApproved(afterSend);
    assertEquals(0, afterSend.getOwner().getKeyAddresses().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()));
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) KeyAddress(com.icodici.crypto.KeyAddress) Test(org.junit.Test)

Example 54 with PrivateKey

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

the class BaseNetworkTest method declineReferenceForRevoke.

@Test
public void declineReferenceForRevoke() 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 = ContractsService.createRevocation(llcProperty, stepaPrivateKeys.iterator().next());
    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 55 with PrivateKey

use of com.icodici.crypto.PrivateKey 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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Aggregations

PrivateKey (com.icodici.crypto.PrivateKey)168 Test (org.junit.Test)122 PublicKey (com.icodici.crypto.PublicKey)76 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)29 Contract (com.icodici.universa.contract.Contract)24 Binder (net.sergeych.tools.Binder)22 IOException (java.io.IOException)16 HashSet (java.util.HashSet)14 ListRole (com.icodici.universa.contract.roles.ListRole)12 SQLException (java.sql.SQLException)11 Ignore (org.junit.Ignore)9 File (java.io.File)8 KeyAddress (com.icodici.crypto.KeyAddress)7 KeyRecord (com.icodici.universa.contract.KeyRecord)7 Role (com.icodici.universa.contract.roles.Role)7 Semaphore (java.util.concurrent.Semaphore)7 RoleLink (com.icodici.universa.contract.roles.RoleLink)5 TimeoutException (java.util.concurrent.TimeoutException)5 Decimal (com.icodici.universa.Decimal)4 HashId (com.icodici.universa.HashId)4