Search in sources :

Example 1 with BlockStore

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

the class StateTestRunner method runImpl.

public List<String> runImpl() {
    logger.info("");
    repository = RepositoryBuilder.build(stateTestCase.getPre());
    logger.info("loaded repository");
    transaction = TransactionBuilder.build(stateTestCase.getTransaction());
    logger.info("transaction: {}", transaction.toString());
    BlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    blockchain = new BlockChainImpl(config, repository, blockStore, null, null, null, null, null);
    env = EnvBuilder.build(stateTestCase.getEnv());
    invokeFactory = new TestProgramInvokeFactory(env);
    block = BlockBuilder.build(env);
    block.setStateRoot(repository.getRoot());
    block.flushRLP();
    blockchain.setBestBlock(block);
    // blockchain.setProgramInvokeFactory(invokeFactory);
    // blockchain.startTracking();
    ProgramResult programResult = executeTransaction(transaction);
    repository.flushNoReconnect();
    List<LogInfo> origLogs = programResult.getLogInfoList();
    List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
    List<String> logsResult = LogsValidator.valid(origLogs, postLogs);
    Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false);
    logger.info("--------- POST Validation---------");
    List<String> outputResults = OutputValidator.valid(Hex.toHexString(programResult.getHReturn()), stateTestCase.getOut());
    List<String> results = new ArrayList<>();
    results.addAll(repoResults);
    results.addAll(logsResult);
    results.addAll(outputResults);
    for (String result : results) {
        logger.error(result);
    }
    logger.info("\n\n");
    return results;
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ProgramResult(org.ethereum.vm.program.ProgramResult) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) TestProgramInvokeFactory(org.ethereum.jsontestsuite.TestProgramInvokeFactory) Repository(org.ethereum.core.Repository)

Example 2 with BlockStore

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

the class BlockUnclesValidationRuleTest method rejectBlockWithSiblingUncle.

@Test
public void rejectBlockWithSiblingUncle() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle = blockGenerator.createChildBlock(block1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle.getHeader());
    Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();
    store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
    store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());
    Assert.assertFalse(rule.isValid(block));
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) BlockStore(org.ethereum.db.BlockStore) ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 3 with BlockStore

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

the class PrevMinGasPriceValidatorTest method validMGPInNewBlock.

@Test
public void validMGPInNewBlock() {
    Block block = Mockito.mock(Block.class);
    Block parent = Mockito.mock(Block.class);
    BlockStore blockStore = Mockito.mock(BlockStore.class);
    Mockito.when(block.getParentHash()).thenReturn(new Keccak256(PARENT_HASH));
    Mockito.when(block.getMinimumGasPrice()).thenReturn(BLOCK_MGP);
    Mockito.when(parent.getMinimumGasPrice()).thenReturn(PARENT_BLOCK_MGP);
    PrevMinGasPriceRule pmgpv = new PrevMinGasPriceRule();
    Assert.assertFalse(pmgpv.isValid(block, parent));
}
Also used : BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 4 with BlockStore

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

the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.

@Test
public void testLoadBlockchainEmptyBlockchain() throws IOException {
    String jsonFile = "blockchain_loader_genesis.json";
    RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
    Constants constants = Mockito.mock(Constants.class);
    Mockito.when(constants.getInitialNonce()).thenReturn(BigInteger.ZERO);
    BlockchainNetConfig blockchainNetConfig = Mockito.mock(BlockchainNetConfig.class);
    Mockito.when(blockchainNetConfig.getCommonConstants()).thenReturn(constants);
    Mockito.when(systemProperties.databaseDir()).thenReturn(new RskSystemProperties().databaseDir());
    Mockito.when(systemProperties.getBlockchainConfig()).thenReturn(blockchainNetConfig);
    Mockito.when(systemProperties.genesisInfo()).thenReturn(jsonFile);
    BlockStore blockStore = Mockito.mock(BlockStore.class);
    Mockito.when(blockStore.getBestBlock()).thenReturn(null);
    EthereumListener ethereumListener = Mockito.mock(EthereumListener.class);
    Repository repository = new RepositoryImpl(systemProperties, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
    ;
    BlockChainLoader blockChainLoader = new BlockChainLoader(systemProperties, repository, blockStore, null, null, ethereumListener, null, null);
    blockChainLoader.loadBlockchain();
    Assert.assertEquals(5, repository.getAccountsKeys().size());
    Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
    Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
    Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
    Assert.assertEquals(BigInteger.ZERO, repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
    Assert.assertEquals(Coin.valueOf(10), repository.getBalance(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
    Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
    Assert.assertEquals(DataWord.ONE, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ZERO));
    Assert.assertEquals(new DataWord(3), repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ONE));
    Assert.assertEquals(274, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).getCode().length);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) Constants(org.ethereum.config.Constants) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) BlockchainNetConfig(org.ethereum.config.BlockchainNetConfig) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 5 with BlockStore

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

the class BlockValidatorTest method processBlockWithInvalidPrevMGP.

@Test
public void processBlockWithInvalidPrevMGP() {
    BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
    Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
    Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
    Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).parent(parent).build();
    Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().blockStore(blockStore).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

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