use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method unclesPublishingFeeMustBeRoundedAndTheRoundedSurplusBurned.
@Test
public void unclesPublishingFeeMustBeRoundedAndTheRoundedSurplusBurned() {
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 < 10; 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 -20
assertEquals(Coin.valueOf(1680 - 20), testRunner.getAccountBalance(blockAtHeightSix.getCoinbase()));
Block blockAtHeightFiveMainchain = blockchain.getBlockByNumber(6);
assertEquals(Coin.valueOf(1374 - 14), testRunner.getAccountBalance(blockAtHeightFiveMainchain.getCoinbase()));
Block blockAtHeightFiveFirstSibling = testRunner.getAddedSiblings().get(0);
assertEquals(Coin.valueOf(1374 - 14), testRunner.getAccountBalance(blockAtHeightFiveFirstSibling.getCoinbase()));
Block blockAtHeightFiveSecondSibling = testRunner.getAddedSiblings().get(1);
assertEquals(Coin.valueOf(1374 - 14), testRunner.getAccountBalance(blockAtHeightFiveSecondSibling.getCoinbase()));
Block blockAtHeightFiveThirdSibling = testRunner.getAddedSiblings().get(2);
assertEquals(Coin.valueOf(1374 - 14), testRunner.getAccountBalance(blockAtHeightFiveThirdSibling.getCoinbase()));
// Review value +6
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.valueOf(84000), Coin.valueOf(6 + 6), 0);
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method processMinersFeesWithoutRequiredMaturity.
@Test
public void processMinersFeesWithoutRequiredMaturity() {
List<Block> blocks = createSimpleBlocks(genesisBlock, 1);
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, 1));
Blockchain blockchain = blockchainBuilder.setBlocks(blocks).build();
RepositoryLocator repositoryLocator = blockchainBuilder.getRepositoryLocator();
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
assertNull(repository.getAccountState(coinbaseA));
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class RemascProcessMinerFeesTest method oneSiblingIncludedOneBlockLaterAndAnotherIncludedRightAfter.
@Test
public void oneSiblingIncludedOneBlockLaterAndAnotherIncludedRightAfter() {
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 = Arrays.asList(new SiblingElement(5, 6, this.minerFee), 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 blockAtHeightSix = blockchain.getBlockByNumber(7);
assertEquals(Coin.valueOf(840L - 9L), testRunner.getAccountBalance(blockAtHeightSix.getCoinbase()));
Block blockAtHeightSeven = blockchain.getBlockByNumber(8);
assertEquals(Coin.valueOf(840L - 9L), testRunner.getAccountBalance(blockAtHeightSeven.getCoinbase()));
Block blockAtHeightFiveMainchain = blockchain.getBlockByNumber(6);
assertEquals(Coin.valueOf(5040L - 51L), testRunner.getAccountBalance(blockAtHeightFiveMainchain.getCoinbase()));
Block blockAtHeightFiveFirstSibling = testRunner.getAddedSiblings().get(0);
assertEquals(Coin.valueOf(5040L - 51L), testRunner.getAccountBalance(blockAtHeightFiveFirstSibling.getCoinbase()));
Block blockAtHeightFiveSecondSibling = testRunner.getAddedSiblings().get(1);
assertEquals(Coin.valueOf(4788L - 48L), testRunner.getAccountBalance(blockAtHeightFiveSecondSibling.getCoinbase()));
this.validateRemascsStorageIsCorrect(getRemascStorageProvider(repository), Coin.valueOf(84000L), Coin.valueOf(252L), 0L);
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class WorldDslProcessor method processAssertBalanceCommand.
private void processAssertBalanceCommand(DslCommand cmd) throws DslProcessorException {
String accountName = cmd.getArgument(0);
Coin expected = new Coin(new BigInteger(cmd.getArgument(1)));
RskAddress accountAddress;
Account account = world.getAccountByName(accountName);
if (account != null)
accountAddress = account.getAddress();
else {
Transaction tx = world.getTransactionByName(accountName);
if (tx != null)
accountAddress = tx.getContractAddress();
else
accountAddress = new RskAddress(accountName);
}
BlockHeader bestBlock = world.getBlockChain().getBestBlock().getHeader();
RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(bestBlock);
Coin accountBalance = repository.getBalance(accountAddress);
if (expected.equals(accountBalance))
return;
throw new DslProcessorException(String.format("Expected account '%s' with balance '%s', but got '%s'", accountName, expected, accountBalance));
}
use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.
the class ExtCodeHashDslTest method getExtCodeHashStateForBlockAndContract.
private byte[] getExtCodeHashStateForBlockAndContract(String targetBlock, String targetContract, int storageKey) {
Transaction creationTransaction = world.getTransactionByName(targetContract);
RskAddress contractAddress = creationTransaction.getContractAddress();
RepositorySnapshot finalRepoState = world.getRepositoryLocator().findSnapshotAt(world.getBlockByName(targetBlock).getHeader()).get();
if (finalRepoState.getStorageKeysCount(contractAddress) > storageKey) {
Iterator<DataWord> storageKeys = finalRepoState.getStorageKeys(contractAddress);
if (storageKey == 1) {
storageKeys.next();
}
byte[] extcodehash = finalRepoState.getStorageBytes(contractAddress, storageKeys.next());
return extcodehash;
} else {
return null;
}
}
Aggregations