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 @@ -17,10 +17,12 @@
package com.iexec.commons.poco.chain;

import com.iexec.commons.poco.contract.generated.IexecHubContract;
import com.iexec.commons.poco.eip712.EIP712Domain;
import com.iexec.commons.poco.task.TaskDescription;
import com.iexec.commons.poco.utils.BytesUtils;
import com.iexec.commons.poco.utils.MultiAddressHelper;
import com.iexec.commons.poco.utils.Retryer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.web3j.abi.FunctionReturnDecoder;
Expand Down Expand Up @@ -56,10 +58,12 @@ public abstract class IexecHubAbstractService {
public static final int MAX_RETRIES = 3;

protected final Credentials credentials;
private final String iexecHubAddress;
protected final RawTransactionManager txManager;
protected final PollingTransactionReceiptProcessor txReceiptProcessor;
protected final IexecHubContract iexecHubContract;
protected final String iexecHubAddress;
@Getter
private final EIP712Domain ordersDomain;
private final Web3jAbstractService web3jAbstractService;
private long maxNbOfPeriodsForConsensus = -1;
private final long retryDelay;// ms
Expand Down Expand Up @@ -109,6 +113,7 @@ protected IexecHubAbstractService(
);

iexecHubContract = getHubContract(web3jAbstractService.getContractGasProvider());
ordersDomain = new EIP712Domain(web3jAbstractService.getChainId(), iexecHubAddress);

log.info("Abstract IexecHubService initialized (iexec proxy address) [hubAddress:{}]",
iexecHubContract.getContractAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void init() throws CipherException, IOException {
web3jService = new Web3jTestService(chainNodeAddress);
iexecHubService = new IexecHubTestService(credentials, web3jService);
signerService = new SignerService(web3jService.getWeb3j(), web3jService.getChainId(), credentials);
ordersService = new OrdersService(signerService);
ordersService = new OrdersService(iexecHubService.getOrdersDomain(), signerService);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void init() throws CipherException, IOException {
web3jService = new Web3jTestService(chainNodeAddress);
iexecHubService = new IexecHubTestService(credentials, web3jService);
signerService = new SignerService(web3jService.getWeb3j(), web3jService.getChainId(), credentials);
ordersService = new OrdersService(signerService);
ordersService = new OrdersService(iexecHubService.getOrdersDomain(), signerService);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@
public class IexecHubTestService extends IexecHubAbstractService {
static final BigInteger GAS_PRICE = BigInteger.valueOf(22_000_000_000L);
static final BigInteger GAS_LIMIT = BigInteger.valueOf(1_000_000L);
static final long CHAIN_ID = 65535L;
static final String IEXEC_HUB_ADDRESS = "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7";

static final String ASSET_MULTI_ADDRESS = "multiAddress";
static final String ASSET_CHECKSUM = Numeric.toHexStringNoPrefix(new byte[32]);

private static final String APP_REGISTRY_SELECTOR = "0x45b637a9";
private static final String DATASET_REGISTRY_SELECTOR = "0xb1b11d2c";
private static final String WORKERPOOL_REGISTRY_SELECTOR = "0x90a0f546";
static final String APP_REGISTRY_SELECTOR = "0x45b637a9";
static final String DATASET_REGISTRY_SELECTOR = "0xb1b11d2c";
static final String WORKERPOOL_REGISTRY_SELECTOR = "0x90a0f546";

private final String ownerAddress;
private final SignerService signerService;
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void init() throws CipherException, IOException {
web3jService = new Web3jTestService(chainNodeAddress);
iexecHubService = new IexecHubTestService(credentials, web3jService);
signerService = new SignerService(web3jService.getWeb3j(), web3jService.getChainId(), credentials);
ordersService = new OrdersService(signerService);
ordersService = new OrdersService(iexecHubService.getOrdersDomain(), signerService);
}

@Test
Expand Down Expand Up @@ -151,10 +151,10 @@ void shouldMatchOrdersWithSignerService() throws IOException {
.isEqualTo(List.of("Transfer", "Lock", "Transfer", "Lock", "SchedulerNotice", "OrdersMatched"));

// orders consumption
assertThat(iexecHubService.viewConsumed(signedAppOrder.computeHash(ordersService.getDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedDatasetOrder.computeHash(ordersService.getDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedWorkerpoolOrder.computeHash(ordersService.getDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedRequestOrder.computeHash(ordersService.getDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedAppOrder.computeHash(iexecHubService.getOrdersDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedDatasetOrder.computeHash(iexecHubService.getOrdersDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedWorkerpoolOrder.computeHash(iexecHubService.getOrdersDomain()))).isEqualTo(BigInteger.ONE);
assertThat(iexecHubService.viewConsumed(signedRequestOrder.computeHash(iexecHubService.getOrdersDomain()))).isEqualTo(BigInteger.ONE);

// estimate gas revert
// 0x694578656356352d6d617463684f72646572732d30783630 is hex string corresponding to the 'iExecV5-matchOrders-0x60' string
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/com/iexec/commons/poco/itest/OrdersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.iexec.commons.poco.encoding.MatchOrdersDataEncoder;
import com.iexec.commons.poco.order.*;
import com.iexec.commons.poco.utils.BytesUtils;
import lombok.Getter;
import org.apache.commons.lang3.RandomStringUtils;
import org.web3j.crypto.Hash;

Expand All @@ -31,21 +30,20 @@
import java.util.Map;
import java.util.TreeMap;

import static com.iexec.commons.poco.itest.IexecHubTestService.*;
import static com.iexec.commons.poco.itest.IexecHubTestService.GAS_PRICE;
import static com.iexec.commons.poco.itest.IexecHubTestService.IEXEC_HUB_ADDRESS;

public class OrdersService {

static final String APP_NAME = "my-app";
static final String DATASET_NAME = "my-dataset";
static final String WORKERPOOL_NAME = "my-workerpool";


@Getter
private final EIP712Domain domain;
private final SignerService signerService;

public OrdersService(SignerService signerService) {
this.domain = new EIP712Domain(CHAIN_ID, IEXEC_HUB_ADDRESS);
public OrdersService(final EIP712Domain domain, final SignerService signerService) {
this.domain = domain;
this.signerService = signerService;
}

Expand Down