Search in sources :

Example 36 with Transaction

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());
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 37 with Transaction

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());
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 38 with Transaction

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);
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) BridgeConstants(co.rsk.config.BridgeConstants) Constants(org.ethereum.config.Constants) HashMapDB(org.ethereum.datasource.HashMapDB) TransactionGateway(co.rsk.net.TransactionGateway) Test(org.junit.Test)

Example 39 with Transaction

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);
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 40 with Transaction

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());
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Aggregations

Transaction (org.ethereum.core.Transaction)257 Test (org.junit.Test)166 Block (org.ethereum.core.Block)73 RskAddress (co.rsk.core.RskAddress)69 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)57 InternalTransaction (org.ethereum.vm.program.InternalTransaction)57 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)39 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)39 BigInteger (java.math.BigInteger)38 ArrayList (java.util.ArrayList)38 Repository (org.ethereum.core.Repository)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)32 ECKey (org.ethereum.crypto.ECKey)30 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)29 Keccak256 (co.rsk.crypto.Keccak256)28 Account (org.ethereum.core.Account)26 World (co.rsk.test.World)23 DslParser (co.rsk.test.dsl.DslParser)23 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)23 MutableRepository (org.ethereum.db.MutableRepository)22