Search in sources :

Example 71 with HashMapDB

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);
}
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 72 with HashMapDB

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

Example 73 with HashMapDB

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);
}
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 74 with HashMapDB

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());
}
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 75 with HashMapDB

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"));
}
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

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12