Search in sources :

Example 11 with RskJsonRpcRequestException

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

the class Web3ImplScoringTest method banningUsingLocalIPV4AndMaskThrowsException.

@Test
public void banningUsingLocalIPV4AndMaskThrowsException() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    // generate a random local IPv4 address
    InetAddress address = generateLocalIPAddressV4();
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
    RskJsonRpcRequestException exception = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> web3.sco_banAddress(address.getHostAddress() + "/8"));
    Assert.assertEquals(-32602, (int) exception.getCode());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 12 with RskJsonRpcRequestException

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

the class Web3ImplScoringTest method removeBannedAddressWithInvalidMask.

@Test
public void removeBannedAddressWithInvalidMask() {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    RskJsonRpcRequestException ex = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> web3.sco_unbanAddress("192.168.56.1/a"));
    Assert.assertEquals("invalid banned address 192.168.56.1/a", ex.getMessage());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Example 13 with RskJsonRpcRequestException

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

the class EthModuleDSLTest method testCall_getRevertReason.

@Test
public void testCall_getRevertReason() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/eth_module/revert_reason.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("tx02");
    byte[] status = transactionReceipt.getStatus();
    Assert.assertNotNull(status);
    Assert.assertEquals(0, status.length);
    EthModule eth = EthModuleTestUtils.buildBasicEthModule(world);
    final Transaction tx01 = world.getTransactionByName("tx01");
    final CallArguments args = new CallArguments();
    // "6252703f5ba322ec64d3ac45e56241b7d9e481ad";
    args.setTo("0x" + tx01.getContractAddress().toHexString());
    // call to contract with param value = 0
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000000");
    args.setValue("0");
    args.setNonce("1");
    args.setGas("10000000");
    try {
        eth.call(args, "0x2");
        fail();
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("Negative value."));
    }
    // call to contract with param value = 1
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000001");
    final String call = eth.call(args, "0x2");
    assertEquals("0x", call);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) CallArguments(org.ethereum.rpc.CallArguments) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 14 with RskJsonRpcRequestException

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

the class EthModuleTest method test_revertedTransaction.

@Test
public void test_revertedTransaction() {
    CallArguments args = new CallArguments();
    BlockResult blockResult = mock(BlockResult.class);
    Block block = mock(Block.class);
    ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
    when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
    when(blockResult.getBlock()).thenReturn(block);
    byte[] hreturn = Hex.decode("08c379a000000000000000000000000000000000000000000000000000000000" + "0000002000000000000000000000000000000000000000000000000000000000" + "0000000f6465706f73697420746f6f2062696700000000000000000000000000" + "00000000");
    ProgramResult executorResult = mock(ProgramResult.class);
    when(executorResult.isRevert()).thenReturn(true);
    when(executorResult.getHReturn()).thenReturn(hreturn);
    ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
    when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any())).thenReturn(executorResult);
    EthModule eth = new EthModule(null, anyByte(), null, null, executor, retriever, null, null, null, new BridgeSupportFactory(null, null, null), config.getGasEstimationCap());
    try {
        eth.call(args, "latest");
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("deposit too big"));
    }
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) BlockResult(co.rsk.core.bc.BlockResult) CallArguments(org.ethereum.rpc.CallArguments) ProgramResult(org.ethereum.vm.program.ProgramResult) Block(org.ethereum.core.Block) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) Test(org.junit.Test)

Example 15 with RskJsonRpcRequestException

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

the class ExecutionFoundBlockRetrieverTest method getByNumberInvalidBlockNumberDec.

@Test
public void getByNumberInvalidBlockNumberDec() {
    when(blockchain.getBlockByNumber(123)).thenReturn(null);
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> retriever.retrieveExecutionBlock("123"));
    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