use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.
the class ReceiptStoreImplTest method getUnknownTransactionByBlock.
@Test
public void getUnknownTransactionByBlock() {
TransactionReceipt receipt = createReceipt();
Keccak256 blockHash = TestUtils.randomHash();
Optional<TransactionInfo> resultOpt = store.get(receipt.getTransaction().getHash().getBytes(), blockHash.getBytes());
Assert.assertFalse(resultOpt.isPresent());
}
use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.
the class ReceiptStoreImplTest method addAndGetTransactionWith128AsIndex.
@Test
public void addAndGetTransactionWith128AsIndex() {
TransactionReceipt receipt = createReceipt();
byte[] blockHash = Hex.decode("0102030405060708");
store.add(blockHash, 128, receipt);
TransactionInfo result = store.get(receipt.getTransaction().getHash().getBytes(), blockHash).orElse(null);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getBlockHash());
Assert.assertArrayEquals(blockHash, result.getBlockHash());
Assert.assertEquals(128, result.getIndex());
Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
}
use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.
the class ReceiptStoreImplTest method addTwoTransactionsAndGetTransactionByFirstBlock.
@Test
public void addTwoTransactionsAndGetTransactionByFirstBlock() {
TransactionReceipt receipt0 = createReceipt();
Keccak256 blockHash0 = new Keccak256("0102030405060708090000000000000000000000000000000000000000000000");
store.add(blockHash0.getBytes(), 3, receipt0);
TransactionReceipt receipt = createReceipt();
Keccak256 blockHash = new Keccak256("0102030405060708000000000000000000000000000000000000000000000000");
store.add(blockHash.getBytes(), 42, receipt);
Optional<TransactionInfo> resultOpt = store.get(receipt.getTransaction().getHash().getBytes(), blockHash0.getBytes());
TransactionInfo result = resultOpt.get();
Assert.assertNotNull(result.getBlockHash());
Assert.assertArrayEquals(blockHash0.getBytes(), result.getBlockHash());
Assert.assertEquals(3, result.getIndex());
Assert.assertArrayEquals(receipt0.getEncoded(), result.getReceipt().getEncoded());
}
use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.
the class ReceiptStoreImplTest method addAndGetTransaction.
@Test
public void addAndGetTransaction() {
TransactionReceipt receipt = createReceipt();
byte[] blockHash = Hex.decode("0102030405060708");
store.add(blockHash, 42, receipt);
TransactionInfo result = store.get(receipt.getTransaction().getHash().getBytes(), blockHash).orElse(null);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getBlockHash());
Assert.assertArrayEquals(blockHash, result.getBlockHash());
Assert.assertEquals(42, result.getIndex());
Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
}
use of org.ethereum.core.TransactionReceipt 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);
}
Aggregations