Search in sources :

Example 6 with Request

use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.

the class ExtensionService method cancelExtension.

public Observable<QuorumCancel> cancelExtension(final QuorumNetworkProperty.Node node, final String address, final Set<QuorumNetworkProperty.Node> allNodes, final PrivacyFlag privacyFlag) {
    final List<String> privateFor = allNodes.stream().filter(n -> !n.equals(node)).map(n -> privacyService.id(n)).collect(Collectors.toList());
    final PrivateTransaction transactionArgs = new EnhancedPrivateTransaction(accountService.getDefaultAccountAddress(node).blockingFirst(), null, null, null, BigInteger.ZERO, null, privacyService.id(node), privateFor, singletonList(privacyFlag));
    return new Request<>("quorumExtension_cancelExtension", Stream.of(address, transactionArgs).collect(Collectors.toList()), connectionFactory().getWeb3jService(node), QuorumCancel.class).flowable().toObservable();
}
Also used : PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) Collections.emptyList(java.util.Collections.emptyList) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) Request(org.web3j.protocol.core.Request) Collections.singletonList(java.util.Collections.singletonList) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Service(org.springframework.stereotype.Service) com.quorum.gauge.ext.contractextension(com.quorum.gauge.ext.contractextension) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) Request(org.web3j.protocol.core.Request)

Example 7 with Request

use of org.web3j.protocol.core.Request in project besu by hyperledger.

the class PrivCallAcceptanceTest method privCall.

@Nonnull
private Request<Object, EthCall> privCall(final String privacyGroupId, final Contract eventEmitter, final boolean useInvalidParameters, final boolean useInvalidContractAddress) {
    final Uint256 invalid = new Uint256(BigInteger.TEN);
    @SuppressWarnings("rawtypes") final List<Type> inputParameters = useInvalidParameters ? Arrays.asList(invalid) : Collections.emptyList();
    final Function function = new Function("value", inputParameters, Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
    }));
    final String encoded = FunctionEncoder.encode(function);
    final HttpService httpService = new HttpService("http://" + minerNode.getBesu().getHostName() + ":" + minerNode.getBesu().getJsonRpcPort().get());
    final String validContractAddress = eventEmitter.getContractAddress();
    final String invalidContractAddress = constructInvalidString(validContractAddress);
    final String contractAddress = useInvalidContractAddress ? invalidContractAddress : validContractAddress;
    final Transaction transaction = Transaction.createEthCallTransaction(null, contractAddress, encoded);
    return new Request<>("priv_call", Arrays.asList(privacyGroupId, transaction, "latest"), httpService, EthCall.class);
}
Also used : Function(org.web3j.abi.datatypes.Function) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Type(org.web3j.abi.datatypes.Type) EnclaveType(org.hyperledger.enclave.testutil.EnclaveType) Transaction(org.web3j.protocol.core.methods.request.Transaction) HttpService(org.web3j.protocol.http.HttpService) Request(org.web3j.protocol.core.Request) Uint256(org.web3j.abi.datatypes.generated.Uint256) TypeReference(org.web3j.abi.TypeReference) Nonnull(javax.annotation.Nonnull)

Example 8 with Request

use of org.web3j.protocol.core.Request in project web3j by web3j.

the class ClientTransactionManagerTest method sendCallErrorRevertByCode.

@Test
void sendCallErrorRevertByCode() throws IOException {
    EthCall lookupDataHex = new EthCall();
    Response.Error error = new Response.Error();
    error.setCode(10);
    error.setData(responseData);
    lookupDataHex.setError(error);
    Request request = mock(Request.class);
    when(request.send()).thenReturn(lookupDataHex);
    when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameter.class))).thenReturn(request);
    assertThrows(ContractCallException.class, () -> clientTransactionManager.sendCall("0xAdress", "data", DefaultBlockParameter.valueOf("latest")));
}
Also used : Response(org.web3j.protocol.core.Response) DefaultBlockParameter(org.web3j.protocol.core.DefaultBlockParameter) Transaction(org.web3j.protocol.core.methods.request.Transaction) Request(org.web3j.protocol.core.Request) EthCall(org.web3j.protocol.core.methods.response.EthCall) Test(org.junit.jupiter.api.Test)

Example 9 with Request

use of org.web3j.protocol.core.Request in project web3j by web3j.

the class ClientTransactionManagerTest method sendCallErrorSuccess.

@Test
void sendCallErrorSuccess() throws IOException {
    EthCall lookupDataHex = new EthCall();
    lookupDataHex.setResult(responseData);
    Request request = mock(Request.class);
    when(request.send()).thenReturn(lookupDataHex);
    when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameter.class))).thenReturn(request);
    String result = clientTransactionManager.sendCall("0xAdress", "data", DefaultBlockParameter.valueOf("latest"));
    assertEquals(responseData, result);
}
Also used : DefaultBlockParameter(org.web3j.protocol.core.DefaultBlockParameter) Transaction(org.web3j.protocol.core.methods.request.Transaction) Request(org.web3j.protocol.core.Request) EthCall(org.web3j.protocol.core.methods.response.EthCall) Test(org.junit.jupiter.api.Test)

Example 10 with Request

use of org.web3j.protocol.core.Request in project web3j by web3j.

the class HttpServiceTest method httpWebException.

@Test
public void httpWebException() throws IOException {
    String content = "400 error";
    Response response = new Response.Builder().code(400).message("").body(ResponseBody.create(content, null)).request(new okhttp3.Request.Builder().url(HttpService.DEFAULT_URL).build()).protocol(Protocol.HTTP_1_1).build();
    OkHttpClient httpClient = Mockito.mock(OkHttpClient.class);
    Mockito.when(httpClient.newCall(Mockito.any())).thenAnswer(invocation -> {
        Call call = Mockito.mock(Call.class);
        Mockito.when(call.execute()).thenReturn(response);
        return call;
    });
    HttpService mockedHttpService = new HttpService(httpClient);
    Request<String, EthBlockNumber> request = new Request<>("eth_blockNumber1", Collections.emptyList(), mockedHttpService, EthBlockNumber.class);
    try {
        mockedHttpService.send(request, EthBlockNumber.class);
    } catch (ClientConnectionException e) {
        assertEquals(e.getMessage(), "Invalid response received: " + response.code() + "; " + content);
        return;
    }
    fail("No exception");
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) EthBlockNumber(org.web3j.protocol.core.methods.response.EthBlockNumber) ClientConnectionException(org.web3j.protocol.exceptions.ClientConnectionException) OkHttpClient(okhttp3.OkHttpClient) Request(org.web3j.protocol.core.Request) Test(org.junit.jupiter.api.Test)

Aggregations

Request (org.web3j.protocol.core.Request)25 Test (org.junit.jupiter.api.Test)8 Response (org.web3j.protocol.core.Response)8 BigInteger (java.math.BigInteger)7 Collectors (java.util.stream.Collectors)7 Transaction (org.web3j.protocol.core.methods.request.Transaction)7 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)6 List (java.util.List)6 Service (org.springframework.stereotype.Service)6 DefaultBlockParameter (org.web3j.protocol.core.DefaultBlockParameter)6 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)5 QuorumNode (com.quorum.gauge.common.QuorumNode)5 Observable (io.reactivex.Observable)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 EthCall (org.web3j.protocol.core.methods.response.EthCall)5 Node (com.quorum.gauge.common.QuorumNetworkProperty.Node)3 EnhancedPrivateTransaction (com.quorum.gauge.ext.EnhancedPrivateTransaction)3 com.quorum.gauge.ext.contractextension (com.quorum.gauge.ext.contractextension)3 IOException (java.io.IOException)3 Collections.emptyList (java.util.Collections.emptyList)3