Search in sources :

Example 16 with PrivateKey

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

the class ResearchTest method registerSimpleContract_recreateNodeClient.

@Test
public void registerSimpleContract_recreateNodeClient() 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();
    System.out.println("nodeClient.register(stepaCoins)...");
    ItemResult itemResult = nodeClient.register(stepaCoins.getLastSealedBinary(), 1000);
    System.out.println("nodeClient.register(stepaCoins)... done! itemResult: " + itemResult.state);
    reCreateNodeClient();
    itemResult = nodeClient.getState(stepaCoins.getId());
    System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
    assertEquals(ItemState.APPROVED, itemResult.state);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet)

Example 17 with PrivateKey

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

the class ResearchTest method registerSimpleContract_getStateOnly.

@Test
public void registerSimpleContract_getStateOnly() 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();
    ItemResult itemResult = nodeClient.getState(stepaCoins.getId());
    System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
    assertEquals(ItemState.APPROVED, itemResult.state);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet)

Example 18 with PrivateKey

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

the class ContractTest method checkTestnetKeyStrengthCriteria.

@Test
public void checkTestnetKeyStrengthCriteria() throws Exception {
    PrivateKey key = new PrivateKey(Do.read(PRIVATE_KEY_PATH));
    Contract contract = createCoin100apiv3();
    contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
    contract.addSignerKey(key);
    sealCheckTrace(contract, true);
    assertFalse(contract.isSuitableForTestnet());
    // now set contract limited for testnet
    contract.setLimitedForTestnet(true);
    sealCheckTrace(contract, false);
    assertFalse(contract.isSuitableForTestnet());
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 19 with PrivateKey

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

the class ContractTest method checkParallelCreation.

@Ignore("parallel test")
@Test
public void checkParallelCreation() throws Exception {
    final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    int N = 100;
    int M = Runtime.getRuntime().availableProcessors();
    int K = 10;
    float threshold = 1.2f;
    float ratio = 0;
    System.out.println("available processors: " + M);
    for (int i = 0; i < N; i++) {
        long ts1;
        long ts2;
        Semaphore semaphore = new Semaphore(-(M - 1));
        ts1 = new Date().getTime();
        for (int j = 0; j < M; j++) {
            new Thread(() -> {
                for (int x = 0; x < K; x++) {
                    try {
                        Contract c = new Contract(key);
                        for (int k = 0; k < 10; k++) {
                            Contract nc = new Contract(key);
                            nc.seal();
                            c.addNewItems(nc);
                        }
                        c.seal();
                        c.check();
                    } catch (Quantiser.QuantiserException e) {
                        e.printStackTrace();
                    }
                }
                semaphore.release();
            }).start();
        }
        semaphore.acquire();
        ts2 = new Date().getTime();
        long time2 = ts2 - ts1;
        ts1 = new Date().getTime();
        new Thread(() -> {
            for (int x = 0; x < K; x++) {
                try {
                    Contract c = new Contract(key);
                    for (int k = 0; k < 10; k++) {
                        Contract nc = new Contract(key);
                        nc.seal();
                        c.addNewItems(nc);
                    }
                    c.seal();
                    c.check();
                } catch (Quantiser.QuantiserException e) {
                    e.printStackTrace();
                }
            }
            semaphore.release();
        }).start();
        semaphore.acquire();
        ts2 = new Date().getTime();
        long time3 = ts2 - ts1;
        System.out.println(time2 * 1.0f / time3);
        ratio += time2 * 1.0f / time3;
    }
    ratio /= N;
    System.out.println("average " + ratio);
    assertFalse(ratio > threshold);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Semaphore(java.util.concurrent.Semaphore) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with PrivateKey

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

the class ContractTest method checkFitTestnetCriteria.

@Test
public void checkFitTestnetCriteria() throws Exception {
    PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
    Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
    contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
    contract.addSignerKey(key);
    sealCheckTrace(contract, true);
    System.out.println("Processing cost is " + contract.getProcessedCostTU());
    assertTrue(contract.isSuitableForTestnet());
    // now set contract limited for testnet
    contract.setLimitedForTestnet(true);
    sealCheckTrace(contract, true);
    assertTrue(contract.isSuitableForTestnet());
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) 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