use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.
@Test
public void testLoadBlockchainEmptyBlockchain() {
RskTestFactory objects = new RskTestFactory() {
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
}
};
// calls loadBlockchain
Blockchain blockchain = objects.getBlockchain();
RepositorySnapshot repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());
TestSystemProperties testSystemProperties = new TestSystemProperties();
ActivationConfig.ForBlock activations = testSystemProperties.getActivationConfig().forBlock(0);
int enabledPCCs = PrecompiledContracts.GENESIS_ADDRESSES.size();
for (ConsensusRule consensusRule : PrecompiledContracts.CONSENSUS_ENABLED_ADDRESSES.values()) {
if (activations.isActive(consensusRule)) {
enabledPCCs++;
}
}
int testAccountsSize = 3;
// PCCs + test accounts in blockchain_loader_genesis.json
int genesisAccountKeysSize = enabledPCCs + testAccountsSize;
Assert.assertEquals(genesisAccountKeysSize, repository.getAccountsKeys().size());
RskAddress daba01 = new RskAddress("dabadabadabadabadabadabadabadabadaba0001");
Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(daba01));
Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(daba01));
RskAddress daba02 = new RskAddress("dabadabadabadabadabadabadabadabadaba0002");
Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(daba02));
Assert.assertEquals(BigInteger.ZERO, repository.getNonce(daba02));
RskAddress address = new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051");
Assert.assertEquals(Coin.valueOf(10), repository.getBalance(address));
Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(address));
Assert.assertEquals(DataWord.ONE, repository.getStorageValue(address, DataWord.ZERO));
Assert.assertEquals(DataWord.valueOf(3), repository.getStorageValue(address, DataWord.ONE));
Assert.assertEquals(274, Objects.requireNonNull(repository.getCode(address)).length);
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class BlockToMineBuilder method getTransactions.
private List<Transaction> getTransactions(List<Transaction> txsToRemove, BlockHeader parentHeader, Coin minGasPrice) {
logger.debug("getting transactions from pending state");
List<Transaction> txs = minerUtils.getAllTransactions(transactionPool);
logger.debug("{} transaction(s) collected from pending state", txs.size());
Transaction remascTx = new RemascTransaction(parentHeader.getNumber() + 1);
txs.add(remascTx);
Map<RskAddress, BigInteger> accountNonces = new HashMap<>();
RepositorySnapshot originalRepo = repositoryLocator.snapshotAt(parentHeader);
return minerUtils.filterTransactions(txsToRemove, txs, accountNonces, originalRepo, minGasPrice);
}
use of co.rsk.db.RepositorySnapshot 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.RepositorySnapshot in project rskj by rsksmart.
the class BlockchainVMTest method testSEND_1.
@Test
public void testSEND_1() {
NewBlockChainInfo binfo = createNewBlockchain();
Blockchain blockchain = binfo.blockchain;
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock(), Collections.emptyList(), blockchain.getBestBlock().getStateRoot());
Coin transferAmount = Coin.valueOf(100L);
// Add a single transaction paying to a new address
byte[] dstAddress = randomAddress();
BigInteger transactionGasLimit = new BigInteger("21000");
Coin transactionGasPrice = Coin.valueOf(1);
Transaction t = Transaction.builder().gasPrice(transactionGasPrice).gasLimit(transactionGasLimit).destination(dstAddress).chainId(Constants.REGTEST_CHAIN_ID).value(transferAmount).build();
t.sign(binfo.faucetKey.getPrivKeyBytes());
List<Transaction> txs = Collections.singletonList(t);
Block block2 = blockGenerator.createChildBlock(block1, txs, blockchain.getBestBlock().getStateRoot());
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
MinerHelper mh = new MinerHelper(binfo.repository, binfo.repositoryLocator, binfo.blockchain);
mh.completeBlock(block2, block1);
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
RepositorySnapshot repository = binfo.repositoryLocator.snapshotAt(block2.getHeader());
Assert.assertEquals(blockchain.getBestBlock(), block2);
Assert.assertEquals(2, block2.getNumber());
Coin srcAmount = faucetAmount.subtract(transferAmount);
srcAmount = srcAmount.subtract(transactionGasPrice.multiply(transactionGasLimit));
Assert.assertEquals(repository.getBalance(new RskAddress(binfo.faucetKey.getAddress())), srcAmount);
Assert.assertEquals(repository.getBalance(new RskAddress(dstAddress)), transferAmount);
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class BlockTxsValidationRuleTest method setup.
@Before
public void setup() {
parent = mock(Block.class);
BlockHeader parentHeader = mock(BlockHeader.class);
when(parent.getHeader()).thenReturn(parentHeader);
RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
repositorySnapshot = mock(RepositorySnapshot.class);
when(repositoryLocator.snapshotAt(parentHeader)).thenReturn(repositorySnapshot);
rule = new BlockTxsValidationRule(repositoryLocator);
}
Aggregations