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