use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TraceModuleImplTest method executeContractWithDelegateCall.
@Test
public void executeContractWithDelegateCall() throws Exception {
DslParser parser = DslParser.fromResource("dsl/delegatecall01.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Account delegateCallAccount = world.getAccountByName("delegatecall");
Account delegatedAccount = world.getAccountByName("delegated");
Assert.assertNotNull(delegateCallAccount);
Assert.assertNotNull(delegatedAccount);
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("callType"));
Assert.assertEquals("\"delegatecall\"", oresult.get("action").get("callType").toString());
Assert.assertEquals("\"" + delegatedAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("to").toString());
Assert.assertEquals("\"" + delegateCallAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("from").toString());
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TraceModuleImplTest method retrieveEmptyContractCreationTrace.
@Test
public void retrieveEmptyContractCreationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts09.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());
}
use of org.ethereum.core.Transaction 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.core.Transaction 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.core.Transaction 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());
}
Aggregations