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();
}
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();
}
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());
}
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;
}
Aggregations