Search in sources :

Example 16 with RskJsonRpcRequestException

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

the class ExecutionFoundBlockRetrieverTest method getByNumberInvalidHex.

@Test
public void getByNumberInvalidHex() {
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> retriever.retrieveExecutionBlock("0xzz"));
    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 17 with RskJsonRpcRequestException

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

the class Web3InformationRetrieverTest method getBlock_invalidIdentifier.

@Test
public void getBlock_invalidIdentifier() {
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> target.getBlock("pending2"));
    assertEquals(INVALID_PARAM_ERROR_CODE, (int) e.getCode());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Example 18 with RskJsonRpcRequestException

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

the class Web3InformationRetrieverTest method getTransactions_blockNotFound.

@Test
public void getTransactions_blockNotFound() {
    RskJsonRpcRequestException e = TestUtils.assertThrows(RskJsonRpcRequestException.class, () -> target.getTransactions("0x3"));
    assertEquals(-32600, (int) e.getCode());
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Test(org.junit.Test)

Example 19 with RskJsonRpcRequestException

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

the class NestedContractsTest method testNested_interfaceCall_require.

/**
 * ------------------------ **
 *  TESTS
 ** ------------------------ *
 */
@Test
public void testNested_interfaceCall_require() throws FileNotFoundException, DslProcessorException {
    processor.processCommands(DslParser.fromResource("dsl/contract_call/contract_nested_interface_calls.txt"));
    assertFalse(world.getTransactionReceiptByName("tx04").isSuccessful());
    assertTrue(world.getTransactionReceiptByName("tx05").isSuccessful());
    // Assert state: RevertReason.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTRR, BLOCK_CONTRACT_CREATE, DataWord.ZERO));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTRR, BLOCK_TRANSACTION_FAIL, DataWord.ZERO));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTRR, BLOCK_TRANSACTION_SUCCESS, DataWord.ZERO));
    // Assert state: ContractB.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTB, BLOCK_CONTRACT_CREATE, DataWord.ONE));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTB, BLOCK_TRANSACTION_FAIL, DataWord.ONE));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTB, BLOCK_TRANSACTION_SUCCESS, DataWord.ONE));
    // Assert state: ContractA.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTA, BLOCK_CONTRACT_CREATE, DataWord.ONE));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTA, BLOCK_TRANSACTION_FAIL, DataWord.ONE));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTA, BLOCK_TRANSACTION_SUCCESS, DataWord.ONE));
    // Failed Call ContractA.buy(0) -> 0 > 0
    final String contractA = getContractAddressString(TX_CONTRACTA);
    CallArguments args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(0)));
    try {
        ethModule.call(args, "latest");
        fail();
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("Negative value"));
    }
    // Success Call -> 2 > 0
    args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(2)));
    final String call = ethModule.call(args, "latest");
// assertEquals("0x" + DataWord.valueOf(2).toString(), call);
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) CallArguments(org.ethereum.rpc.CallArguments) 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