use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class LogFilterTest method onlyOneEventAfterTwoBlocksWithEventAndFromLatestBlock.
@Test
public void onlyOneEventAfterTwoBlocksWithEventAndFromLatestBlock() {
RskTestFactory factory = new RskTestFactory();
Blockchain blockchain = factory.getBlockchain();
BlockStore blockStore = factory.getBlockStore();
RepositoryLocator repositoryLocator = factory.getRepositoryLocator();
Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain, blockStore, repositoryLocator, factory.getTrieStore());
Block block = blockchain.getBestBlock();
AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new RskAddress[0], null);
LogFilter filter = new LogFilter(atfilter, blockchain, true, true);
filter.newBlockReceived(block);
filter.newBlockReceived(block);
Object[] result = filter.getEvents();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.length);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class LogFilterTest method eventAfterBlockWithEvent.
@Test
public void eventAfterBlockWithEvent() {
RskTestFactory factory = new RskTestFactory();
Blockchain blockchain = factory.getBlockchain();
BlockStore blockStore = factory.getBlockStore();
RepositoryLocator repositoryLocator = factory.getRepositoryLocator();
Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain, blockStore, repositoryLocator, factory.getTrieStore());
Block block = blockchain.getBestBlock();
AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new RskAddress[0], null);
LogFilter filter = new LogFilter(atfilter, blockchain, false, true);
filter.newBlockReceived(block);
Object[] result = filter.getEvents();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.length);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method testGasEstimation.
@Test
public void testGasEstimation() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
BlockStore blockStore = world.getBlockStore();
BlockTxSignatureCache blockTxSignatureCache = world.getBlockTxSignatureCache();
ReceivedTxSignatureCache receivedTxSignatureCache = world.getReceivedTxSignatureCache();
TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutionFactoryWithProgramInvokeFactory(blockStore, null, blockTxSignatureCache);
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironmentGasExactimation(blockchain, trieStore, transactionPool, blockStore, transactionGateway, transactionExecutorFactory);
RskAddress srcAddr = new RskAddress(ECKey.fromPrivate(Keccak256Helper.keccak256("cow".getBytes())).getAddress());
// Create the transaction that creates the destination contract
sendContractCreationTransaction(srcAddr, web3, repository);
// Compute contract destination address
BigInteger nonce = repository.getAccountState(srcAddr).getNonce();
RskAddress contractAddress = new RskAddress(HashUtil.calcNewAddr(srcAddr.getBytes(), nonce.toByteArray()));
// start with 5M
int gasLimit = 5000000;
int consumed = checkEstimateGas(callCallWithValue, 33472, gasLimit, srcAddr, contractAddress, web3, repository);
// Now that I know the estimation, call again using the estimated value
// it should not fail. We set the gasLimit to the expected value plus 1 to
// differentiate between OOG and success.
int consumed2 = checkEstimateGas(callCallWithValue, 33472, consumed + 1, srcAddr, contractAddress, web3, repository);
Assert.assertEquals(consumed, consumed2);
consumed = checkEstimateGas(callUnfill, 46942, gasLimit, srcAddr, contractAddress, web3, repository);
consumed2 = checkEstimateGas(callUnfill, 46942, consumed + 1, srcAddr, contractAddress, web3, repository);
Assert.assertEquals(consumed, consumed2);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method sendTransactionMustNotBeMined.
@Test
public void sendTransactionMustNotBeMined() {
World world = new World();
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, null, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, null, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
String tx = sendTransaction(web3, repository);
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
// Transaction tx must not be in block
Assert.assertNull(txInBlock);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class ImportLightTest method createBlockchain.
public static BlockChainImpl createBlockchain(Genesis genesis, TestSystemProperties config, Repository repository, BlockStore blockStore, TrieStore trieStore) {
BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
CompositeEthereumListener listener = new TestCompositeEthereumListener();
KeyValueDataSource ds = new HashMapDB();
ds.init();
ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), null, blockTxSignatureCache);
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
RepositoryLocator repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repositoryLocator, null, blockFactory, listener, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, listener, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory), stateRootHandler);
blockchain.setNoValidation(true);
Repository track = repository.startTracking();
for (Map.Entry<RskAddress, AccountState> accountsEntry : genesis.getAccounts().entrySet()) {
RskAddress accountAddress = accountsEntry.getKey();
track.createAccount(accountAddress);
track.addBalance(accountAddress, accountsEntry.getValue().getBalance());
}
track.commit();
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
return blockchain;
}
Aggregations