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