Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> getWorkerScore(String address) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call">eth_call JSON-RPC API</a>
*/
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());
}
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -116,7 +116,7 @@ void shouldFailAssertDatasetCompatibilityWhenDealNotFound() throws IOException {
final Map<String, String> 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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -223,15 +223,15 @@ 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\"");

// assertDatasetDealCompatibility checks for a deal without a dataset
for (final Map.Entry<DatasetOrder, String> 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());
}
Expand Down Expand Up @@ -261,6 +261,10 @@ private Map<DatasetOrder, String> 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

}