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