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