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