Search in sources :

Example 56 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TipsManagerTest method updateRatingsSerialWorks.

@Test
public void updateRatingsSerialWorks() throws Exception {
    Hash[] hashes = new Hash[5];
    hashes[0] = getRandomTransactionHash();
    new TransactionViewModel(getRandomTransactionTrits(), hashes[0]).store(tangle);
    for (int i = 1; i < hashes.length; i++) {
        hashes[i] = getRandomTransactionHash();
        new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hashes[i - 1], hashes[i - 1]), hashes[i]).store(tangle);
    }
    Map<Hash, Long> ratings = new HashMap<>();
    tipsManager.recursiveUpdateRatings(hashes[0], ratings, new HashSet<>());
    Assert.assertTrue(ratings.get(hashes[0]).equals(5L));
}
Also used : TransactionViewModel(com.iota.iri.controllers.TransactionViewModel) Hash(com.iota.iri.model.Hash) TransactionViewModelTest.getRandomTransactionHash(com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionHash) Test(org.junit.Test)

Example 57 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class ISSTest method generateNAddressesForSeed.

// @Test
public void generateNAddressesForSeed() throws Exception {
    int nof = 2;
    System.out.println("seed,address_0,address_1,address_2,address_3");
    for (int i = 0; i < 1000; i++) {
        Hash seed = getRandomTransactionHash();
        SpongeFactory.Mode mode = SpongeFactory.Mode.KERL;
        Hash[] addresses = new Hash[4];
        for (int j = 0; j < 4; j++) {
            int[] subseed = ISS.subseed(mode, seed.trits(), j);
            int[] key = ISS.key(mode, subseed, nof);
            int[] digest = ISS.digests(mode, key);
            int[] address = ISS.address(mode, digest);
            addresses[j] = new Hash(address);
        }
        System.out.println(String.format("%s,%s,%s,%s,%s", seed, addresses[0], addresses[1], addresses[2], addresses[3]));
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 58 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class TransactionRequesterTest method nonMilestoneCapacityLimited.

@Test
public void nonMilestoneCapacityLimited() throws Exception {
    TransactionRequester txReq = new TransactionRequester(tangle, mq);
    int capacity = TransactionRequester.MAX_TX_REQ_QUEUE_SIZE;
    // fill tips list
    for (int i = 0; i < capacity * 2; i++) {
        Hash hash = TransactionViewModelTest.getRandomTransactionHash();
        txReq.requestTransaction(hash, false);
    }
    // check that limit wasn't breached
    assertEquals(capacity, txReq.numberOfTransactionsToRequest());
}
Also used : TransactionRequester(com.iota.iri.network.TransactionRequester) Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

Example 59 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class KerlTest method generateTrytesAndHashes.

// @Test
public void generateTrytesAndHashes() throws Exception {
    System.out.println("trytes,Kerl_hash");
    for (int i = 0; i < 10000; i++) {
        Hash trytes = getRandomTransactionHash();
        int[] initial_value = trytes.trits();
        Sponge k = SpongeFactory.create(SpongeFactory.Mode.KERL);
        k.absorb(initial_value, 0, initial_value.length);
        int[] hash_value = new int[Curl.HASH_LENGTH];
        k.squeeze(hash_value, 0, hash_value.length);
        String hash = Converter.trytes(hash_value);
        System.out.println(String.format("%s,%s", trytes, hash));
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 60 with Hash

use of com.iota.iri.model.Hash in project iri by iotaledger.

the class KerlTest method benchmarkCurl.

// @Test
public void benchmarkCurl() {
    int i;
    Hash hash;
    long start, diff;
    long maxdiff = 0, sumdiff = 0, subSumDiff = 0;
    // was 10000;
    int max = 100;
    int interval = 1000;
    String test = "curl";
    for (i = 0; i++ < max; ) {
        // pre
        int size = 8019;
        int[] in_trits = getRandomTrits(size);
        int[] hash_trits = new int[Curl.HASH_LENGTH];
        start = System.nanoTime();
        // measured
        // Curl curl;
        // curl = new Curl();
        // curl.absorb(in_trits, 0, in_trits.length);
        // curl.squeeze(hash_trits, 0, Curl.HASH_LENGTH);
        Kerl kerl;
        kerl = new Kerl();
        kerl.absorb(in_trits, 0, in_trits.length);
        kerl.squeeze(hash_trits, 0, Curl.HASH_LENGTH);
        diff = System.nanoTime() - start;
        // post
        String out_trytes = Converter.trytes(hash_trits);
        sumdiff += diff;
        subSumDiff += diff;
        if (diff > maxdiff) {
            maxdiff = diff;
        }
        if (i % interval == 0) {
        // log.info("{}", new String(new char[(int) ((diff / 10000))]).replace('\0', '|'));
        }
        if (i % interval == 0) {
            log.info("Run time for {}: {} us.\tInterval Time: {} us.\tMax time per iter: {} us. \tAverage: {} us.\t Total time: {} us.", i, (diff / 1000), subSumDiff / 1000, (maxdiff / 1000), sumdiff / i / 1000, sumdiff / 1000);
            subSumDiff = 0;
            maxdiff = 0;
        }
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Aggregations

Hash (com.iota.iri.model.Hash)75 Test (org.junit.Test)16 TransactionViewModel (com.iota.iri.controllers.TransactionViewModel)12 RocksDBPersistenceProviderTest (com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)12 HttpString (io.undertow.util.HttpString)8 TransactionViewModelTest.getRandomTransactionHash (com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionHash)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Curl (com.iota.iri.hash.Curl)3 PearlDiver (com.iota.iri.hash.PearlDiver)3 TransactionRequester (com.iota.iri.network.TransactionRequester)3 Converter (com.iota.iri.utils.Converter)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 com.iota.iri (com.iota.iri)2 Configuration (com.iota.iri.conf.Configuration)2 DefaultConfSettings (com.iota.iri.conf.Configuration.DefaultConfSettings)2