Search in sources :

Example 21 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class Web3RskImplTest method web3_ext_dumpState.

@Test
public void web3_ext_dumpState() throws Exception {
    Rsk rsk = Mockito.mock(Rsk.class);
    Blockchain blockchain = Mockito.mock(Blockchain.class);
    NetworkStateExporter networkStateExporter = Mockito.mock(NetworkStateExporter.class);
    Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHash()).thenReturn(PegTestUtils.createHash3());
    Mockito.when(block.getNumber()).thenReturn(1L);
    BlockStore blockStore = Mockito.mock(BlockStore.class);
    Mockito.when(blockStore.getBestBlock()).thenReturn(block);
    Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
    Mockito.when(blockchain.getBestBlock()).thenReturn(block);
    Wallet wallet = WalletFactory.createWallet();
    RskSystemProperties config = new RskSystemProperties();
    PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
    EthModule em = new EthModule(config, blockchain, null, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, rsk, wallet, null));
    TxPoolModule tpm = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3RskImpl web3 = new Web3RskImpl(rsk, blockchain, Web3Mocks.getMockTransactionPool(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, tpm, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, networkStateExporter, blockStore, null, null, null, null, null);
    web3.ext_dumpState();
}
Also used : BlockStore(org.ethereum.db.BlockStore) EthModuleSolidityDisabled(co.rsk.rpc.modules.eth.EthModuleSolidityDisabled) Wallet(co.rsk.core.Wallet) Blockchain(org.ethereum.core.Blockchain) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) Rsk(co.rsk.core.Rsk) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) NetworkStateExporter(co.rsk.core.NetworkStateExporter) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) EthModule(co.rsk.rpc.modules.eth.EthModule) Block(org.ethereum.core.Block) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 22 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class Web3ImplTest method eth_coinbase.

@Test
public void eth_coinbase() {
    String originalCoinbase = "1dcc4de8dec75d7aab85b513f0a142fd40d49347";
    MinerServer minerServerMock = Mockito.mock(MinerServer.class);
    Mockito.when(minerServerMock.getCoinbaseAddress()).thenReturn(new RskAddress(originalCoinbase));
    Ethereum ethMock = Web3Mocks.getMockEthereum();
    Blockchain blockchain = Web3Mocks.getMockBlockchain();
    TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
    BlockStore blockStore = Web3Mocks.getMockBlockStore();
    RskSystemProperties mockProperties = Web3Mocks.getMockProperties();
    PersonalModule personalModule = new PersonalModuleWalletDisabled();
    Web3 web3 = new Web3Impl(ethMock, blockchain, transactionPool, blockStore, null, mockProperties, null, minerServerMock, personalModule, null, null, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null);
    Assert.assertEquals("0x" + originalCoinbase, web3.eth_coinbase());
    Mockito.verify(minerServerMock, Mockito.times(1)).getCoinbaseAddress();
}
Also used : BlockStore(org.ethereum.db.BlockStore) MinerServer(co.rsk.mine.MinerServer) Ethereum(org.ethereum.facade.Ethereum) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 23 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class Web3ImplTest method eth_mining.

@Test
public void eth_mining() {
    Ethereum ethMock = Web3Mocks.getMockEthereum();
    Blockchain blockchain = Web3Mocks.getMockBlockchain();
    TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
    BlockStore blockStore = Web3Mocks.getMockBlockStore();
    RskSystemProperties mockProperties = Web3Mocks.getMockProperties();
    MinerClient minerClient = new SimpleMinerClient();
    PersonalModule personalModule = new PersonalModuleWalletDisabled();
    TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3 web3 = new Web3Impl(ethMock, blockchain, transactionPool, blockStore, null, mockProperties, minerClient, null, personalModule, null, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null);
    Assert.assertTrue("Node is not mining", !web3.eth_mining());
    try {
        minerClient.mine();
        Assert.assertTrue("Node is mining", web3.eth_mining());
    } finally {
        minerClient.stop();
    }
    Assert.assertTrue("Node is not mining", !web3.eth_mining());
}
Also used : BlockStore(org.ethereum.db.BlockStore) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) MinerClient(co.rsk.mine.MinerClient) Ethereum(org.ethereum.facade.Ethereum) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 24 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class SnapshotManager method resetSnapshots.

public boolean resetSnapshots(Blockchain blockchain) {
    this.snapshots = new ArrayList<>();
    TransactionPool transactionPool = blockchain.getTransactionPool();
    long bestNumber = blockchain.getBestBlock().getNumber();
    BlockStore store = blockchain.getBlockStore();
    Block block = store.getChainBlockByNumber(0);
    BlockDifficulty difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash().getBytes());
    blockchain.setStatus(block, difficulty);
    // To clean pending state, first process the fork
    blockchain.getTransactionPool().processBest(block);
    // then, clear any reverted transaction
    transactionPool.removeTransactions(transactionPool.getPendingTransactions());
    transactionPool.removeTransactions(transactionPool.getQueuedTransactions());
    // Remove removed blocks from store
    for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= bestNumber; nb++) {
        blockchain.removeBlocksByNumber(nb);
    }
    return true;
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block)

Aggregations

BlockStore (org.ethereum.db.BlockStore)24 Test (org.junit.Test)20 Block (org.ethereum.core.Block)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)14 Keccak256 (co.rsk.crypto.Keccak256)7 ArrayList (java.util.ArrayList)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 BlockHeader (org.ethereum.core.BlockHeader)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)3 SimpleBlock (co.rsk.peg.simples.SimpleBlock)3 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)3 BlockBuilder (co.rsk.test.builders.BlockBuilder)3 BlockDifficulty (co.rsk.core.BlockDifficulty)2 RemascTransaction (co.rsk.remasc.RemascTransaction)2 PersonalModuleWalletDisabled (co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled)2 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)2 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)2 Repository (org.ethereum.core.Repository)2