Search in sources :

Example 31 with RepositorySnapshot

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);
}
Also used : BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RepositoryLocator(co.rsk.db.RepositoryLocator) RepositorySnapshot(co.rsk.db.RepositorySnapshot) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 32 with RepositorySnapshot

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));
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RepositorySnapshot(co.rsk.db.RepositorySnapshot) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 33 with RepositorySnapshot

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);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RepositorySnapshot(co.rsk.db.RepositorySnapshot) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 34 with RepositorySnapshot

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));
}
Also used : Coin(co.rsk.core.Coin) RepositorySnapshot(co.rsk.db.RepositorySnapshot) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger)

Example 35 with RepositorySnapshot

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;
    }
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord)

Aggregations

RepositorySnapshot (co.rsk.db.RepositorySnapshot)37 Test (org.junit.Test)25 RepositoryLocator (co.rsk.db.RepositoryLocator)18 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)13 RskAddress (co.rsk.core.RskAddress)12 BlockStore (org.ethereum.db.BlockStore)11 BigInteger (java.math.BigInteger)10 Coin (co.rsk.core.Coin)9 BlockExecutor (co.rsk.core.bc.BlockExecutor)8 World (co.rsk.test.World)7 TestSystemProperties (co.rsk.config.TestSystemProperties)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)5 Account (org.ethereum.core.Account)5 AccountInformationProvider (co.rsk.core.bc.AccountInformationProvider)3 TransactionGateway (co.rsk.net.TransactionGateway)3 DslParser (co.rsk.test.dsl.DslParser)3 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)3 TrieStore (co.rsk.trie.TrieStore)3 Block (org.ethereum.core.Block)3