@Override public Request<?, EthBlock> ethGetBlockByNumber( DefaultBlockParameter defaultBlockParameter, boolean returnFullTransactionObjects) { return new Request<>( "eth_getBlockByNumber", Arrays.asList( defaultBlockParameter.getValue(), returnFullTransactionObjects), web3jService, EthBlock.class); }
@Test public void testEthCall() throws Exception { EthCall ethCall = web3j.ethCall(config.buildTransaction(), DefaultBlockParameter.valueOf("latest")).send(); assertThat(DefaultBlockParameterName.LATEST.getValue(), is("latest")); assertThat(ethCall.getValue(), is("0x")); }
@Test public void testEthGetUncleCountByBlockNumber() throws Exception { EthGetUncleCountByBlockNumber ethGetUncleCountByBlockNumber = web3j.ethGetUncleCountByBlockNumber( DefaultBlockParameter.valueOf("latest")).send(); assertThat(ethGetUncleCountByBlockNumber.getUncleCount(), equalTo(config.validBlockUncleCount())); }
@Test public void testEthGetStorageAt() throws Exception { EthGetStorageAt ethGetStorageAt = web3j.ethGetStorageAt( config.validContractAddress(), BigInteger.valueOf(0), DefaultBlockParameter.valueOf("latest")).send(); assertThat(ethGetStorageAt.getData(), is(config.validContractAddressPositionZero())); }
@Override public Request<?, EthAccounts> clicqueGetSigners(DefaultBlockParameter defaultBlockParameter) { return new Request<>( "clique_getSigners", Arrays.asList(defaultBlockParameter.getValue()), web3jService, EthAccounts.class); }
@Test public void testEthGetLogsWithNumericBlockRange() throws Exception { web3j.ethGetLogs(new EthFilter( DefaultBlockParameter.valueOf(Numeric.toBigInt("0xe8")), DefaultBlockParameter.valueOf("latest"), "")) .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\"," + "\"params\":[{\"topics\":[],\"fromBlock\":\"0xe8\"," + "\"toBlock\":\"latest\",\"address\":[\"\"]}],\"id\":1}"); }
@Override public Request<?, EthGetCode> ethGetCode( String address, DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getCode", Arrays.asList(address, defaultBlockParameter.getValue()), web3jService, EthGetCode.class); }
@Test public void testEthGetTransactionByBlockNumberAndIndex() throws Exception { BigInteger index = BigInteger.ONE; EthTransaction ethTransaction = web3j.ethGetTransactionByBlockNumberAndIndex( DefaultBlockParameter.valueOf(config.validBlock()), index).send(); assertTrue(ethTransaction.getTransaction().isPresent()); Transaction transaction = ethTransaction.getTransaction().get(); assertThat(transaction.getBlockHash(), is(config.validBlockHash())); assertThat(transaction.getTransactionIndex(), equalTo(index)); }
@Override public Request<?, EthGetBlockTransactionCountByNumber> ethGetBlockTransactionCountByNumber( DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getBlockTransactionCountByNumber", Arrays.asList(defaultBlockParameter.getValue()), web3jService, EthGetBlockTransactionCountByNumber.class); }
@Test public void testEthGetBlockByNumberReturnTransactionObjects() throws Exception { EthBlock ethBlock = web3j.ethGetBlockByNumber( DefaultBlockParameter.valueOf(config.validBlock()), true).send(); EthBlock.Block block = ethBlock.getBlock(); assertNotNull(ethBlock.getBlock()); assertThat(block.getNumber(), equalTo(config.validBlock())); assertThat(block.getTransactions().size(), equalTo(config.validBlockTransactionCount().intValue())); }
@Override public Request<?, EthGetUncleCountByBlockNumber> ethGetUncleCountByBlockNumber( DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getUncleCountByBlockNumber", Arrays.asList(defaultBlockParameter.getValue()), web3jService, EthGetUncleCountByBlockNumber.class); }
@Test public void testEthGetBlockTransactionCountByNumber() throws Exception { EthGetBlockTransactionCountByNumber ethGetBlockTransactionCountByNumber = web3j.ethGetBlockTransactionCountByNumber( DefaultBlockParameter.valueOf(config.validBlock())).send(); assertThat(ethGetBlockTransactionCountByNumber.getTransactionCount(), equalTo(config.validBlockTransactionCount())); }
@Override public Request<?, EthGetBalance> ethGetBalance( String address, DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getBalance", Arrays.asList(address, defaultBlockParameter.getValue()), web3jService, EthGetBalance.class); }
@Test public void testEthGetBlockByNumberReturnHashObjects() throws Exception { EthBlock ethBlock = web3j.ethGetBlockByNumber( DefaultBlockParameter.valueOf(config.validBlock()), false).send(); EthBlock.Block block = ethBlock.getBlock(); assertNotNull(ethBlock.getBlock()); assertThat(block.getNumber(), equalTo(config.validBlock())); assertThat(block.getTransactions().size(), equalTo(config.validBlockTransactionCount().intValue())); }
@Override public Request<?, EthGetTransactionCount> ethGetTransactionCount( String address, DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getTransactionCount", Arrays.asList(address, defaultBlockParameter.getValue()), web3jService, EthGetTransactionCount.class); }
@Test public void testEthGetCode() throws Exception { EthGetCode ethGetCode = web3j.ethGetCode(config.validContractAddress(), DefaultBlockParameter.valueOf(config.validBlock())).send(); assertThat(ethGetCode.getCode(), is(config.validContractCode())); }
@Override public Request<?, EthBlock> ethGetUncleByBlockNumberAndIndex( DefaultBlockParameter defaultBlockParameter, BigInteger uncleIndex) { return new Request<>( "eth_getUncleByBlockNumberAndIndex", Arrays.asList( defaultBlockParameter.getValue(), Numeric.encodeQuantity(uncleIndex)), web3jService, EthBlock.class); }
@Test public void testClicqueGetSigners() throws Exception { final DefaultBlockParameter blockParameter = DefaultBlockParameter.valueOf("latest"); web3j.clicqueGetSigners(blockParameter).send(); verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"clique_getSigners\"," + "\"params\":[\"latest\"],\"id\":1}"); }
@Override public Request<?, EthGetStorageAt> ethGetStorageAt( String address, BigInteger position, DefaultBlockParameter defaultBlockParameter) { return new Request<>( "eth_getStorageAt", Arrays.asList( address, Numeric.encodeQuantity(position), defaultBlockParameter.getValue()), web3jService, EthGetStorageAt.class); }
@Test public void testEthGetBalance() throws Exception { EthGetBalance ethGetBalance = web3j.ethGetBalance( config.validAccount(), DefaultBlockParameter.valueOf("latest")).send(); assertTrue(ethGetBalance.getBalance().signum() == 1); }