Search in sources :

Example 1 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TransactionBuilderTest method buildValidRandomTransactions.

@Test
public void buildValidRandomTransactions() {
    List<String> randomTxsHashes = IntStream.range(0, 100).mapToObj(i -> new TransactionBuilder().buildRandomTransaction().getHash().toJsonString()).collect(Collectors.toList());
    Set<String> hashesWithoutDuplicates = randomTxsHashes.stream().collect(Collectors.toSet());
    Assert.assertEquals(randomTxsHashes.size(), hashesWithoutDuplicates.size());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Account(org.ethereum.core.Account) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder) Set(java.util.Set) Test(org.junit.Test) BigInteger(java.math.BigInteger) Transaction(org.ethereum.core.Transaction) Assert(org.junit.Assert) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) Test(org.junit.Test)

Example 2 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class BlockHashesHelperTest method calculateReceiptsTrieRootForDifferentTxHash.

@Test
public void calculateReceiptsTrieRootForDifferentTxHash() {
    World world = new World();
    // Creation of transactions
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx1 = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    Account acc3 = new AccountBuilder(world).name("acc3").balance(Coin.valueOf(2000000)).build();
    Account acc4 = new AccountBuilder().name("acc4").build();
    Transaction tx2 = new TransactionBuilder().sender(acc3).receiver(acc4).value(BigInteger.valueOf(500000)).build();
    Account acc5 = new AccountBuilder(world).name("acc5").balance(Coin.valueOf(2000000)).build();
    Account acc6 = new AccountBuilder().name("acc6").build();
    Transaction tx3 = new TransactionBuilder().sender(acc5).receiver(acc6).value(BigInteger.valueOf(800000)).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx1);
    txs.add(tx2);
    Block block = mock(Block.class);
    when(block.getTransactionsList()).thenReturn(txs);
    when(block.getHash()).thenReturn(new Keccak256(Hex.decode("0246c165ac839255aab76c1bc3df7842673ee3673e20dd908bba60862cf41326")));
    ReceiptStore receiptStore = mock(ReceiptStore.class);
    byte[] rskBlockHash = new byte[] { 0x2 };
    when(receiptStore.get(tx1.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    when(receiptStore.get(tx2.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    when(receiptStore.get(tx3.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    // Tx3 is not part of the transaction list of the block
    List<Trie> trie = BlockHashesHelper.calculateReceiptsTrieRootFor(block, receiptStore, tx3.getHash());
    assertNull(trie);
}
Also used : Account(org.ethereum.core.Account) ArrayList(java.util.ArrayList) TransactionReceipt(org.ethereum.core.TransactionReceipt) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) Keccak256(co.rsk.crypto.Keccak256) World(co.rsk.test.World) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) AccountBuilder(co.rsk.test.builders.AccountBuilder) Trie(co.rsk.trie.Trie) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 3 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TxPoolModuleImplTest method createSampleTransactionWithoutReceiver.

private Transaction createSampleTransactionWithoutReceiver() {
    Account sender = new AccountBuilder().name("sender").build();
    Transaction tx = new TransactionBuilder().sender(sender).value(BigInteger.TEN).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 4 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TxPoolModuleImplTest method createSampleTransaction.

private Transaction createSampleTransaction() {
    Account sender = new AccountBuilder().name("sender").build();
    Account receiver = new AccountBuilder().name("receiver").build();
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).value(BigInteger.TEN).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 5 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TransactionFactoryHelper method createSampleTransactionWithData.

public static Transaction createSampleTransactionWithData(int from, int nonce, String data) {
    Account sender = createAccount(from);
    Transaction tx = new TransactionBuilder().sender(sender).receiverAddress(new byte[0]).nonce(nonce).data(data).gasLimit(BigInteger.valueOf(1000000)).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Aggregations

TransactionBuilder (co.rsk.test.builders.TransactionBuilder)46 AccountBuilder (co.rsk.test.builders.AccountBuilder)41 Test (org.junit.Test)25 World (co.rsk.test.World)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 Account (org.ethereum.core.Account)17 BlockBuilder (co.rsk.test.builders.BlockBuilder)13 Transaction (org.ethereum.core.Transaction)12 ReceiptStore (org.ethereum.db.ReceiptStore)9 HashMapDB (org.ethereum.datasource.HashMapDB)6 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)6 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)5 BlockResultDTO (org.ethereum.rpc.dto.BlockResultDTO)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 Keccak256 (co.rsk.crypto.Keccak256)3 Trie (co.rsk.trie.Trie)3 Block (org.ethereum.core.Block)3 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2