Search in sources :

Example 31 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class TransactionModuleTest method testGasEstimation.

@Test
public void testGasEstimation() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    TrieStore trieStore = world.getTrieStore();
    RepositoryLocator repositoryLocator = world.getRepositoryLocator();
    RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
    BlockStore blockStore = world.getBlockStore();
    BlockTxSignatureCache blockTxSignatureCache = world.getBlockTxSignatureCache();
    ReceivedTxSignatureCache receivedTxSignatureCache = world.getReceivedTxSignatureCache();
    TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutionFactoryWithProgramInvokeFactory(blockStore, null, blockTxSignatureCache);
    TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
    TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
    Web3Impl web3 = createEnvironmentGasExactimation(blockchain, trieStore, transactionPool, blockStore, transactionGateway, transactionExecutorFactory);
    RskAddress srcAddr = new RskAddress(ECKey.fromPrivate(Keccak256Helper.keccak256("cow".getBytes())).getAddress());
    // Create the transaction that creates the destination contract
    sendContractCreationTransaction(srcAddr, web3, repository);
    // Compute contract destination address
    BigInteger nonce = repository.getAccountState(srcAddr).getNonce();
    RskAddress contractAddress = new RskAddress(HashUtil.calcNewAddr(srcAddr.getBytes(), nonce.toByteArray()));
    // start with 5M
    int gasLimit = 5000000;
    int consumed = checkEstimateGas(callCallWithValue, 33472, gasLimit, srcAddr, contractAddress, web3, repository);
    // Now that I know the estimation, call again using the estimated value
    // it should not fail. We set the gasLimit to the expected value plus 1 to
    // differentiate between OOG and success.
    int consumed2 = checkEstimateGas(callCallWithValue, 33472, consumed + 1, srcAddr, contractAddress, web3, repository);
    Assert.assertEquals(consumed, consumed2);
    consumed = checkEstimateGas(callUnfill, 46942, gasLimit, srcAddr, contractAddress, web3, repository);
    consumed2 = checkEstimateGas(callUnfill, 46942, consumed + 1, srcAddr, contractAddress, web3, repository);
    Assert.assertEquals(consumed, consumed2);
}
Also used : BlockStore(org.ethereum.db.BlockStore) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) RepositorySnapshot(co.rsk.db.RepositorySnapshot) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 32 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class TransactionModuleTest method sendTransactionMustNotBeMined.

@Test
public void sendTransactionMustNotBeMined() {
    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, false, world.getBlockTxSignatureCache(), transactionGateway);
    String tx = sendTransaction(web3, repository);
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
    // Transaction tx must not be in block
    Assert.assertNull(txInBlock);
}
Also used : BlockStore(org.ethereum.db.BlockStore) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) RepositorySnapshot(co.rsk.db.RepositorySnapshot) Test(org.junit.Test)

Example 33 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class TransactionTest method dontLogWhenReverting.

@Test
public void dontLogWhenReverting() throws IOException, InterruptedException {
    /*

        Original contracts

        pragma solidity ^0.4.0;
        contract TestEventInvoked {
            event internalEvent();

            function doIt() {
                internalEvent();
                throw;
            }
        }

        contract TestEventInvoker {
            event externalEvent();

            function doIt(address invokedAddress) {
                externalEvent();
                invokedAddress.call.gas(50000)(0xb29f0835);
            }
        }

         */
    BigInteger nonce = config.getNetworkConstants().getInitialNonce();
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    MutableRepository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
    IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    Blockchain blockchain = ImportLightTest.createBlockchain(new TestGenesisLoader(trieStore, getClass().getResourceAsStream("/genesis/genesis-light.json"), nonce, false, true, true).load(), config, repository, blockStore, trieStore);
    ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
    System.out.println("address: " + ByteUtil.toHexString(sender.getAddress()));
    // First contract code TestEventInvoked
    String code1 = "6060604052341561000f57600080fd5b5b60ae8061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063b29f083514603d575b600080fd5b3415604757600080fd5b604d604f565b005b7f95481a538d62f8458d3cecac82408d5ff2630d8335962b1cdbac16f1a9b910e760405160405180910390a1600080fd5b5600a165627a7a723058207d93861daff7f4a0479d7f3eb0ca7ef5cef7e2bbf2c4637ab4f021ecc5afa7ad0029";
    // Second contract code TestEventInvoker
    String code2 = "6060604052341561000f57600080fd5b5b6101358061001f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e25fd8a71461003e575b600080fd5b341561004957600080fd5b610075600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610077565b005b7f4cd6f2e769273405c20f3a0c098c9045749deec145502c4838b54206ec5c542860405160405180910390a18073ffffffffffffffffffffffffffffffffffffffff1661c35063b29f0835906040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160006040518083038160008887f19350505050505b505600a165627a7a7230582019096fd773ebc5581ba378acd64cb1acb450b4eb4866d710f3e3f4e33d635a4b0029";
    // Second contract ABI
    String abi2 = "[{\"constant\":false,\"inputs\":[{\"name\":\"invokedAddress\",\"type\":\"address\"}],\"name\":\"doIt\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"externalEvent\",\"type\":\"event\"}]";
    Transaction tx1 = createTx(sender, new byte[0], Hex.decode(code1), repository);
    executeTransaction(blockchain, blockStore, tx1, repository, blockTxSignatureCache);
    Transaction tx2 = createTx(sender, new byte[0], Hex.decode(code2), repository);
    executeTransaction(blockchain, blockStore, tx2, repository, blockTxSignatureCache);
    CallTransaction.Contract contract2 = new CallTransaction.Contract(abi2);
    byte[] data = contract2.getByName("doIt").encode(ByteUtil.toHexString(tx1.getContractAddress().getBytes()));
    Transaction tx3 = createTx(sender, tx2.getContractAddress().getBytes(), data, repository);
    TransactionExecutor executor = executeTransaction(blockchain, blockStore, tx3, repository, blockTxSignatureCache);
    Assert.assertEquals(1, executor.getResult().getLogInfoList().size());
    Assert.assertFalse(executor.getResult().getLogInfoList().get(0).isRejected());
    Assert.assertEquals(1, executor.getVMLogs().size());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ECKey(org.ethereum.crypto.ECKey) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) MutableRepository(org.ethereum.db.MutableRepository) BigInteger(java.math.BigInteger) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 34 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class RepositoryMigrationTest method test.

@Test
public void test() {
    final RskAddress COW = new RskAddress("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
    final BigInteger accountNonce = BigInteger.valueOf(9);
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(trieStore, new Trie(trieStore));
    AccountState accountState = repository.createAccount(COW);
    accountState.setNonce(accountNonce);
    repository.updateAccountState(COW, accountState);
    repository.commit();
    Assert.assertThat(repository.getAccountState(COW).getNonce(), is(accountNonce));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) AccountState(org.ethereum.core.AccountState) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 35 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class BridgeStateTest method recreateFromEmptyStorageProvider.

@Test
public void recreateFromEmptyStorageProvider() throws IOException {
    TestSystemProperties config = new TestSystemProperties();
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
    BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, config.getActivationConfig().forBlock(0L));
    BridgeState state = new BridgeState(42, provider, null);
    BridgeState clone = BridgeState.create(bridgeConstants, state.getEncoded(), null);
    Assert.assertNotNull(clone);
    Assert.assertEquals(42, clone.getBtcBlockchainBestChainHeight());
    Assert.assertTrue(clone.getActiveFederationBtcUTXOs().isEmpty());
    Assert.assertTrue(clone.getRskTxsWaitingForSignatures().isEmpty());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BridgeConstants(co.rsk.config.BridgeConstants) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Aggregations

TrieStore (co.rsk.trie.TrieStore)43 Test (org.junit.Test)29 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)28 HashMapDB (org.ethereum.datasource.HashMapDB)26 Trie (co.rsk.trie.Trie)18 MutableRepository (org.ethereum.db.MutableRepository)12 BlockStore (org.ethereum.db.BlockStore)11 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)9 RepositoryLocator (co.rsk.db.RepositoryLocator)6 MultiTrieStore (co.rsk.trie.MultiTrieStore)6 Path (java.nio.file.Path)6 Repository (org.ethereum.core.Repository)6 DataWord (org.ethereum.vm.DataWord)6 MutableTrieImpl (co.rsk.db.MutableTrieImpl)5 TransactionGateway (co.rsk.net.TransactionGateway)5 World (co.rsk.test.World)5 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 ECKey (org.ethereum.crypto.ECKey)5 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)5