Search in sources :

Example 6 with TransactionReceipt

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());
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 7 with TransactionReceipt

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());
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) Test(org.junit.Test)

Example 8 with TransactionReceipt

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());
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 9 with TransactionReceipt

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());
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) Test(org.junit.Test)

Example 10 with TransactionReceipt

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

Aggregations

TransactionReceipt (org.ethereum.core.TransactionReceipt)39 Test (org.junit.Test)30 Block (org.ethereum.core.Block)17 Transaction (org.ethereum.core.Transaction)15 Keccak256 (co.rsk.crypto.Keccak256)13 World (co.rsk.test.World)13 TransactionInfo (org.ethereum.db.TransactionInfo)10 RskAddress (co.rsk.core.RskAddress)8 CallArguments (org.ethereum.rpc.CallArguments)8 ArrayList (java.util.ArrayList)7 EthModuleTestUtils (org.ethereum.util.EthModuleTestUtils)7 LogInfo (org.ethereum.vm.LogInfo)7 BigInteger (java.math.BigInteger)6 Bloom (org.ethereum.core.Bloom)6 ProgramResult (org.ethereum.vm.program.ProgramResult)6 TestSystemProperties (co.rsk.config.TestSystemProperties)5 DslParser (co.rsk.test.dsl.DslParser)4 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)4 Trie (co.rsk.trie.Trie)4 List (java.util.List)4