Search in sources :

Example 66 with Hash

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

the class MilestoneViewModelTest method latestSnapshot.

@Test
public void latestSnapshot() throws Exception {
    int nosnapshot = 90;
    int topSnapshot = 80;
    int mid = 50;
    new MilestoneViewModel(nosnapshot, new Hash("FBCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999")).store(tangle);
    MilestoneViewModel milestoneViewModelmid = new MilestoneViewModel(mid, new Hash("GBCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999"));
    milestoneViewModelmid.store(tangle);
    MilestoneViewModel milestoneViewModeltopSnapshot = new MilestoneViewModel(topSnapshot, new Hash("GBCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999"));
    milestoneViewModeltopSnapshot.store(tangle);
// assertTrue(topSnapshot == MilestoneViewModel.latestWithSnapshot().index());
}
Also used : Hash(com.iota.iri.model.Hash) RocksDBPersistenceProviderTest(com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)

Example 67 with Hash

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

the class MilestoneViewModelTest method next.

@Test
public void next() throws Exception {
    int first = 1;
    int next = 2;
    MilestoneViewModel firstMilestone = new MilestoneViewModel(first, new Hash("99CDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999"));
    firstMilestone.store(tangle);
    new MilestoneViewModel(next, new Hash("9ACDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999")).store(tangle);
    assertTrue(next == MilestoneViewModel.first(tangle).next(tangle).index());
}
Also used : Hash(com.iota.iri.model.Hash) RocksDBPersistenceProviderTest(com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)

Example 68 with Hash

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

the class TransactionViewModelTest method findShouldBeSuccessful.

@Test
public void findShouldBeSuccessful() throws Exception {
    int[] trits = getRandomTransactionTrits();
    TransactionViewModel transactionViewModel = new TransactionViewModel(trits, Hash.calculate(SpongeFactory.Mode.CURLP81, trits));
    transactionViewModel.store(tangle);
    Hash hash = transactionViewModel.getHash();
    Assert.assertArrayEquals(TransactionViewModel.find(tangle, Arrays.copyOf(hash.bytes(), TransactionRequester.REQUEST_HASH_SIZE)).getBytes(), transactionViewModel.getBytes());
}
Also used : Hash(com.iota.iri.model.Hash)

Example 69 with Hash

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

the class TransactionViewModelTest method findShouldReturnNull.

@Test
public void findShouldReturnNull() throws Exception {
    int[] trits = getRandomTransactionTrits();
    TransactionViewModel transactionViewModel = new TransactionViewModel(trits, Hash.calculate(SpongeFactory.Mode.CURLP81, trits));
    trits = getRandomTransactionTrits();
    TransactionViewModel transactionViewModelNoSave = new TransactionViewModel(trits, Hash.calculate(SpongeFactory.Mode.CURLP81, trits));
    transactionViewModel.store(tangle);
    Hash hash = transactionViewModelNoSave.getHash();
    Assert.assertFalse(Arrays.equals(TransactionViewModel.find(tangle, Arrays.copyOf(hash.bytes(), TransactionRequester.REQUEST_HASH_SIZE)).getBytes(), transactionViewModel.getBytes()));
}
Also used : Hash(com.iota.iri.model.Hash)

Example 70 with Hash

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

the class TipsManager method transactionToApprove.

Hash transactionToApprove(final Set<Hash> visitedHashes, final Map<Hash, Long> diff, final Hash reference, final Hash extraTip, int depth, final int iterations, Random seed) throws Exception {
    long startTime = System.nanoTime();
    if (depth > maxDepth) {
        depth = maxDepth;
    }
    if (milestone.latestSolidSubtangleMilestoneIndex > Milestone.MILESTONE_START_INDEX || milestone.latestMilestoneIndex == Milestone.MILESTONE_START_INDEX) {
        Map<Hash, Long> ratings = new HashMap<>();
        Set<Hash> analyzedTips = new HashSet<>();
        Set<Hash> maxDepthOk = new HashSet<>();
        try {
            Hash tip = entryPoint(reference, extraTip, depth);
            serialUpdateRatings(visitedHashes, tip, ratings, analyzedTips, extraTip);
            analyzedTips.clear();
            if (ledgerValidator.updateDiff(visitedHashes, diff, tip)) {
                return markovChainMonteCarlo(visitedHashes, diff, tip, extraTip, ratings, iterations, milestone.latestSolidSubtangleMilestoneIndex - depth * 2, maxDepthOk, seed);
            } else {
                throw new RuntimeException("starting tip failed consistency check: " + tip.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("Encountered error: " + e.getLocalizedMessage());
            throw e;
        } finally {
            API.incEllapsedTime_getTxToApprove(System.nanoTime() - startTime);
        }
    }
    return null;
}
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