use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class EthModuleTest method sendTransactionWithGasLimitTest.
@Test
public void sendTransactionWithGasLimitTest() {
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
RskAddress sender = wallet.addAccount();
RskAddress receiver = wallet.addAccount();
// Hash of the expected transaction
CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
Transaction tx = TransactionFactoryHelper.createTransaction(args, constants.getChainId(), wallet.getAccount(sender));
String txExpectedResult = tx.getHash().toJsonString();
TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
TransactionGateway transactionGateway = mock(TransactionGateway.class);
when(transactionGateway.receiveTransaction(any(Transaction.class))).thenReturn(transactionPoolAddResult);
TransactionPool transactionPool = mock(TransactionPool.class);
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPool, transactionGateway);
// Hash of the actual transaction builded inside the sendTransaction
String txResult = ethModuleTransaction.sendTransaction(args);
assertEquals(txExpectedResult, txResult);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class EthModuleTest method sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException.
@Test
public void sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException() {
// Given
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
TransactionPool transactionPoolMock = mock(TransactionPool.class);
TransactionGateway transactionGatewayMock = mock(TransactionGateway.class);
CallArguments argsMock = mock(CallArguments.class);
RskAddress addressFrom = new RskAddress(new ECKey().getAddress());
// Address not in wallet
doReturn(addressFrom.toJsonString()).when(argsMock).getFrom();
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPoolMock, transactionGatewayMock);
// Then
try {
ethModuleTransaction.sendTransaction(argsMock);
fail("RskJsonRpcRequestException should be thrown");
} catch (RskJsonRpcRequestException ex) {
verify(argsMock, times(2)).getFrom();
assertEquals("Could not find account for address: " + addressFrom.toJsonString(), ex.getMessage());
}
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class DebugModuleImplTest method debug_traceTransaction_retrieveSimpleContractInvocationTrace.
@Test
public void debug_traceTransaction_retrieveSimpleContractInvocationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts02.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx02");
DebugModuleImpl debugModule = new DebugModuleImpl(world.getBlockStore(), receiptStore, messageHandler, world.getBlockExecutor());
JsonNode result = debugModule.traceTransaction(transaction.getHash().toJsonString(), null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isObject());
ObjectNode oResult = (ObjectNode) result;
Assert.assertTrue(oResult.get("error").textValue().isEmpty());
Assert.assertTrue(oResult.get("result").textValue().isEmpty());
JsonNode structLogs = oResult.get("structLogs");
Assert.assertTrue(structLogs.isArray());
Assert.assertTrue(structLogs.size() > 0);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class TraceModuleImplTest method executeContractWithCreate2.
@Test
public void executeContractWithCreate2() throws Exception {
DslParser parser = DslParser.fromResource("dsl/create201.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx01");
TraceModuleImpl traceModule = new TraceModuleImpl(world.getBlockChain(), world.getBlockStore(), receiptStore, world.getBlockExecutor());
JsonNode result = traceModule.traceTransaction(transaction.getHash().toJsonString());
Assert.assertNotNull(result);
Assert.assertTrue(result.isArray());
ArrayNode aresult = (ArrayNode) result;
Assert.assertEquals(2, aresult.size());
Assert.assertTrue(result.get(0).isObject());
ObjectNode oresult = (ObjectNode) result.get(1);
Assert.assertNotNull(oresult.get("action"));
Assert.assertNotNull(oresult.get("action").get("creationMethod"));
Assert.assertEquals("\"create2\"", oresult.get("action").get("creationMethod").toString());
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class TraceModuleImplTest method retrieveSimpleContractCreationTrace.
@Test
public void retrieveSimpleContractCreationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts01.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx01");
TraceModuleImpl traceModule = new TraceModuleImpl(world.getBlockChain(), world.getBlockStore(), receiptStore, world.getBlockExecutor());
JsonNode result = traceModule.traceTransaction(transaction.getHash().toJsonString());
Assert.assertNotNull(result);
Assert.assertTrue(result.isArray());
ArrayNode aresult = (ArrayNode) result;
Assert.assertEquals(1, aresult.size());
Assert.assertTrue(result.get(0).isObject());
ObjectNode oresult = (ObjectNode) result.get(0);
Assert.assertNotNull(oresult.get("type"));
Assert.assertEquals("\"create\"", oresult.get("type").toString());
Assert.assertNotNull(oresult.get("action"));
Assert.assertNull(oresult.get("action").get("creationMethod"));
Assert.assertNotNull(oresult.get("action").get("init"));
Assert.assertNull(oresult.get("action").get("input"));
}
Aggregations