Search in sources :

Example 61 with PublicKey

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

the class BaseNetworkTest method declineParcelWithTooBigCostTUTestPayment.

// @Test(timeout = 90000)
public void declineParcelWithTooBigCostTUTestPayment() 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 stepaPrivateKey = stepaPrivateKeys.iterator().next();
    Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
    stepaCoins.setExpiresAt(ZonedDateTime.now().plusMonths(1));
    stepaCoins.addSignerKey(stepaPrivateKey);
    for (int i = 0; i < 100; i++) {
        Contract newItem = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
        newItem.setExpiresAt(ZonedDateTime.now().plusMonths(1));
        newItem.addSignerKey(stepaPrivateKey);
        stepaCoins.addNewItems(newItem);
    }
    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);
    int processedCost = stepaCoins.getProcessedCostTU();
    System.out.println("stepaCoins processed cost in TU: " + processedCost);
    assertTrue(processedCost > Config.maxCostTUInTestMode);
    Parcel parcel = ContractsService.createParcel(stepaCoins, stepaTU, processedCost, 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 - processedCost, 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(), 18000);
    // 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(), 18000).state);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey)

Example 62 with PublicKey

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

the class BaseNetworkTest method declineParcelWithNotSignedPayment.

@Test(timeout = 90000)
public void declineParcelWithNotSignedPayment() 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 + "keys/tu_key.private.unikey"));
    Contract stepaTU = Contract.fromDslFile(ROOT_PATH + "StepaTU.yml");
    stepaTU.addSignerKey(manufacturePrivateKey);
    stepaTU.seal();
    stepaTU.check();
    // stepaTU.setIsTU(true);
    stepaTU.traceErrors();
    node.registerItem(stepaTU);
    ItemResult itemResult = node.waitItem(stepaTU.getId(), 8000);
    assertEquals(ItemState.APPROVED, itemResult.state);
    // registerAndCheckApproved(stepaTU);
    Contract paymentDecreased = stepaTU.createRevision();
    paymentDecreased.getStateData().set("transaction_units", stepaTU.getStateData().getIntOrThrow("transaction_units") - 50);
    // paymentDecreased.setIsTU(true);
    paymentDecreased.seal();
    paymentDecreased.check();
    paymentDecreased.traceErrors();
    Parcel parcel = new Parcel(stepaCoins.getTransactionPack(), paymentDecreased.getTransactionPack());
    assertFalse(parcel.getPaymentContract().isOk());
    assertTrue(parcel.getPayloadContract().isOk());
    node.registerParcel(parcel);
    // check parcel
    node.waitParcel(parcel.getId(), 8000);
    // check payment and payload contracts
    assertEquals(ItemState.DECLINED, node.waitItem(parcel.getPaymentContract().getId(), 8000).state);
    assertEquals(ItemState.UNDEFINED, node.waitItem(parcel.getPayloadContract().getId(), 8000).state);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 63 with PublicKey

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

the class BaseNetworkTest method declineParcelWithBadPayload.

@Test(timeout = 90000)
public void declineParcelWithBadPayload() 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);
    assertTrue(parcel.getPaymentContract().isOk());
    assertFalse(parcel.getPayloadContract().isOk());
    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)

Example 64 with PublicKey

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

the class BaseNetworkTest method changeOwnerWithAnonId.

@Test(timeout = 90000)
public void changeOwnerWithAnonId() 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);
    // 
    AnonymousId stepaAnonId = AnonymousId.fromBytes(stepaPublicKeys.iterator().next().createAnonymousId());
    Contract anonOwnerContract = c1.createRevisionAnonymously(Arrays.asList(key));
    anonOwnerContract.addSignerKey(key);
    anonOwnerContract.setOwnerKey(stepaAnonId);
    anonOwnerContract.seal();
    anonOwnerContract.check();
    anonOwnerContract.traceErrors();
    registerAndCheckApproved(anonOwnerContract);
    assertTrue(anonOwnerContract.getOwner().getAnonymousIds().iterator().next().equals(stepaAnonId));
    assertEquals(0, anonOwnerContract.getOwner().getKeys().size());
    // 
    Contract anonSignedContract = anonOwnerContract.createRevisionAnonymously(stepaPrivateKeys);
    anonSignedContract.addSignerKeys(stepaPrivateKeys);
    anonSignedContract.setOwnerKeys(martyPublicKeys);
    anonSignedContract.seal();
    anonSignedContract.check();
    anonSignedContract.traceErrors();
    Contract afterSend = imitateSendingTransactionToPartner(anonSignedContract);
    registerAndCheckApproved(afterSend);
    assertEquals(0, afterSend.getOwner().getAnonymousIds().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) Test(org.junit.Test)

Example 65 with PublicKey

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

the class BaseNetworkTest method createTokenContractAllGood.

@Test(timeout = 90000)
public void createTokenContractAllGood() 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 tokenContract = ContractsService.createTokenContract(martyPrivateKeys, stepaPublicKeys, "100000000000");
    tokenContract.check();
    tokenContract.traceErrors();
    registerAndCheckApproved(tokenContract);
}
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