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);
}
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());
}
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);
}
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);
}
Aggregations