Search in sources :

Example 1 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class EthModuleTest method callWithoutReturn.

@Test
public void callWithoutReturn() {
    CallArguments args = new CallArguments();
    BlockResult blockResult = mock(BlockResult.class);
    Block block = mock(Block.class);
    ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
    when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
    when(blockResult.getBlock()).thenReturn(block);
    byte[] hReturn = new byte[0];
    ProgramResult executorResult = mock(ProgramResult.class);
    when(executorResult.getHReturn()).thenReturn(hReturn);
    ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
    when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any())).thenReturn(executorResult);
    EthModule eth = new EthModule(null, anyByte(), null, null, executor, retriever, null, null, null, new BridgeSupportFactory(null, null, null), config.getGasEstimationCap());
    String expectedResult = TypeConverter.toUnformattedJsonHex(hReturn);
    String actualResult = eth.call(args, "latest");
    assertEquals(expectedResult, actualResult);
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) CallArguments(org.ethereum.rpc.CallArguments) ProgramResult(org.ethereum.vm.program.ProgramResult) Block(org.ethereum.core.Block) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) Test(org.junit.Test)

Example 2 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class RemascTestRunner method start.

public void start() {
    this.blockchain = this.builder.build();
    ((BlockChainImpl) this.blockchain).setNoValidation(true);
    this.addedSiblings = new ArrayList<>();
    List<Block> mainChainBlocks = new ArrayList<>();
    this.blockchain.tryToConnect(this.genesis);
    BlockFactory blockFactory = new BlockFactory(builder.getConfig().getActivationConfig());
    final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(builder.getConfig().getNetworkConstants().getBridgeConstants().getBtcParams()), builder.getConfig().getNetworkConstants().getBridgeConstants(), builder.getConfig().getActivationConfig());
    PrecompiledContracts precompiledContracts = new PrecompiledContracts(builder.getConfig(), bridgeSupportFactory);
    BlockExecutor blockExecutor = new BlockExecutor(builder.getConfig().getActivationConfig(), builder.getRepositoryLocator(), new TransactionExecutorFactory(builder.getConfig(), builder.getBlockStore(), null, blockFactory, programInvokeFactory, precompiledContracts, blockTxSignatureCache));
    for (int i = 0; i <= this.initialHeight; i++) {
        int finalI = i;
        List<SiblingElement> siblingsForCurrentHeight = this.siblingElements.stream().filter(siblingElement -> siblingElement.getHeightToBeIncluded() == finalI).collect(Collectors.toList());
        List<BlockHeader> blockSiblings = new ArrayList<>();
        // Going to add siblings
        BlockDifficulty cummDifficulty = BlockDifficulty.ZERO;
        if (siblingsForCurrentHeight.size() > 0) {
            cummDifficulty = blockchain.getTotalDifficulty();
        }
        for (SiblingElement sibling : siblingsForCurrentHeight) {
            RskAddress siblingCoinbase = TestUtils.randomAddress();
            Block mainchainSiblingParent = mainChainBlocks.get(sibling.getHeight() - 1);
            Block siblingBlock = createBlock(this.genesis, mainchainSiblingParent, PegTestUtils.createHash3(), siblingCoinbase, Collections.emptyList(), minerFee, this.gasPrice, (long) i, this.txValue, this.txSigningKey, null);
            blockSiblings.add(siblingBlock.getHeader());
            builder.getBlockStore().saveBlock(siblingBlock, cummDifficulty.add(siblingBlock.getCumulativeDifficulty()), false);
            this.addedSiblings.add(siblingBlock);
        }
        long txNonce = i;
        RskAddress coinbase = fixedCoinbase != null ? fixedCoinbase : TestUtils.randomAddress();
        Block block = createBlock(this.genesis, this.blockchain.getBestBlock(), PegTestUtils.createHash3(), coinbase, blockSiblings, minerFee, this.gasPrice, txNonce, this.txValue, this.txSigningKey, null);
        mainChainBlocks.add(block);
        blockExecutor.executeAndFillAll(block, this.blockchain.getBestBlock().getHeader());
        block.seal();
        ImportResult result = this.blockchain.tryToConnect(block);
        System.out.println(result);
    }
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) TestUtils(org.ethereum.TestUtils) RskAddress(co.rsk.core.RskAddress) Coin(co.rsk.core.Coin) Keccak256(co.rsk.crypto.Keccak256) ArrayList(java.util.ArrayList) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BigInteger(java.math.BigInteger) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) BlockHashesHelper(co.rsk.core.bc.BlockHashesHelper) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) HashUtil(org.ethereum.crypto.HashUtil) RLP(org.ethereum.util.RLP) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) PegTestUtils(co.rsk.peg.PegTestUtils) Collectors(java.util.stream.Collectors) List(java.util.List) RepositorySnapshot(co.rsk.db.RepositorySnapshot) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) org.ethereum.core(org.ethereum.core) Collections(java.util.Collections) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ArrayList(java.util.ArrayList) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) BlockDifficulty(co.rsk.core.BlockDifficulty) RskAddress(co.rsk.core.RskAddress) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts)

Example 3 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class BlockExecutorTest method buildBlockExecutor.

private static BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config) {
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    return new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(store, stateRootHandler), new TransactionExecutorFactory(config, null, null, BLOCK_FACTORY, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
}
Also used : PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RskTestFactory(org.ethereum.util.RskTestFactory) HashMapDB(org.ethereum.datasource.HashMapDB) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 4 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class TransactionTest method constantCallConflictTest.

@Test
public void constantCallConflictTest() throws Exception {
    /*
          0x095e7baea6a6c7c4c2dfeb977efac326af552d87 contract is the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
        }
        */
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x00', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a76586a0', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x0400' " + "                } " + "            }, " + "            '" + PrecompiledContracts.REMASC_ADDR_STR + "' : { " + "                'balance' : '0x67EB', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0DE0B6B3A7621175', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x02' " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x60fe47b10000000000000000000000000000000000000000000000000000000000000400', " + "            'gasLimit' : '0x061a80', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '095e7baea6a6c7c4c2dfeb977efac326af552d87', " + "            'value' : '0x0186a0' " + "        } " + "    } " + "}";
    // The transaction calls the method set() (signature 0x60fe47b1)
    // passing the argument 0x400 (1024 in decimal)
    // So the contract storage cell at address 0x00 should contain 0x400.
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    // Executes only the test1.
    // Overrides the execution of the transaction to first execute a "get"
    // and then proceed with the "set" specified in JSON.
    // Why? I don't know. Maybe just to test if the returned value is the correct one.
    List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")) {

        @Override
        protected ProgramResult executeTransaction(Transaction tx) {
            // first emulating the constant call (Ethereum.callConstantFunction)
            // to ensure it doesn't affect the final state
            {
                Repository track = repository.startTracking();
                Transaction txConst = CallTransaction.createCallTransaction(0, 0, 100000000000000L, new RskAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), 0, CallTransaction.Function.fromSignature("get"), chainId);
                txConst.sign(new byte[] {});
                Block bestBlock = block;
                BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
                precompiledContracts = new PrecompiledContracts(config, bridgeSupportFactory);
                TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, new BlockStoreDummy(), null, blockFactory, invokeFactory, precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()));
                TransactionExecutor executor = transactionExecutorFactory.newInstance(txConst, 0, bestBlock.getCoinbase(), track, bestBlock, 0).setLocalCall(true);
                executor.executeTransaction();
                track.rollback();
                System.out.println("Return value: " + new CallTransaction.IntType("uint").decode(executor.getResult().getHReturn()));
            }
            // now executing the JSON test transaction
            return super.executeTransaction(tx);
        }
    }.setstateTestUSeREMASC(true).runImpl();
    if (!res.isEmpty())
        throw new RuntimeException("Test failed: " + res);
}
Also used : BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockStoreDummy(org.ethereum.db.BlockStoreDummy) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) Test(org.junit.Test)

Example 5 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class World method getBlockExecutor.

public BlockExecutor getBlockExecutor() {
    final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
    Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    if (this.blockExecutor == null) {
        this.blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache));
    }
    return this.blockExecutor;
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BlockExecutor(co.rsk.core.bc.BlockExecutor) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Aggregations

BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)21 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)11 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)8 Test (org.junit.Test)8 RepositoryBtcBlockStoreWithCache (co.rsk.peg.RepositoryBtcBlockStoreWithCache)7 Web3RskImpl (co.rsk.rpc.Web3RskImpl)6 DebugModule (co.rsk.rpc.modules.debug.DebugModule)6 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)6 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)6 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)6 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)6 EthModule (co.rsk.rpc.modules.eth.EthModule)5 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)5 TestSystemProperties (co.rsk.config.TestSystemProperties)4 RskAddress (co.rsk.core.RskAddress)4 BlockExecutor (co.rsk.core.bc.BlockExecutor)4 MiningMainchainView (co.rsk.core.bc.MiningMainchainView)4 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3