Search in sources :

Example 26 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class LogsNotificationEmitterTest method withTransactionInfo.

private void withTransactionInfo(Block block, Transaction transaction, LogInfo... logInfos) {
    TransactionInfo transactionInfo = mock(TransactionInfo.class);
    TransactionReceipt receipt = mock(TransactionReceipt.class);
    when(transactionInfo.getReceipt()).thenReturn(receipt);
    when(receipt.getLogInfoList()).thenReturn(Arrays.asList(logInfos));
    when(receiptStore.get(transaction.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(transactionInfo));
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) TransactionInfo(org.ethereum.db.TransactionInfo)

Example 27 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class LogsNotificationEmitter method getLogsNotifications.

private List<LogsNotification> getLogsNotifications(Block block, boolean removed) {
    List<LogsNotification> notifications = new ArrayList<>();
    for (int transactionIndex = 0; transactionIndex < block.getTransactionsList().size(); transactionIndex++) {
        Transaction transaction = block.getTransactionsList().get(transactionIndex);
        Optional<TransactionInfo> transactionInfoOpt = receiptStore.get(transaction.getHash().getBytes(), block.getHash().getBytes());
        if (!transactionInfoOpt.isPresent()) {
            logger.error("Missing receipt for transaction {} in block {}", transaction.getHash(), block.getHash());
            continue;
        }
        TransactionInfo transactionInfo = transactionInfoOpt.get();
        TransactionReceipt receipt = transactionInfo.getReceipt();
        List<LogInfo> logInfoList = receipt.getLogInfoList();
        for (int logIndex = 0; logIndex < logInfoList.size(); logIndex++) {
            LogInfo logInfo = logInfoList.get(logIndex);
            LogsNotification notification = new LogsNotification(logInfo, block, transactionIndex, transaction, logIndex, removed);
            notifications.add(notification);
        }
    }
    return notifications;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) TransactionReceipt(org.ethereum.core.TransactionReceipt) TransactionInfo(org.ethereum.db.TransactionInfo)

Example 28 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class EthModuleDSLTest method testCall_getRevertReason.

@Test
public void testCall_getRevertReason() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/eth_module/revert_reason.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("tx02");
    byte[] status = transactionReceipt.getStatus();
    Assert.assertNotNull(status);
    Assert.assertEquals(0, status.length);
    EthModule eth = EthModuleTestUtils.buildBasicEthModule(world);
    final Transaction tx01 = world.getTransactionByName("tx01");
    final CallArguments args = new CallArguments();
    // "6252703f5ba322ec64d3ac45e56241b7d9e481ad";
    args.setTo("0x" + tx01.getContractAddress().toHexString());
    // call to contract with param value = 0
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000000");
    args.setValue("0");
    args.setNonce("1");
    args.setGas("10000000");
    try {
        eth.call(args, "0x2");
        fail();
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("Negative value."));
    }
    // call to contract with param value = 1
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000001");
    final String call = eth.call(args, "0x2");
    assertEquals("0x", call);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) CallArguments(org.ethereum.rpc.CallArguments) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 29 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class ReceiptStoreImplTest method addFourTransactionsAndGetReceiptByBlockHashAndBestInChain.

@Test
public void addFourTransactionsAndGetReceiptByBlockHashAndBestInChain() {
    for (int i = 0; i < 4; i++) {
        TransactionReceipt receipt = createReceipt(i);
        Keccak256 blockHash = new Keccak256("01020304050607080900000000000000000000000000000000000000000000" + String.format("%02d", i));
        store.add(blockHash.getBytes(), i, receipt);
    }
    Block block = mock(Block.class);
    when(block.getNumber()).thenReturn(1L);
    BlockStore blockStore = mock(BlockStore.class);
    for (int i = 0; i < 4; i++) {
        TransactionReceipt receipt = createReceipt(i);
        Keccak256 blockHash = new Keccak256("01020304050607080900000000000000000000000000000000000000000000" + String.format("%02d", i));
        TransactionInfo result = store.get(receipt.getTransaction().getHash().getBytes(), blockHash.getBytes()).orElse(null);
        Assert.assertNotNull(result);
        Assert.assertNotNull(result.getBlockHash());
        Assert.assertArrayEquals(blockHash.getBytes(), result.getBlockHash());
        Assert.assertEquals(i, result.getIndex());
        Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
        when(blockStore.getBlockByHash(eq(blockHash.getBytes()))).thenReturn(block);
        when(blockStore.getChainBlockByNumber(1)).thenReturn(block);
        when(block.getHash()).thenReturn(blockHash);
        result = store.getInMainChain(receipt.getTransaction().getHash().getBytes(), blockStore).orElse(null);
        Assert.assertNotNull(result);
        Assert.assertNotNull(result.getBlockHash());
        Assert.assertArrayEquals(blockHash.getBytes(), result.getBlockHash());
        Assert.assertEquals(i, result.getIndex());
        Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
    }
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 30 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class ReceiptStoreImplTest method addAndGetTransactionWith238AsIndex.

@Test
public void addAndGetTransactionWith238AsIndex() {
    TransactionReceipt receipt = createReceipt();
    byte[] blockHash = Hex.decode("0102030405060708");
    store.add(blockHash, 238, 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(238, result.getIndex());
    Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) 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