Search in sources :

Example 81 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class BlockchainTest method blockchainTest.

@Test
public void blockchainTest() {
    Blockchain blockchain = createBlockchain();
    Assert.assertNotNull(blockchain);
    Block block = blockchain.getBestBlock();
    Assert.assertNotNull(block);
    Assert.assertEquals(0, block.getNumber());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) Test(org.junit.Test)

Example 82 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class BlockchainTest method tryToConnect.

@Test
public void tryToConnect() {
    Blockchain blockchain = createBlockchain();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2 = blockGenerator.createChildBlock(block1);
    Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 83 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class BridgePerformanceTestCase method execute.

private ExecutionTracker execute(ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, int executionIndex) {
    ExecutionTracker executionInfo = new ExecutionTracker(thread);
    RepositoryImpl repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider storageProvider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants);
    storageInitializer.initialize(storageProvider, track, executionIndex);
    try {
        storageProvider.save();
    } catch (Exception e) {
        throw new RuntimeException("Error trying to save the storage after initialization", e);
    }
    track.commit();
    Transaction tx = txBuilder.build(executionIndex);
    List<LogInfo> logs = new ArrayList<>();
    RepositoryTrackWithBenchmarking benchmarkerTrack = new RepositoryTrackWithBenchmarking(config, repository);
    Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
    Blockchain blockchain = BlockChainBuilder.ofSizeWithNoTransactionPoolCleaner(heightProvider.getHeight(executionIndex));
    bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockchain.getBlockStore(), null, logs);
    // Execute a random method so that bridge support initialization
    // does its initial writes to the repo for e.g. genesis block,
    // federation, etc, etc. and we don't get
    // those recorded in the actual execution.
    bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
    benchmarkerTrack.getStatistics().clear();
    executionInfo.startTimer();
    bridge.execute(abiEncoder.encode(executionIndex));
    executionInfo.endTimer();
    benchmarkerTrack.commit();
    executionInfo.setRepositoryStatistics(benchmarkerTrack.getStatistics());
    return executionInfo;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) Blockchain(org.ethereum.core.Blockchain) ArrayList(java.util.ArrayList) RepositoryTrackWithBenchmarking(co.rsk.db.RepositoryTrackWithBenchmarking) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) RepositoryImpl(co.rsk.db.RepositoryImpl) Bridge(co.rsk.peg.Bridge)

Example 84 with Blockchain

use of org.ethereum.core.Blockchain 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 85 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class Web3ImplSnapshotTest method revertToSnapshot.

@Test
public void revertToSnapshot() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Blockchain blockchain = world.getBlockChain();
    addBlocks(blockchain, 10);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    BlockChainStatus status = blockchain.getStatus();
    String snapshotId = web3.evm_snapshot();
    addBlocks(blockchain, 10);
    Assert.assertEquals(20, blockchain.getBestBlock().getNumber());
    Assert.assertTrue(web3.evm_revert(snapshotId));
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    BlockChainStatus newStatus = blockchain.getStatus();
    Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
    Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

Blockchain (org.ethereum.core.Blockchain)86 Test (org.junit.Test)75 Block (org.ethereum.core.Block)51 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)47 RskSystemProperties (co.rsk.config.RskSystemProperties)45 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)38 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)25 World (co.rsk.test.World)19 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)14 Keccak256 (co.rsk.crypto.Keccak256)7 Ignore (org.junit.Ignore)7 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)5 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)2 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)2 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)2 Repository (org.ethereum.core.Repository)2 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1