Search in sources :

Example 16 with Hash

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

the class TipsViewModelTest method totalCapacityLimited.

@Test
public void totalCapacityLimited() throws ExecutionException, InterruptedException {
    TipsViewModel tipsVM = new TipsViewModel();
    int capacity = TipsViewModel.MAX_TIPS;
    // fill tips list
    for (int i = 0; i <= capacity * 4; i++) {
        Hash hash = TransactionViewModelTest.getRandomTransactionHash();
        tipsVM.addTipHash(hash);
        if (i % 2 == 1) {
            tipsVM.setSolid(hash);
        }
    }
    // check that limit wasn't breached
    assertEquals(capacity * 2, tipsVM.size());
}
Also used : Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

Example 17 with Hash

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

the class ISSTest method addressGenerationISS.

@Test
public void addressGenerationISS() throws Exception {
    int index = 0;
    int nof = 2;
    SpongeFactory.Mode[] modes = { SpongeFactory.Mode.CURLP81, SpongeFactory.Mode.KERL };
    Hash[] hashes = { new Hash("D9XCNSCCAJGLWSQOQAQNFWANPYKYMCQ9VCOMROLDVLONPPLDFVPIZNAPVZLQMPFYJPAHUKIAEKNCQIYJZ"), new Hash("MDWYEJJHJDIUVPKDY9EACGDJUOP9TLYDWETUBOYCBLYXYYYJYUXYUTCTPTDGJYFKMQMCNZDQPTBE9AFIW") };
    for (int i = 0; i < modes.length; i++) {
        SpongeFactory.Mode mode = modes[i];
        int[] seedTrits = Converter.allocateTritsForTrytes(seed.length());
        Converter.trits(seed, seedTrits, 0);
        int[] subseed = ISS.subseed(mode, seedTrits, index);
        int[] key = ISS.key(mode, subseed, nof);
        int[] digest = ISS.digests(mode, key);
        int[] address = ISS.address(mode, digest);
        Hash addressTrytes = new Hash(address);
        assertEquals(hashes[i].toString(), addressTrytes.toString());
    }
}
Also used : Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

Example 18 with Hash

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

the class PearlDiverTest method testNoRandomFail.

@Test
@Ignore("to test pearlDiver iteratively")
public void testNoRandomFail() {
    for (int i = 0; i < 10000; i++) {
        int[] trits = TransactionViewModelTest.getRandomTransactionTrits();
        pearlDiver.search(trits, MIN_WEIGHT_MAGNITUDE, NUM_CORES);
        Hash hash = Hash.calculate(SpongeFactory.Mode.CURLP81, trits);
        for (int j = Hash.SIZE_IN_TRITS - 1; j > Hash.SIZE_IN_TRITS - MIN_WEIGHT_MAGNITUDE; j--) {
            assertEquals(hash.trits()[j], 0);
        }
        if (i % 100 == 0) {
            System.out.println(i + " successful hashes.");
        }
    }
}
Also used : Hash(com.iota.iri.model.Hash) Ignore(org.junit.Ignore) Test(org.junit.Test) TransactionViewModelTest(com.iota.iri.controllers.TransactionViewModelTest)

Example 19 with Hash

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

the class TransactionRequesterTest method milestoneCapacityNotLimited.

@Test
public void milestoneCapacityNotLimited() 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, true);
    }
    // check that limit was surpassed
    assertEquals(capacity * 2, txReq.numberOfTransactionsToRequest());
}
Also used : TransactionRequester(com.iota.iri.network.TransactionRequester) Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

Example 20 with Hash

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

the class TransactionRequesterTest method mixedCapacityLimited.

@Test
public void mixedCapacityLimited() 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 * 4; i++) {
        Hash hash = TransactionViewModelTest.getRandomTransactionHash();
        txReq.requestTransaction(hash, (i % 2 == 1));
    }
    // check that limit wasn't breached
    assertEquals(capacity + capacity * 2, txReq.numberOfTransactionsToRequest());
}
Also used : TransactionRequester(com.iota.iri.network.TransactionRequester) Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

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