Search in sources :

Example 1 with RskJsonRpcRequestException

use of org.ethereum.rpc.exception.RskJsonRpcRequestException in project rskj by rsksmart.

the class Web3InformationRetrieverTest method getTransactions_stateNotFound.

@Test
public void getTransactions_stateNotFound() {
    Block block = mock(Block.class);
    BlockHeader header = mock(BlockHeader.class);
    when(block.getHeader()).thenReturn(header);
    Keccak256 blockHash = new Keccak256(new byte[32]);
    when(block.getHash()).thenReturn(blockHash);
    when(blockchain.getBlockByNumber(4)).thenReturn(block);
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> target.getInformationProvider("0x4"));
    assertEquals("State not found for block with hash " + blockHash.toString(), e.getMessage());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 2 with RskJsonRpcRequestException

use of org.ethereum.rpc.exception.RskJsonRpcRequestException 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 3 with RskJsonRpcRequestException

use of org.ethereum.rpc.exception.RskJsonRpcRequestException in project rskj by rsksmart.

the class ExecutionFoundBlockRetrieverTest method getByNumberInvalidBlockNumberHex.

@Test
public void getByNumberInvalidBlockNumberHex() {
    when(blockchain.getBlockByNumber(123)).thenReturn(null);
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> retriever.retrieveExecutionBlock("0x7B"));
    Assert.assertEquals(INVALID_PARAM_ERROR_CODE, (int) e.getCode());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Example 4 with RskJsonRpcRequestException

use of org.ethereum.rpc.exception.RskJsonRpcRequestException in project rskj by rsksmart.

the class ExecutionFoundBlockRetrieverTest method getByNumberInvalidDec.

@Test
public void getByNumberInvalidDec() {
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> retriever.retrieveExecutionBlock("zz"));
    Assert.assertEquals(INVALID_PARAM_ERROR_CODE, (int) e.getCode());
    verify(blockchain, never()).getBlockByNumber(any(long.class));
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Example 5 with RskJsonRpcRequestException

use of org.ethereum.rpc.exception.RskJsonRpcRequestException in project rskj by rsksmart.

the class ExecutionFoundBlockRetrieverTest method getOtherThanPendingLatestOrNumberThrows.

@Test
public void getOtherThanPendingLatestOrNumberThrows() {
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> retriever.retrieveExecutionBlock("other"));
    Assert.assertEquals(INVALID_PARAM_ERROR_CODE, (int) e.getCode());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Aggregations

RskJsonRpcRequestException (org.ethereum.rpc.exception.RskJsonRpcRequestException)19 Test (org.junit.Test)19 CallArguments (org.ethereum.rpc.CallArguments)4 InetAddress (java.net.InetAddress)2 BridgeConstants (co.rsk.config.BridgeConstants)1 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)1 RskAddress (co.rsk.core.RskAddress)1 Wallet (co.rsk.core.Wallet)1 BlockResult (co.rsk.core.bc.BlockResult)1 Keccak256 (co.rsk.crypto.Keccak256)1 TransactionGateway (co.rsk.net.TransactionGateway)1 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)1 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)1 World (co.rsk.test.World)1 DslParser (co.rsk.test.dsl.DslParser)1 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)1 Constants (org.ethereum.config.Constants)1 Block (org.ethereum.core.Block)1 Transaction (org.ethereum.core.Transaction)1 TransactionPool (org.ethereum.core.TransactionPool)1