Search in sources :

Example 1 with Wallet

use of co.rsk.core.Wallet in project rskj by rsksmart.

the class PersonalModuleWalletEnabledTest method importRawKey_KeyContains0xPrefix_OK.

@Test
public void importRawKey_KeyContains0xPrefix_OK() {
    ECKey eckey = new ECKey();
    String rawKey = ByteUtil.toHexString(eckey.getPrivKeyBytes());
    String passphrase = "passphrase1";
    byte[] hexDecodedKey = Hex.decode(rawKey);
    RskAddress addressMock = mock(RskAddress.class);
    doReturn("{}").when(addressMock).toJsonString();
    Wallet walletMock = mock(Wallet.class);
    doReturn(addressMock).when(walletMock).addAccountWithPrivateKey(hexDecodedKey, passphrase);
    doReturn(true).when(walletMock).unlockAccount(eq(addressMock), eq(passphrase), any(Long.class));
    PersonalModuleWalletEnabled personalModuleWalletEnabled = createPersonalModuleWalletEnabled(walletMock);
    String result = personalModuleWalletEnabled.importRawKey(String.format("0x%s", rawKey), passphrase);
    verify(walletMock, times(1)).addAccountWithPrivateKey(hexDecodedKey, passphrase);
    verify(walletMock, times(1)).unlockAccount(addressMock, passphrase, 1800000L);
    verify(addressMock, times(1)).toJsonString();
    assertEquals("{}", result);
}
Also used : Wallet(co.rsk.core.Wallet) RskAddress(co.rsk.core.RskAddress) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 2 with Wallet

use of co.rsk.core.Wallet in project rskj by rsksmart.

the class EthModuleTest method sendTransactionWithGasLimitTest.

@Test
public void sendTransactionWithGasLimitTest() {
    Constants constants = Constants.regtest();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount();
    RskAddress receiver = wallet.addAccount();
    // Hash of the expected transaction
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    Transaction tx = TransactionFactoryHelper.createTransaction(args, constants.getChainId(), wallet.getAccount(sender));
    String txExpectedResult = tx.getHash().toJsonString();
    TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
    when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
    TransactionGateway transactionGateway = mock(TransactionGateway.class);
    when(transactionGateway.receiveTransaction(any(Transaction.class))).thenReturn(transactionPoolAddResult);
    TransactionPool transactionPool = mock(TransactionPool.class);
    EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPool, transactionGateway);
    // Hash of the actual transaction builded inside the sendTransaction
    String txResult = ethModuleTransaction.sendTransaction(args);
    assertEquals(txExpectedResult, txResult);
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) BridgeConstants(co.rsk.config.BridgeConstants) Constants(org.ethereum.config.Constants) HashMapDB(org.ethereum.datasource.HashMapDB) TransactionGateway(co.rsk.net.TransactionGateway) Test(org.junit.Test)

Example 3 with Wallet

use of co.rsk.core.Wallet in project rskj by rsksmart.

the class EthModuleTest method sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException.

@Test
public void sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException() {
    // Given
    Constants constants = Constants.regtest();
    Wallet wallet = new Wallet(new HashMapDB());
    TransactionPool transactionPoolMock = mock(TransactionPool.class);
    TransactionGateway transactionGatewayMock = mock(TransactionGateway.class);
    CallArguments argsMock = mock(CallArguments.class);
    RskAddress addressFrom = new RskAddress(new ECKey().getAddress());
    // Address not in wallet
    doReturn(addressFrom.toJsonString()).when(argsMock).getFrom();
    EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPoolMock, transactionGatewayMock);
    // Then
    try {
        ethModuleTransaction.sendTransaction(argsMock);
        fail("RskJsonRpcRequestException should be thrown");
    } catch (RskJsonRpcRequestException ex) {
        verify(argsMock, times(2)).getFrom();
        assertEquals("Could not find account for address: " + addressFrom.toJsonString(), ex.getMessage());
    }
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Wallet(co.rsk.core.Wallet) CallArguments(org.ethereum.rpc.CallArguments) RskAddress(co.rsk.core.RskAddress) BridgeConstants(co.rsk.config.BridgeConstants) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) HashMapDB(org.ethereum.datasource.HashMapDB) TransactionGateway(co.rsk.net.TransactionGateway) Test(org.junit.Test)

Example 4 with Wallet

use of co.rsk.core.Wallet in project rskj by rsksmart.

the class Web3ImplScoringTest method createWeb3.

private static Web3Impl createWeb3(PeerScoringManager peerScoringManager) {
    SimpleEthereum rsk = new SimpleEthereum();
    World world = new World();
    rsk.blockchain = world.getBlockChain();
    MiningMainchainView miningMainchainView = new MiningMainchainViewImpl(world.getBlockStore(), 2);
    Wallet wallet = WalletFactory.createWallet();
    TestSystemProperties config = new TestSystemProperties();
    PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
    EthModule em = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), world.getBlockChain(), null, null, new ExecutionBlockRetriever(miningMainchainView, world.getBlockChain(), null, null), null, new EthModuleWalletEnabled(wallet), null, new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
    TxPoolModule tpm = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    DebugModule dm = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
    return new Web3RskImpl(rsk, world.getBlockChain(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, null, tpm, null, dm, null, null, Web3Mocks.getMockChannelManager(), peerScoringManager, null, null, null, null, null, null, null, null, null, null, null);
}
Also used : Wallet(co.rsk.core.Wallet) Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) DebugModuleImpl(co.rsk.rpc.modules.debug.DebugModuleImpl) World(co.rsk.test.World) MiningMainchainViewImpl(co.rsk.core.bc.MiningMainchainViewImpl) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) MiningMainchainView(co.rsk.core.bc.MiningMainchainView) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) EthModule(co.rsk.rpc.modules.eth.EthModule) DebugModule(co.rsk.rpc.modules.debug.DebugModule) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 5 with Wallet

use of co.rsk.core.Wallet in project rskj by rsksmart.

the class Web3RskImplTest method web3_ext_dumpState.

@Test
public void web3_ext_dumpState() throws Exception {
    Rsk rsk = Mockito.mock(Rsk.class);
    Blockchain blockchain = Mockito.mock(Blockchain.class);
    NetworkStateExporter networkStateExporter = Mockito.mock(NetworkStateExporter.class);
    Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHash()).thenReturn(PegTestUtils.createHash3());
    Mockito.when(block.getNumber()).thenReturn(1L);
    BlockStore blockStore = Mockito.mock(BlockStore.class);
    Mockito.when(blockStore.getBestBlock()).thenReturn(block);
    Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
    Mockito.when(blockchain.getBestBlock()).thenReturn(block);
    Wallet wallet = WalletFactory.createWallet();
    RskSystemProperties config = new RskSystemProperties();
    PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
    EthModule em = new EthModule(config, blockchain, null, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, rsk, wallet, null));
    TxPoolModule tpm = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
    Web3RskImpl web3 = new Web3RskImpl(rsk, blockchain, Web3Mocks.getMockTransactionPool(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, tpm, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, networkStateExporter, blockStore, null, null, null, null, null);
    web3.ext_dumpState();
}
Also used : BlockStore(org.ethereum.db.BlockStore) EthModuleSolidityDisabled(co.rsk.rpc.modules.eth.EthModuleSolidityDisabled) Wallet(co.rsk.core.Wallet) Blockchain(org.ethereum.core.Blockchain) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) Rsk(co.rsk.core.Rsk) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) NetworkStateExporter(co.rsk.core.NetworkStateExporter) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) EthModule(co.rsk.rpc.modules.eth.EthModule) Block(org.ethereum.core.Block) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Aggregations

Wallet (co.rsk.core.Wallet)9 Test (org.junit.Test)7 RskAddress (co.rsk.core.RskAddress)6 HashMapDB (org.ethereum.datasource.HashMapDB)5 CallArguments (org.ethereum.rpc.CallArguments)4 EthModule (co.rsk.rpc.modules.eth.EthModule)3 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)3 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)3 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)3 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)3 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)3 Constants (org.ethereum.config.Constants)3 ECKey (org.ethereum.crypto.ECKey)3 BridgeConstants (co.rsk.config.BridgeConstants)2 TestSystemProperties (co.rsk.config.TestSystemProperties)2 TransactionGateway (co.rsk.net.TransactionGateway)2 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)2 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)2 Web3RskImpl (co.rsk.rpc.Web3RskImpl)2 DebugModule (co.rsk.rpc.modules.debug.DebugModule)2