use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TipsManagerTest method updateRatingsSerialWorks.
@Test
public void updateRatingsSerialWorks() 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 - 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(5L));
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class ISSTest method generateNAddressesForSeed.
// @Test
public void generateNAddressesForSeed() throws Exception {
int nof = 2;
System.out.println("seed,address_0,address_1,address_2,address_3");
for (int i = 0; i < 1000; i++) {
Hash seed = getRandomTransactionHash();
SpongeFactory.Mode mode = SpongeFactory.Mode.KERL;
Hash[] addresses = new Hash[4];
for (int j = 0; j < 4; j++) {
int[] subseed = ISS.subseed(mode, seed.trits(), j);
int[] key = ISS.key(mode, subseed, nof);
int[] digest = ISS.digests(mode, key);
int[] address = ISS.address(mode, digest);
addresses[j] = new Hash(address);
}
System.out.println(String.format("%s,%s,%s,%s,%s", seed, addresses[0], addresses[1], addresses[2], addresses[3]));
}
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class TransactionRequesterTest method nonMilestoneCapacityLimited.
@Test
public void nonMilestoneCapacityLimited() 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, false);
}
// check that limit wasn't breached
assertEquals(capacity, txReq.numberOfTransactionsToRequest());
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class KerlTest method generateTrytesAndHashes.
// @Test
public void generateTrytesAndHashes() throws Exception {
System.out.println("trytes,Kerl_hash");
for (int i = 0; i < 10000; i++) {
Hash trytes = getRandomTransactionHash();
int[] initial_value = trytes.trits();
Sponge k = SpongeFactory.create(SpongeFactory.Mode.KERL);
k.absorb(initial_value, 0, initial_value.length);
int[] hash_value = new int[Curl.HASH_LENGTH];
k.squeeze(hash_value, 0, hash_value.length);
String hash = Converter.trytes(hash_value);
System.out.println(String.format("%s,%s", trytes, hash));
}
}
use of com.iota.iri.model.Hash in project iri by iotaledger.
the class KerlTest method benchmarkCurl.
// @Test
public void benchmarkCurl() {
int i;
Hash hash;
long start, diff;
long maxdiff = 0, sumdiff = 0, subSumDiff = 0;
// was 10000;
int max = 100;
int interval = 1000;
String test = "curl";
for (i = 0; i++ < max; ) {
// pre
int size = 8019;
int[] in_trits = getRandomTrits(size);
int[] hash_trits = new int[Curl.HASH_LENGTH];
start = System.nanoTime();
// measured
// Curl curl;
// curl = new Curl();
// curl.absorb(in_trits, 0, in_trits.length);
// curl.squeeze(hash_trits, 0, Curl.HASH_LENGTH);
Kerl kerl;
kerl = new Kerl();
kerl.absorb(in_trits, 0, in_trits.length);
kerl.squeeze(hash_trits, 0, Curl.HASH_LENGTH);
diff = System.nanoTime() - start;
// post
String out_trytes = Converter.trytes(hash_trits);
sumdiff += diff;
subSumDiff += diff;
if (diff > maxdiff) {
maxdiff = diff;
}
if (i % interval == 0) {
// log.info("{}", new String(new char[(int) ((diff / 10000))]).replace('\0', '|'));
}
if (i % interval == 0) {
log.info("Run time for {}: {} us.\tInterval Time: {} us.\tMax time per iter: {} us. \tAverage: {} us.\t Total time: {} us.", i, (diff / 1000), subSumDiff / 1000, (maxdiff / 1000), sumdiff / i / 1000, sumdiff / 1000);
subSumDiff = 0;
maxdiff = 0;
}
}
}
Aggregations