use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method sendRawTransactionWithAutoMining.
@Test
public void sendRawTransactionWithAutoMining() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, true, world.getBlockTxSignatureCache(), transactionGateway);
String txHash = sendRawTransaction(web3);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, txHash);
// Transaction tx must be in the block mined.
Assert.assertEquals(txHash, txInBlock.getHash().toJsonString());
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method sendTransactionMustBeMined.
@Test
public void sendTransactionMustBeMined() {
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, true, world.getBlockTxSignatureCache(), transactionGateway);
String tx = sendTransaction(web3, repository);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
// Transaction tx must be in the block mined.
Assert.assertEquals(tx, txInBlock.getHash().toJsonString());
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method sendRawTransactionWithoutAutoMining.
@Test
public void sendRawTransactionWithoutAutoMining() {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
String txHash = sendRawTransaction(web3);
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
Assert.assertEquals(1, transactionPool.getPendingTransactions().size());
Assert.assertEquals(txHash, transactionPool.getPendingTransactions().get(0).getHash().toJsonString());
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class SyncProcessorTest method processBodyResponseWithTransactionAddsToBlockchain.
@Test
public void processBodyResponseWithTransactionAddsToBlockchain() {
Account senderAccount = createAccount("sender");
Account receiverAccount = createAccount("receiver");
Map<RskAddress, AccountState> accounts = new HashMap<>();
accounts.put(senderAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.valueOf(20000000)));
accounts.put(receiverAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.ZERO));
final NetBlockStore store = new NetBlockStore();
BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
Blockchain blockchain = blockChainBuilder.ofSize(0, false, accounts);
Block genesis = blockchain.getBestBlock();
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
List<Transaction> txs = Collections.singletonList(createTransaction(senderAccount, receiverAccount, BigInteger.valueOf(1000000), BigInteger.ZERO));
Block block = new BlockGenerator().createChildBlock(genesis, txs, blockChainBuilder.getRepository().getRoot());
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(blockChainBuilder.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockChainBuilder.getBlockStore(), null, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
Assert.assertEquals(1, block.getTransactionsList().size());
blockExecutor.executeAndFillAll(block, genesis.getHeader());
Assert.assertEquals(21000, block.getFeesPaidToMiner().asBigInteger().intValueExact());
Assert.assertEquals(1, block.getTransactionsList().size());
Assert.assertEquals(1, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
List<Transaction> transactions = block.getTransactionsList();
List<BlockHeader> uncles = block.getUncleList();
long lastRequestId = new Random().nextLong();
BodyResponseMessage response = new BodyResponseMessage(lastRequestId, transactions, uncles);
processor.registerExpectedMessage(response);
Deque<BlockHeader> headerStack = new ArrayDeque<>();
headerStack.add(block.getHeader());
List<Deque<BlockHeader>> headers = new ArrayList<>();
headers.add(headerStack);
List<BlockIdentifier> bids = new ArrayList<>();
bids.add(new BlockIdentifier(blockchain.getBlockByNumber(0).getHash().getBytes(), 0));
bids.add(new BlockIdentifier(block.getHash().getBytes(), 1));
processor.startDownloadingBodies(headers, Collections.singletonMap(sender, bids), sender);
((DownloadingBodiesSyncState) processor.getSyncState()).expectBodyResponseFor(lastRequestId, sender.getPeerNodeID(), block.getHeader());
processor.processBodyResponse(sender, response);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class BlockToMineBuilderTest method setUp.
@Before
public void setUp() {
validationRules = mock(BlockValidationRule.class);
RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
StateRootHandler stateRootHandler = mock(StateRootHandler.class);
MiningConfig miningConfig = mock(MiningConfig.class);
DifficultyCalculator difficultyCalculator = mock(DifficultyCalculator.class);
MinimumGasPriceCalculator minimumGasPriceCalculator = mock(MinimumGasPriceCalculator.class);
MinerUtils minerUtils = mock(MinerUtils.class);
activationConfig = mock(ActivationConfig.class);
blockExecutor = mock(BlockExecutor.class);
blockBuilder = new BlockToMineBuilder(activationConfig, miningConfig, repositoryLocator, mock(BlockStore.class), mock(TransactionPool.class), difficultyCalculator, new GasLimitCalculator(Constants.mainnet()), new ForkDetectionDataCalculator(), validationRules, mock(MinerClock.class), new BlockFactory(activationConfig), blockExecutor, minimumGasPriceCalculator, minerUtils);
BlockDifficulty blockDifficulty = mock(BlockDifficulty.class);
Repository snapshot = mock(Repository.class);
GasLimitConfig gasLimitConfig = new GasLimitConfig(0, 0, false);
when(minerUtils.getAllTransactions(any())).thenReturn(new ArrayList<>());
when(minerUtils.filterTransactions(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
when(repositoryLocator.snapshotAt(any())).thenReturn(snapshot);
when(minimumGasPriceCalculator.calculate(any())).thenReturn(mock(Coin.class));
when(stateRootHandler.translate(any())).thenReturn(TestUtils.randomHash());
when(miningConfig.getGasLimit()).thenReturn(gasLimitConfig);
when(miningConfig.getUncleListLimit()).thenReturn(10);
when(miningConfig.getCoinbaseAddress()).thenReturn(TestUtils.randomAddress());
when(difficultyCalculator.calcDifficulty(any(), any())).thenReturn(blockDifficulty);
}
Aggregations