Search in sources :

Example 1 with Ethereum

use of org.ethereum.facade.Ethereum in project rskj by rsksmart.

the class Web3ImplRpcTest method getRpcModules.

@Test
public void getRpcModules() {
    Ethereum eth = Web3Mocks.getMockEthereum();
    Blockchain blockchain = Web3Mocks.getMockBlockchain();
    PersonalModule pm = new PersonalModuleWalletDisabled();
    Web3Impl web3 = new Web3RskImpl(eth, blockchain, new TestSystemProperties(), null, null, pm, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    Map<String, String> result = web3.rpc_modules();
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertTrue(result.containsKey("eth"));
    Assert.assertEquals("1.0", result.get("eth"));
}
Also used : Ethereum(org.ethereum.facade.Ethereum) Blockchain(org.ethereum.core.Blockchain) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) Web3Impl(org.ethereum.rpc.Web3Impl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 2 with Ethereum

use of org.ethereum.facade.Ethereum in project rskj by rsksmart.

the class SyncNotificationEmitterTest method setUp.

@Before
public void setUp() {
    Ethereum ethereum = mock(Ethereum.class);
    serializer = mock(JsonRpcSerializer.class);
    Blockchain blockchain = mock(Blockchain.class);
    Block block = mock(Block.class);
    when(block.getNumber()).thenReturn(2L);
    when(blockchain.getBestBlock()).thenReturn(block);
    SyncProcessor syncProcessor = mock(SyncProcessor.class);
    when(syncProcessor.getInitialBlockNumber()).thenReturn(2L);
    when(syncProcessor.getHighestBlockNumber()).thenReturn(100L);
    emitter = new SyncNotificationEmitter(ethereum, serializer, blockchain, syncProcessor);
    ArgumentCaptor<EthereumListener> listenerCaptor = ArgumentCaptor.forClass(EthereumListener.class);
    verify(ethereum).addListener(listenerCaptor.capture());
    listener = listenerCaptor.getValue();
}
Also used : JsonRpcSerializer(co.rsk.rpc.JsonRpcSerializer) EthereumListener(org.ethereum.listener.EthereumListener) Ethereum(org.ethereum.facade.Ethereum) Blockchain(org.ethereum.core.Blockchain) SyncProcessor(co.rsk.net.SyncProcessor) Block(org.ethereum.core.Block) Before(org.junit.Before)

Example 3 with Ethereum

use of org.ethereum.facade.Ethereum in project rskj by rsksmart.

the class RskContext method getWeb3WebSocketServer.

private Web3WebSocketServer getWeb3WebSocketServer() {
    if (web3WebSocketServer == null) {
        RskSystemProperties rskSystemProperties = getRskSystemProperties();
        JsonRpcSerializer jsonRpcSerializer = getJsonRpcSerializer();
        Ethereum rsk = getRsk();
        SyncProcessor syncProcessor = getSyncProcessor();
        EthSubscriptionNotificationEmitter emitter = new EthSubscriptionNotificationEmitter(new BlockHeaderNotificationEmitter(rsk, jsonRpcSerializer), new LogsNotificationEmitter(rsk, jsonRpcSerializer, getReceiptStore(), new BlockchainBranchComparator(getBlockStore())), new PendingTransactionsNotificationEmitter(rsk, jsonRpcSerializer), new SyncNotificationEmitter(rsk, jsonRpcSerializer, blockchain, syncProcessor));
        RskWebSocketJsonRpcHandler jsonRpcHandler = new RskWebSocketJsonRpcHandler(emitter);
        web3WebSocketServer = new Web3WebSocketServer(rskSystemProperties.rpcWebSocketBindAddress(), rskSystemProperties.rpcWebSocketPort(), jsonRpcHandler, getJsonRpcWeb3ServerHandler(), rskSystemProperties.rpcWebSocketServerWriteTimeoutSeconds(), rskSystemProperties.rpcWebSocketMaxFrameSize(), rskSystemProperties.rpcWebSocketMaxAggregatedFrameSize());
    }
    return web3WebSocketServer;
}
Also used : LogsNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.LogsNotificationEmitter) SyncNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.SyncNotificationEmitter) PendingTransactionsNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.PendingTransactionsNotificationEmitter) Ethereum(org.ethereum.facade.Ethereum) BlockHeaderNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.BlockHeaderNotificationEmitter)

Example 4 with Ethereum

use of org.ethereum.facade.Ethereum in project rskj by rsksmart.

the class Web3ImplTest method eth_compileSolidity.

@Test
@Ignore
public void eth_compileSolidity() throws Exception {
    RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
    String solc = System.getProperty("solc");
    if (StringUtils.isEmpty(solc))
        solc = "/usr/bin/solc";
    Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);
    Ethereum eth = Mockito.mock(Ethereum.class);
    EthModule ethModule = new EthModule(config, null, null, new ExecutionBlockRetriever(null, null, null), new EthModuleSolidityEnabled(new SolidityCompiler(systemProperties)), null);
    PersonalModule personalModule = new PersonalModuleWalletDisabled();
    TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3Impl web3 = new Web3RskImpl(eth, null, null, systemProperties, null, null, personalModule, ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null, null);
    String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) {   return a * 7;   } }";
    Map<String, CompilationResultDTO> result = web3.eth_compileSolidity(contract);
    org.junit.Assert.assertNotNull(result);
    CompilationResultDTO dto = result.get("rsk");
    if (dto == null)
        dto = result.get("<stdin>:rsk");
    org.junit.Assert.assertEquals(contract, dto.info.getSource());
}
Also used : Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) EthModuleSolidityEnabled(co.rsk.rpc.modules.eth.EthModuleSolidityEnabled) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) Ethereum(org.ethereum.facade.Ethereum) EthModule(co.rsk.rpc.modules.eth.EthModule) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskSystemProperties(co.rsk.config.RskSystemProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Ethereum

use of org.ethereum.facade.Ethereum in project rskj by rsksmart.

the class Web3ImplTest method eth_compileSolidityWithoutSolidity.

@Test
public void eth_compileSolidityWithoutSolidity() throws Exception {
    SystemProperties systemProperties = Mockito.mock(SystemProperties.class);
    String solc = System.getProperty("solc");
    if (StringUtils.isEmpty(solc))
        solc = "/usr/bin/solc";
    Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);
    Wallet wallet = WalletFactory.createWallet();
    Ethereum eth = Web3Mocks.getMockEthereum();
    Blockchain blockchain = Web3Mocks.getMockBlockchain();
    TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
    EthModule ethModule = new EthModule(config, blockchain, null, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, null));
    TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3Impl web3 = new Web3RskImpl(eth, blockchain, transactionPool, config, null, null, new PersonalModuleWalletDisabled(), ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null, null);
    String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) {   return a * 7;   } }";
    Map<String, CompilationResultDTO> result = web3.eth_compileSolidity(contract);
    org.junit.Assert.assertNotNull(result);
    org.junit.Assert.assertEquals(0, result.size());
}
Also used : EthModuleSolidityDisabled(co.rsk.rpc.modules.eth.EthModuleSolidityDisabled) Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) SystemProperties(org.ethereum.config.SystemProperties) RskSystemProperties(co.rsk.config.RskSystemProperties) CompilationResultDTO(org.ethereum.rpc.dto.CompilationResultDTO) Ethereum(org.ethereum.facade.Ethereum) EthModule(co.rsk.rpc.modules.eth.EthModule) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) Test(org.junit.Test)

Aggregations

Ethereum (org.ethereum.facade.Ethereum)13 Test (org.junit.Test)6 PersonalModuleWalletDisabled (co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 JsonRpcSerializer (co.rsk.rpc.JsonRpcSerializer)4 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)4 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)4 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)4 EthereumListener (org.ethereum.listener.EthereumListener)4 Before (org.junit.Before)4 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 Web3RskImpl (co.rsk.rpc.Web3RskImpl)3 TestSystemProperties (co.rsk.config.TestSystemProperties)2 Web3InformationRetriever (co.rsk.rpc.Web3InformationRetriever)2 DebugModule (co.rsk.rpc.modules.debug.DebugModule)2 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)2 EthModule (co.rsk.rpc.modules.eth.EthModule)2 SystemProperties (org.ethereum.config.SystemProperties)2 Blockchain (org.ethereum.core.Blockchain)2 BlockStore (org.ethereum.db.BlockStore)2