diff --git a/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java b/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java index 3e29f19..50d775e 100644 --- a/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java @@ -436,7 +436,7 @@ private String sendCallAndDecodeDynamicBytes(final String address, final String * @throws IOException on communication error */ private String sendCallAndGetRawResult(final String address, final String selector) throws IOException { - return web3jAbstractService.sendCall(address, selector); + return web3jAbstractService.sendCall(credentials.getAddress(), address, selector); } public Optional getWorkerScore(String address) { @@ -546,7 +546,7 @@ public boolean isTeeTask(String chainTaskId) { public void assertDatasetDealCompatibility(final DatasetOrder datasetOrder, final String dealId) throws IOException { final String txData = MatchOrdersDataEncoder.encodeAssertDatasetDealCompatibility(datasetOrder, dealId); - web3jAbstractService.sendCall(iexecHubAddress, txData); + web3jAbstractService.sendCall(credentials.getAddress(), iexecHubAddress, txData); } /** @@ -580,12 +580,12 @@ public BigInteger getFinalDeadlineRatio() throws IOException { } private BigInteger sendCallWithFunctionSelector(final String functionSelector) throws IOException { - return toBigInt(web3jAbstractService.sendCall(iexecHubAddress, functionSelector)); + return toBigInt(web3jAbstractService.sendCall(credentials.getAddress(), iexecHubAddress, functionSelector)); } public String getOwner(final String address) { try { - return toEthereumAddress(web3jAbstractService.sendCall(address, OWNER_SELECTOR)); + return toEthereumAddress(web3jAbstractService.sendCall(credentials.getAddress(), address, OWNER_SELECTOR)); } catch (Exception e) { log.error("Failed to get owner [address:{}]", address, e); } @@ -602,7 +602,7 @@ public String getOwner(final String address) { */ public BigInteger viewConsumed(final String typedHash) throws IOException { final String payload = VIEW_CONSUMED_SELECTOR + Numeric.cleanHexPrefix(typedHash); - return toBigInt(web3jAbstractService.sendCall(iexecHubAddress, payload)); + return toBigInt(web3jAbstractService.sendCall(credentials.getAddress(), iexecHubAddress, payload)); } // endregion diff --git a/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java b/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java index dabb89a..62df0b9 100644 --- a/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java @@ -209,19 +209,20 @@ public boolean isBlockAvailable(long blockNumber) { * The {@code sendCall} method can throw runtime exceptions, specifically {@code JsonRpcError}. * Those exceptions must be caught and handled properly in the business code. * + * @param from Wallet address sending the query, mandatory on Arbitrum * @param to Contract address to send the call to * @param data Encoded data representing the method to call with its parameters * @return A single value returned by the called method. * @throws IOException in case of communication failure with the blockchain network. * @see eth_call JSON-RPC API */ - public String sendCall(final String to, final String data) throws IOException { - return sendCall(to, data, DefaultBlockParameterName.LATEST); + public String sendCall(final String from, final String to, final String data) throws IOException { + return sendCall(from, to, data, DefaultBlockParameterName.LATEST); } - public String sendCall(final String to, final String data, final DefaultBlockParameter defaultBlockParameter) throws IOException { + public String sendCall(final String from, final String to, final String data, final DefaultBlockParameter defaultBlockParameter) throws IOException { final EthCall ethCall = web3j.ethCall( - createEthCallTransaction("", to, data), defaultBlockParameter).send(); + createEthCallTransaction(from, to, data), defaultBlockParameter).send(); if (ethCall.hasError()) { decodeAndThrowEvmRpcError(ethCall.getError()); } diff --git a/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java b/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java index 36fb6bc..16fea28 100644 --- a/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java +++ b/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java @@ -94,7 +94,7 @@ void shouldFailAssertDatasetDealCompatibilityWhenBadlySignedWhenConsumed() throw final DatasetOrder datasetOrder = getValidOrderBuilder(deployedAddresses.get("dataset")).volume(BigInteger.ZERO).build(); final DatasetOrder signedDatasetOrder = (DatasetOrder) signerService.signOrderForDomain(datasetOrder, iexecHubService.getOrdersDomain()); final String assertDatasetDealCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedDatasetOrder, CHAIN_DEAL_ID); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertDatasetDealCompatibilityTxData)) + assertThatThrownBy(() -> sendCall(assertDatasetDealCompatibilityTxData)) .isInstanceOf(JsonRpcError.class) .hasMessage("Dataset order is revoked or fully consumed"); } @@ -106,7 +106,7 @@ void shouldFailAssertDatasetDealCompatibilityWhenBadlySigned() throws IOExceptio final SignerService otherSigner = new SignerService(null, web3jService.getChainId(), Credentials.create(Keys.createEcKeyPair())); final DatasetOrder signedDatasetOrder = (DatasetOrder) otherSigner.signOrderForDomain(datasetOrder, iexecHubService.getOrdersDomain()); final String assertDatasetDealCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedDatasetOrder, CHAIN_DEAL_ID); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertDatasetDealCompatibilityTxData)) + assertThatThrownBy(() -> sendCall(assertDatasetDealCompatibilityTxData)) .isInstanceOf(JsonRpcError.class) .hasMessage("Invalid dataset order signature"); } @@ -116,7 +116,7 @@ void shouldFailAssertDatasetCompatibilityWhenDealNotFound() throws IOException { final Map deployedAddresses = iexecHubService.deployAssets(); final DatasetOrder signedDatasetOrder = ordersService.buildSignedDatasetOrder(deployedAddresses.get("dataset")); final String assertDatasetDealCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedDatasetOrder, CHAIN_DEAL_ID); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertDatasetDealCompatibilityTxData)) + assertThatThrownBy(() -> sendCall(assertDatasetDealCompatibilityTxData)) .isInstanceOf(JsonRpcError.class) .hasMessage("Deal not found"); } @@ -171,14 +171,14 @@ void shouldMatchOrdersWithDataset() throws IOException { // assertDatasetDealCompatibility reverts for fully consumed dataset final String assertDatasetDealCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedDatasetOrder, chainDealId); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertDatasetDealCompatibilityTxData)) + assertThatThrownBy(() -> sendCall(assertDatasetDealCompatibilityTxData)) .isInstanceOf(JsonRpcError.class) .hasMessage("Dataset order is revoked or fully consumed"); // assertDatasetDealCompatibility reverts if deal has a dataset final DatasetOrder invalidDatasetOrder = getValidOrderBuilder(deployedAddresses.get("dataset")).build(); final DatasetOrder signedInvalidDatasetOrder = (DatasetOrder) signerService.signOrderForDomain(invalidDatasetOrder, iexecHubService.getOrdersDomain()); final String txData = MatchOrdersDataEncoder.encodeAssertDatasetDealCompatibility(signedInvalidDatasetOrder, chainDealId); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, txData)) + assertThatThrownBy(() -> sendCall(txData)) .isInstanceOf(JsonRpcError.class) .hasMessage("Deal already has a dataset"); } @@ -223,7 +223,7 @@ void shouldMatchOrdersWithoutDataset() throws IOException { // assertDatasetDealCompatibility revert when dataset not present final String assertDatasetDealCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedDatasetOrder, chainDealId); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertDatasetDealCompatibilityTxData)) + assertThatThrownBy(() -> sendCall(assertDatasetDealCompatibilityTxData)) .isInstanceOf(JsonRpcError.class) .hasMessage("\"revert\""); @@ -231,7 +231,7 @@ void shouldMatchOrdersWithoutDataset() throws IOException { for (final Map.Entry entry : getInvalidOrders(deployedAddresses.get("dataset")).entrySet()) { final DatasetOrder signedInvalidDatasetOrder = (DatasetOrder) signerService.signOrderForDomain(entry.getKey(), iexecHubService.getOrdersDomain()); final String assertCompatibilityTxData = encodeAssertDatasetDealCompatibility(signedInvalidDatasetOrder, chainDealId); - assertThatThrownBy(() -> web3jService.sendCall(IEXEC_HUB_ADDRESS, assertCompatibilityTxData), entry.getValue()) + assertThatThrownBy(() -> sendCall(assertCompatibilityTxData), entry.getValue()) .isInstanceOf(JsonRpcError.class) .hasMessage(entry.getValue()); } @@ -261,6 +261,10 @@ private Map getInvalidOrders(final String datasetAddress) Map.entry(getValidOrderBuilder(datasetAddress).tag(OrderTag.TEE_TDX.getValue()).build(), "Tag compatibility not satisfied") ); } + + private void sendCall(final String txData) throws IOException { + web3jService.sendCall(signerService.getAddress(), IEXEC_HUB_ADDRESS, txData); + } // endregion }