Search in sources :

Example 21 with Hash

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

the class KerlTest method generateHashes.

// @Test
public void generateHashes() throws Exception {
    // System.out.println("trytes,Kerl_hash");
    for (int i = 0; i < 1_000_000; 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));
        System.out.println(String.format("%s", hash));
    }
}
Also used : Hash(com.iota.iri.model.Hash)

Example 22 with Hash

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

the class MilestoneViewModelTest method latest.

@Test
public void latest() throws Exception {
    int top = 100;
    Hash milestoneHash = new Hash("ZBCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999");
    MilestoneViewModel milestoneViewModel = new MilestoneViewModel(top, milestoneHash);
    milestoneViewModel.store(tangle);
    assertTrue(top == MilestoneViewModel.latest(tangle).index());
}
Also used : Hash(com.iota.iri.model.Hash) RocksDBPersistenceProviderTest(com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)

Example 23 with Hash

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

the class TangleTest method save.

@Test
public void save() throws Exception {
    Transaction transaction = new Transaction();
    Random r = new Random();
    int[] hash = new int[Curl.HASH_LENGTH], trits = Arrays.stream(new int[TransactionViewModel.TRINARY_SIZE]).map(i -> r.nextInt(3) - 1).toArray();
    Sponge curl = SpongeFactory.create(SpongeFactory.Mode.CURLP81);
    curl.absorb(trits, 0, trits.length);
    curl.squeeze(hash, 0, Curl.HASH_LENGTH);
    transaction.bytes = Converter.allocateBytesForTrits(trits.length);
    Converter.bytes(trits, transaction.bytes);
// assertTrue("Should be a new, unique transaction", !Tangle.instance().save(transaction).get());
}
Also used : Arrays(java.util.Arrays) RocksDBPersistenceProvider(com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider) Sponge(com.iota.iri.hash.Sponge) Set(java.util.Set) Test(org.junit.Test) Random(java.util.Random) Hash(com.iota.iri.model.Hash) SpongeFactory(com.iota.iri.hash.SpongeFactory) Converter(com.iota.iri.utils.Converter) TransactionViewModelTest.getRandomTransactionTrits(com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionTrits) Curl(com.iota.iri.hash.Curl) After(org.junit.After) Transaction(com.iota.iri.model.Transaction) TransactionViewModel(com.iota.iri.controllers.TransactionViewModel) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Transaction(com.iota.iri.model.Transaction) Random(java.util.Random) Sponge(com.iota.iri.hash.Sponge) Test(org.junit.Test)

Example 24 with Hash

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

the class MilestoneViewModelTest method snapshot.

@Test
public void snapshot() throws Exception {
    Hash milestoneHash = new Hash("BBCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUV99999");
    long value = 3;
    MilestoneViewModel milestoneViewModel = new MilestoneViewModel(++index, milestoneHash);
}
Also used : Hash(com.iota.iri.model.Hash) RocksDBPersistenceProviderTest(com.iota.iri.storage.rocksDB.RocksDBPersistenceProviderTest)

Example 25 with Hash

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

the class MilestoneViewModelTest method first.

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

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