Search in sources :

Example 36 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class RemascProcessMinerFeesTest method oneSiblingIncludedOneBlockLaterAndAnotherIncludedRightAfter.

@Test
public void oneSiblingIncludedOneBlockLaterAndAnotherIncludedRightAfter() {
    RskSystemProperties config = spy(new TestSystemProperties());
    when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.allBut(ConsensusRule.RSKIP85));
    BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config);
    List<SiblingElement> siblings = Arrays.asList(new SiblingElement(5, 6, this.minerFee), new SiblingElement(5, 7, this.minerFee));
    RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(this.minerFee).initialHeight(15).siblingElements(siblings).txSigningKey(this.cowKey).gasPrice(1L);
    testRunner.start();
    Blockchain blockchain = testRunner.getBlockChain();
    RepositoryLocator repositoryLocator = builder.getRepositoryLocator();
    RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
    Block blockAtHeightSix = blockchain.getBlockByNumber(7);
    assertEquals(Coin.valueOf(840L - 9L), testRunner.getAccountBalance(blockAtHeightSix.getCoinbase()));
    Block blockAtHeightSeven = blockchain.getBlockByNumber(8);
    assertEquals(Coin.valueOf(840L - 9L), testRunner.getAccountBalance(blockAtHeightSeven.getCoinbase()));
    Block blockAtHeightFiveMainchain = blockchain.getBlockByNumber(6);
    assertEquals(Coin.valueOf(5040L - 51L), testRunner.getAccountBalance(blockAtHeightFiveMainchain.getCoinbase()));
    Block blockAtHeightFiveFirstSibling = testRunner.getAddedSiblings().get(0);
    assertEquals(Coin.valueOf(5040L - 51L), testRunner.getAccountBalance(blockAtHeightFiveFirstSibling.getCoinbase()));
    Block blockAtHeightFiveSecondSibling = testRunner.getAddedSiblings().get(1);
    assertEquals(Coin.valueOf(4788L - 48L), testRunner.getAccountBalance(blockAtHeightFiveSecondSibling.getCoinbase()));
    this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.valueOf(84000L), Coin.valueOf(252L), 0L);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RepositorySnapshot(co.rsk.db.RepositorySnapshot) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 37 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class WorldDslProcessor method processBlockChainCommand.

private void processBlockChainCommand(DslCommand cmd) {
    Block parent = world.getBlockByName(cmd.getArgument(0));
    int k = 1;
    while (cmd.getArgument(k) != null) {
        String name = cmd.getArgument(k);
        int difficulty = k;
        if (name != null) {
            StringTokenizer difficultyTokenizer = new StringTokenizer(name, ":");
            name = difficultyTokenizer.nextToken();
            difficulty = difficultyTokenizer.hasMoreTokens() ? parseDifficulty(difficultyTokenizer.nextToken(), k) : k;
        }
        Block block = blockBuilder.difficulty(difficulty).parent(parent).build();
        final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(world.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, world.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, null, world.getBlockTxSignatureCache()));
        executor.executeAndFill(block, parent.getHeader());
        world.saveBlock(name, block);
        parent = block;
        k++;
    }
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) StringTokenizer(java.util.StringTokenizer) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 38 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class BlockchainVMTest method createNewBlockchain.

private static NewBlockChainInfo createNewBlockchain() {
    World world = new World();
    NewBlockChainInfo binfo = new NewBlockChainInfo();
    binfo.faucetKey = createFaucetAccount(world);
    binfo.blockchain = world.getBlockChain();
    binfo.repository = world.getRepository();
    binfo.repositoryLocator = new RepositoryLocator(world.getTrieStore(), world.getStateRootHandler());
    return binfo;
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) World(co.rsk.test.World)

Aggregations

RepositoryLocator (co.rsk.db.RepositoryLocator)38 Test (org.junit.Test)25 BlockStore (org.ethereum.db.BlockStore)21 RepositorySnapshot (co.rsk.db.RepositorySnapshot)18 BlockExecutor (co.rsk.core.bc.BlockExecutor)15 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 HashMapDB (org.ethereum.datasource.HashMapDB)10 TestSystemProperties (co.rsk.config.TestSystemProperties)9 Coin (co.rsk.core.Coin)7 World (co.rsk.test.World)7 RskAddress (co.rsk.core.RskAddress)6 StateRootHandler (co.rsk.db.StateRootHandler)6 TransactionGateway (co.rsk.net.TransactionGateway)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 TrieStore (co.rsk.trie.TrieStore)6 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)6 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5