Search in sources :

Example 51 with Hash

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

the class SnapshotTest method applyShouldFail.

@Test
public void applyShouldFail() throws Exception {
    Snapshot latestSnapshot = Snapshot.initialSnapshot.clone();
    Map<Hash, Long> badMap = new HashMap<>();
    badMap.put(new Hash("PSRQPWWIECDGDDZEHGJNMEVJNSVOSMECPPVRPEVRZFVIZYNNXZNTOTJOZNGCZNQVSPXBXTYUJUOXYASLS"), 100L);
    badMap.put(new Hash("ESRQPWWIECDGDDZEHGJNMEVJNSVOSMECPPVRPEVRZFVIZYNNXZNTOTJOZNGCZNQVSPXBXTYUJUOXYASLS"), -100L);
    Map<Hash, Long> patch = latestSnapshot.patchedDiff(badMap);
    assertFalse("should be inconsistent", Snapshot.isConsistent(latestSnapshot.patchedDiff(badMap)));
}
Also used : HashMap(java.util.HashMap) Hash(com.iota.iri.model.Hash) Test(org.junit.Test)

Example 52 with Hash

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

the class SnapshotTest method getModifiedMap.

private Map<Hash, Long> getModifiedMap() {
    Hash someHash = new Hash("PSRQPWWIECDGDDZXHGJNMEVJNSVOSMECPPVRPEVRZFVIZYNNXZNTOTJOZNGCZNQVSPXBXTYUJUOXYASLS");
    Map<Hash, Long> newMap;
    newMap = new HashMap<>();
    Iterator<Map.Entry<Hash, Long>> iterator = newMap.entrySet().iterator();
    Map.Entry<Hash, Long> entry;
    if (iterator.hasNext()) {
        entry = iterator.next();
        Long value = entry.getValue();
        Hash hash = entry.getKey();
        newMap.put(hash, 0L);
        newMap.put(someHash, value);
    }
    return newMap;
}
Also used : Hash(com.iota.iri.model.Hash) Map(java.util.Map) HashMap(java.util.HashMap)

Example 53 with Hash

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

the class TipsManagerTest method updateLinearRatingsTestWorks.

@Test
public void updateLinearRatingsTestWorks() throws Exception {
    TransactionViewModel transaction, transaction1, transaction2;
    transaction = new TransactionViewModel(getRandomTransactionTrits(), getRandomTransactionHash());
    transaction1 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction.getHash(), transaction.getHash()), getRandomTransactionHash());
    transaction2 = new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(transaction1.getHash(), transaction1.getHash()), getRandomTransactionHash());
    transaction.store(tangle);
    transaction1.store(tangle);
    transaction2.store(tangle);
    Map<Hash, Set<Hash>> ratings = new HashMap<>();
    tipsManager.updateHashRatings(transaction.getHash(), ratings, new HashSet<>());
    Assert.assertEquals(ratings.get(transaction.getHash()).size(), 3);
    Assert.assertEquals(ratings.get(transaction1.getHash()).size(), 2);
    Assert.assertEquals(ratings.get(transaction2.getHash()).size(), 1);
}
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 54 with Hash

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

the class TipsManagerTest method updateRatingsSerialWorks2.

@Test
public void updateRatingsSerialWorks2() 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 - (i > 1 ? 2 : 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(12L));
}
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 55 with Hash

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

the class TipsManagerTest method ratingTime.

public long ratingTime(int size) throws Exception {
    Hash[] hashes = new Hash[size];
    hashes[0] = getRandomTransactionHash();
    new TransactionViewModel(getRandomTransactionTrits(), hashes[0]).store(tangle);
    Random random = new Random();
    for (int i = 1; i < hashes.length; i++) {
        hashes[i] = getRandomTransactionHash();
        new TransactionViewModel(getRandomTransactionWithTrunkAndBranch(hashes[i - random.nextInt(i) - 1], hashes[i - random.nextInt(i) - 1]), hashes[i]).store(tangle);
    }
    Map<Hash, Long> ratings = new HashMap<>();
    long start = System.currentTimeMillis();
    tipsManager.serialUpdateRatings(new HashSet<>(), hashes[0], ratings, new HashSet<>(), null);
    return System.currentTimeMillis() - start;
}
Also used : TransactionViewModel(com.iota.iri.controllers.TransactionViewModel) Hash(com.iota.iri.model.Hash) TransactionViewModelTest.getRandomTransactionHash(com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionHash)

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