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)));
}
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;
}
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);
}
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));
}
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;
}
Aggregations