use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionPoolImplTest method setUp.
@Before
public void setUp() {
rskTestContext = new RskTestContext(new String[] { "--regtest" }) {
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
}
@Override
protected RepositoryLocator buildRepositoryLocator() {
return spy(super.buildRepositoryLocator());
}
};
blockChain = rskTestContext.getBlockchain();
RepositoryLocator repositoryLocator = rskTestContext.getRepositoryLocator();
repository = repositoryLocator.startTrackingAt(blockChain.getBestBlock().getHeader());
signatureCache = spy(rskTestContext.getReceivedTxSignatureCache());
transactionPool = new TransactionPoolImpl(rskTestContext.getRskSystemProperties(), repositoryLocator, rskTestContext.getBlockStore(), rskTestContext.getBlockFactory(), rskTestContext.getCompositeEthereumListener(), rskTestContext.getTransactionExecutorFactory(), signatureCache, 10, 100);
// don't call start to avoid creating threads
transactionPool.processBest(blockChain.getBestBlock());
// this is to workaround the current test structure, which abuses the Repository by
// modifying it in place
doReturn(repository).when(repositoryLocator).snapshotAt(any());
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method processMinersFeesWithNoSiblings.
@Test
public void processMinersFeesWithNoSiblings() {
Blockchain blockchain = blockchainBuilder.build();
BlockStore blockStore = blockchainBuilder.getBlockStore();
RepositoryLocator repositoryLocator = blockchainBuilder.getRepositoryLocator();
List<Block> blocks = createSimpleBlocks(genesisBlock, 4);
Block blockWithOneTx = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbaseA, Collections.emptyList(), minerFee, 0, txValue, cowKey);
blocks.add(blockWithOneTx);
blocks.addAll(createSimpleBlocks(blockWithOneTx, 9));
BlockExecutor blockExecutor = buildBlockExecutor(repositoryLocator, blockStore);
executeBlocks(blockchain, blocks, blockExecutor);
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
assertEquals(cowInitialBalance.subtract(Coin.valueOf(minerFee + txValue)), repository.getAccountState(new RskAddress(cowAddress)).getBalance());
assertEquals(Coin.valueOf(minerFee), repository.getAccountState(PrecompiledContracts.REMASC_ADDR).getBalance());
assertNull(repository.getAccountState(coinbaseA));
assertNull(repository.getAccountState(remascConfig.getRskLabsAddress()));
RemascStorageProvider remascStorageProvider = getRemascStorageProvider(repository);
assertEquals(Coin.ZERO, remascStorageProvider.getRewardBalance());
assertEquals(Coin.ZERO, remascStorageProvider.getBurnedBalance());
Block newblock = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), TestUtils.randomAddress(), Collections.emptyList(), null);
blockExecutor.executeAndFillAll(newblock, blockchain.getBestBlock().getHeader());
blockchain.tryToConnect(newblock);
repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
assertEquals(cowInitialBalance.subtract(Coin.valueOf(minerFee + txValue)), repository.getAccountState(new RskAddress(cowAddress)).getBalance());
long blockReward = minerFee / remascConfig.getSyntheticSpan();
assertEquals(Coin.valueOf(minerFee - blockReward), repository.getAccountState(PrecompiledContracts.REMASC_ADDR).getBalance());
long rskReward = blockReward / remascConfig.getRskLabsDivisor();
assertEquals(Coin.valueOf(rskReward), repository.getAccountState(remascConfig.getRskLabsAddress()).getBalance());
long federationReward = (blockReward - rskReward) / remascConfig.getFederationDivisor();
assertEquals(33, federationReward);
assertEquals(Coin.valueOf(blockReward - rskReward - federationReward), repository.getAccountState(coinbaseA).getBalance());
remascStorageProvider = getRemascStorageProvider(repository);
assertEquals(Coin.valueOf(minerFee - blockReward), remascStorageProvider.getRewardBalance());
assertEquals(Coin.ZERO, remascStorageProvider.getBurnedBalance());
this.validateFederatorsBalanceIsCorrect(repository, federationReward, newblock);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method noPublisherFeeIsPaidWhenThePublisherHasNoSiblings.
@Test
public void noPublisherFeeIsPaidWhenThePublisherHasNoSiblings() {
Blockchain blockchain = blockchainBuilder.build();
BlockStore blockStore = blockchainBuilder.getBlockStore();
RepositoryLocator repositoryLocator = blockchainBuilder.getRepositoryLocator();
final long NUMBER_OF_TXS_WITH_FEES = 3;
List<Block> blocks = createSimpleBlocks(genesisBlock, 4);
Block blockWithOneTxD = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbaseD, Collections.emptyList(), minerFee, 0, txValue, cowKey);
blocks.add(blockWithOneTxD);
Block blockWithOneTxA = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxD, PegTestUtils.createHash3(), coinbaseA, Collections.emptyList(), minerFee, 1, txValue, cowKey);
Block blockWithOneTxB = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxD, PegTestUtils.createHash3(), coinbaseB, Collections.emptyList(), minerFee * 3, 1, txValue, cowKey);
blocks.add(blockWithOneTxA);
Block blockThatIncludesUncleC = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxA, PegTestUtils.createHash3(), coinbaseC, Collections.singletonList(blockWithOneTxB.getHeader()), minerFee, 2, txValue, cowKey);
blocks.add(blockThatIncludesUncleC);
blocks.addAll(createSimpleBlocks(blockThatIncludesUncleC, 7));
BlockExecutor blockExecutor = buildBlockExecutor(repositoryLocator, blockStore);
executeBlocks(blockchain, blocks, blockExecutor);
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
// validate that the blockchain's and REMASC's initial states are correct
Coin cowRemainingBalance = cowInitialBalance.subtract(Coin.valueOf(minerFee * NUMBER_OF_TXS_WITH_FEES + txValue * NUMBER_OF_TXS_WITH_FEES));
List<Long> otherAccountsBalance = new ArrayList<>(Arrays.asList(null, null, null, null));
this.validateAccountsCurrentBalanceIsCorrect(repository, cowRemainingBalance, minerFee * NUMBER_OF_TXS_WITH_FEES, null, this.getAccountsWithExpectedBalance(otherAccountsBalance));
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.ZERO, Coin.ZERO, 1L);
// add block to pay fees of blocks on blockchain's height 4
Block blockToPayFeesOnHeightFour = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), TestUtils.randomAddress(), Collections.emptyList(), minerFee, 0, txValue, cowKey);
blockExecutor.executeAndFillAll(blockToPayFeesOnHeightFour, blockchain.getBestBlock().getHeader());
blockchain.tryToConnect(blockToPayFeesOnHeightFour);
repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
// -- After executing REMASC's contract for paying height 4 block
// validate that account's balances are correct
long blockRewardOnHeightFour = minerFee / remascConfig.getSyntheticSpan();
long remascCurrentBalance = minerFee * 3 - blockRewardOnHeightFour;
long rskCurrentBalance = blockRewardOnHeightFour / remascConfig.getRskLabsDivisor();
blockRewardOnHeightFour -= rskCurrentBalance;
long federationReward = blockRewardOnHeightFour / remascConfig.getFederationDivisor();
assertEquals(33, federationReward);
blockRewardOnHeightFour -= federationReward;
List<Long> otherAccountsBalanceOnHeightFour = new ArrayList<>(Arrays.asList(null, null, null, blockRewardOnHeightFour));
this.validateAccountsCurrentBalanceIsCorrect(repository, cowRemainingBalance, remascCurrentBalance, rskCurrentBalance, this.getAccountsWithExpectedBalance(otherAccountsBalanceOnHeightFour));
// validate that REMASC's state is correct
blockRewardOnHeightFour = minerFee / remascConfig.getSyntheticSpan();
Coin expectedRewardBalance = Coin.valueOf(minerFee - blockRewardOnHeightFour);
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), expectedRewardBalance, Coin.ZERO, 1L);
this.validateFederatorsBalanceIsCorrect(repository, federationReward, blockToPayFeesOnHeightFour);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method siblingIncludedOneBlockLater.
@Test
public void siblingIncludedOneBlockLater() {
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 = Collections.singletonList(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 blockAtHeightSeven = blockchain.getBlockByNumber(8);
assertEquals(Coin.valueOf(1680L - 17L), testRunner.getAccountBalance(blockAtHeightSeven.getCoinbase()));
Block blockAtHeightFiveMainchain = blockchain.getBlockByNumber(6);
assertEquals(Coin.valueOf(7560L - 76L), testRunner.getAccountBalance(blockAtHeightFiveMainchain.getCoinbase()));
Block blockAtHeightFiveSibling = testRunner.getAddedSiblings().get(0);
assertEquals(Coin.valueOf(7182L - 72L), testRunner.getAccountBalance(blockAtHeightFiveSibling.getCoinbase()));
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.valueOf(84000L), Coin.valueOf(378L - 3L), 0L);
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method siblingsFeeForMiningBlockMustBeRoundedAndTheRoundedSurplusBurned.
@Test
public void siblingsFeeForMiningBlockMustBeRoundedAndTheRoundedSurplusBurned() {
RskSystemProperties config = spy(new TestSystemProperties());
when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.allBut(ConsensusRule.RSKIP85));
BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config);
long minerFee = 21000;
List<SiblingElement> siblings = new ArrayList<>();
for (int i = 0; i < 9; i++) {
siblings.add(new SiblingElement(5, 6, minerFee));
}
RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(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);
// TODO Review value 18
assertEquals(Coin.valueOf(1674 - 18), testRunner.getAccountBalance(blockAtHeightSix.getCoinbase()));
Block blockAtHeightSeven = blockchain.getBlockByNumber(8);
assertNull(testRunner.getAccountBalance(blockAtHeightSeven.getCoinbase()));
Block blockAtHeightFiveMainchain = blockchain.getBlockByNumber(6);
assertEquals(Coin.valueOf(1512 - 16), testRunner.getAccountBalance(blockAtHeightFiveMainchain.getCoinbase()));
Block blockAtHeightFiveFirstSibling = testRunner.getAddedSiblings().get(0);
assertEquals(Coin.valueOf(1512 - 16), testRunner.getAccountBalance(blockAtHeightFiveFirstSibling.getCoinbase()));
Block blockAtHeightFiveSecondSibling = testRunner.getAddedSiblings().get(1);
assertEquals(Coin.valueOf(1512 - 16), testRunner.getAccountBalance(blockAtHeightFiveSecondSibling.getCoinbase()));
// TODO Review value 16 (original value 6)
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.valueOf(84000), Coin.valueOf(16), 0L);
}
Aggregations