Search in sources :

Example 81 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class RskForksBridgeTest method callGetStateForDebuggingTx.

private BridgeState callGetStateForDebuggingTx() throws IOException {
    TestSystemProperties beforeBambooProperties = new TestSystemProperties();
    Transaction rskTx = CallTransaction.createRawTransaction(0, Long.MAX_VALUE, Long.MAX_VALUE, PrecompiledContracts.BRIDGE_ADDR, 0, Bridge.GET_STATE_FOR_DEBUGGING.encode(new Object[] {}), beforeBambooProperties.getNetworkConstants().getChainId());
    rskTx.sign(new byte[] {});
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(beforeBambooProperties, blockStore, null, new BlockFactory(beforeBambooProperties.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(beforeBambooProperties, world.getBridgeSupportFactory()), world.getBlockTxSignatureCache());
    Repository track = repository.startTracking();
    TransactionExecutor executor = transactionExecutorFactory.newInstance(rskTx, 0, blockChain.getBestBlock().getCoinbase(), track, blockChain.getBestBlock(), 0).setLocalCall(true);
    executor.executeTransaction();
    ProgramResult res = executor.getResult();
    Object[] result = Bridge.GET_STATE_FOR_DEBUGGING.decodeResult(res.getHReturn());
    ActivationConfig.ForBlock activations = beforeBambooProperties.getActivationConfig().forBlock(blockChain.getBestBlock().getNumber());
    return BridgeState.create(beforeBambooProperties.getNetworkConstants().getBridgeConstants(), (byte[]) result[0], activations);
}
Also used : ProgramResult(org.ethereum.vm.program.ProgramResult) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 82 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class GitHubBlockTest method runHomestead.

private void runHomestead(String name) throws IOException, ParseException {
    String json = JSONReader.loadJSONFromCommit("BlockchainTests/Homestead/" + name + ".json", shacommit);
    TestSystemProperties config = new TestSystemProperties();
    GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET);
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 83 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class GitHubBlockTest method runSingleTest.

// test for conveniently running a single test
@Ignore
@Test
public void runSingleTest() throws ParseException, IOException {
    TestSystemProperties config = new TestSystemProperties();
    config.setGenesisInfo("frontier.json");
    String json = JSONReader.loadJSONFromCommit("BlockchainTests/Homestead/bcTotalDifficultyTest.json", shacommit);
    GitHubJSONTestSuite.runGitHubJsonSingleBlockTest(json, "sideChainWithNewMaxDifficultyStartingFromBlock3AfterBlock4");
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 84 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class CliToolsTest method rewindBlocks.

@Test
public void rewindBlocks() {
    TestSystemProperties config = new TestSystemProperties();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    KeyValueDataSource keyValueDataSource = new HashMapDB();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(blockFactory, keyValueDataSource, new HashMapBlocksIndex());
    int blocksToGenerate = 14;
    Keccak256 parentHash = Keccak256.ZERO_HASH;
    for (long i = 0; i < blocksToGenerate; i++) {
        Block block = mock(Block.class);
        Keccak256 blockHash = randomHash();
        when(block.getHash()).thenReturn(blockHash);
        when(block.getParentHash()).thenReturn(parentHash);
        when(block.getNumber()).thenReturn(i);
        when(block.getEncoded()).thenReturn(TestUtils.randomBytes(128));
        indexedBlockStore.saveBlock(block, ZERO, true);
        parentHash = blockHash;
    }
    Block bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is((long) blocksToGenerate - 1));
    RskContext rskContext = mock(RskContext.class);
    doReturn(indexedBlockStore).when(rskContext).getBlockStore();
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    doReturn(Optional.of(mock(RepositorySnapshot.class))).when(repositoryLocator).findSnapshotAt(any());
    doReturn(repositoryLocator).when(rskContext).getRepositoryLocator();
    NodeStopper stopper = mock(NodeStopper.class);
    StringBuilder output = new StringBuilder();
    RewindBlocks rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "fmi" }, () -> rskContext, stopper);
    String data = output.toString();
    Assert.assertTrue(data.contains("No inconsistent block has been found"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    long blockToRewind = blocksToGenerate / 2;
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { String.valueOf(blockToRewind) }, () -> rskContext, stopper);
    bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is(blockToRewind));
    data = output.toString();
    Assert.assertTrue(data.contains("New highest block number stored in db: " + blockToRewind));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { String.valueOf(blocksToGenerate + 1) }, () -> rskContext, stopper);
    bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is(blockToRewind));
    data = output.toString();
    Assert.assertTrue(data.contains("No need to rewind"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    doReturn(Optional.empty()).when(repositoryLocator).findSnapshotAt(any());
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "fmi" }, () -> rskContext, stopper);
    data = output.toString();
    Assert.assertTrue(data.contains("Min inconsistent block number: 0"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "rbc" }, () -> rskContext, stopper);
    data = output.toString();
    Assert.assertTrue(data.contains("Min inconsistent block number: 0"));
    Assert.assertTrue(data.contains("New highest block number stored in db: -1"));
    verify(stopper).stop(0);
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) RepositoryLocator(co.rsk.db.RepositoryLocator) RskContext(co.rsk.RskContext) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) NodeStopper(co.rsk.util.NodeStopper) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 85 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class ChannelManagerImplTest method blockAddressIsAvailable.

@Test
public void blockAddressIsAvailable() throws UnknownHostException {
    ChannelManagerImpl channelManagerImpl = new ChannelManagerImpl(new TestSystemProperties(), null);
    ;
    Assert.assertTrue(channelManagerImpl.isAddressBlockAvailable(InetAddress.getLocalHost()));
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Aggregations

TestSystemProperties (co.rsk.config.TestSystemProperties)158 Test (org.junit.Test)130 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)109 Blockchain (org.ethereum.core.Blockchain)78 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)75 SimplePeer (co.rsk.net.simples.SimplePeer)69 Block (org.ethereum.core.Block)69 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)56 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)23 EthereumListener (org.ethereum.listener.EthereumListener)23 BlockStore (org.ethereum.db.BlockStore)21 RskSystemProperties (co.rsk.config.RskSystemProperties)17 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)16 Keccak256 (co.rsk.crypto.Keccak256)13 RepositoryLocator (co.rsk.db.RepositoryLocator)10 World (co.rsk.test.World)10 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)9 Ignore (org.junit.Ignore)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)8