Search in sources :

Example 1 with Curl

use of com.iota.iri.hash.Curl 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)

Aggregations

TransactionViewModel (com.iota.iri.controllers.TransactionViewModel)1 TransactionViewModelTest.getRandomTransactionTrits (com.iota.iri.controllers.TransactionViewModelTest.getRandomTransactionTrits)1 Curl (com.iota.iri.hash.Curl)1 Sponge (com.iota.iri.hash.Sponge)1 SpongeFactory (com.iota.iri.hash.SpongeFactory)1 Hash (com.iota.iri.model.Hash)1 Transaction (com.iota.iri.model.Transaction)1 RocksDBPersistenceProvider (com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider)1 Converter (com.iota.iri.utils.Converter)1 Arrays (java.util.Arrays)1 Random (java.util.Random)1 Set (java.util.Set)1 After (org.junit.After)1 Before (org.junit.Before)1 Test (org.junit.Test)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1