Search in sources :

Example 6 with Wallet

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

the class Web3ImplLogsTest method createWeb3.

private Web3Impl createWeb3() {
    Wallet wallet = WalletFactory.createWallet();
    PersonalModule personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
    EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockChain, transactionPool, null, new ExecutionBlockRetriever(mainchainView, blockChain, null, null), null, new EthModuleWalletEnabled(wallet), null, new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
    TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
    DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
    return new Web3RskImpl(eth, blockChain, config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, null, Web3Mocks.getMockChannelManager(), null, null, blockStore, receiptStore, null, null, null, new SimpleConfigCapabilities(), null, new BlocksBloomStore(2, 0, new HashMapDB()), mock(Web3InformationRetriever.class), 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) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) HashMapDB(org.ethereum.datasource.HashMapDB) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) BlocksBloomStore(co.rsk.logfilter.BlocksBloomStore) Web3InformationRetriever(co.rsk.rpc.Web3InformationRetriever) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) EthModule(co.rsk.rpc.modules.eth.EthModule) DebugModule(co.rsk.rpc.modules.debug.DebugModule) SimpleConfigCapabilities(org.ethereum.rpc.Simples.SimpleConfigCapabilities) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule)

Example 7 with Wallet

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

the class TransactionArgumentsUtilTest method processArguments.

@Test
public void processArguments() {
    Constants constants = Constants.regtest();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount();
    RskAddress receiver = wallet.addAccount();
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, null, wallet.getAccount(sender), constants.getChainId());
    assertEquals(txArgs.getValue(), BigInteger.valueOf(100000L));
    assertEquals(txArgs.getGasPrice(), BigInteger.valueOf(10000000000000L));
    assertEquals(txArgs.getGasLimit(), BigInteger.valueOf(30400L));
    assertEquals(txArgs.getChainId(), 33);
    assertEquals(txArgs.getNonce(), BigInteger.ONE);
    assertEquals(txArgs.getData(), null);
    assertArrayEquals(txArgs.getTo(), receiver.getBytes());
}
Also used : Wallet(co.rsk.core.Wallet) TransactionArguments(org.ethereum.core.TransactionArguments) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) Constants(org.ethereum.config.Constants) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 8 with Wallet

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

the class PersonalModuleTest method sendTransactionWithGasLimitTest.

@Test
public void sendTransactionWithGasLimitTest() throws Exception {
    TestSystemProperties props = new TestSystemProperties();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount(PASS_FRASE);
    RskAddress receiver = wallet.addAccount();
    // Hash of the expected transaction
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    Transaction tx = TransactionFactoryHelper.createTransaction(args, props.getNetworkConstants().getChainId(), wallet.getAccount(sender, PASS_FRASE));
    String txExpectedResult = tx.getHash().toJsonString();
    TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
    when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
    Ethereum ethereum = mock(Ethereum.class);
    PersonalModuleWalletEnabled personalModuleWalletEnabled = new PersonalModuleWalletEnabled(props, ethereum, wallet, null);
    // Hash of the actual transaction builded inside the sendTransaction
    String txResult = personalModuleWalletEnabled.sendTransaction(args, PASS_FRASE);
    assertEquals(txExpectedResult, txResult);
}
Also used : Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) Ethereum(org.ethereum.facade.Ethereum) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) HashMapDB(org.ethereum.datasource.HashMapDB) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 9 with Wallet

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

the class PersonalModuleWalletEnabledTest method importRawKey_KeyDoesNotContains0xPrefix_OK.

@Test
public void importRawKey_KeyDoesNotContains0xPrefix_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(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)

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