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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
poco-chain:
image: docker-regis.iex.ec/poco-chain:1.1.0-poco-v6.1.0-contracts-voucher-v1.0.0-nethermind
image: docker-regis.iex.ec/poco-chain:1.2.2-poco-v6.2.0-contracts-nethermind
expose:
- "8545"
55 changes: 51 additions & 4 deletions src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -45,14 +48,14 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import static com.iexec.commons.poco.encoding.MatchOrdersDataEncoder.encodeAssertDatasetDealCompatibility;
import static com.iexec.commons.poco.itest.ChainTests.SERVICE_NAME;
import static com.iexec.commons.poco.itest.ChainTests.SERVICE_PORT;
import static com.iexec.commons.poco.itest.IexecHubTestService.*;
import static com.iexec.commons.poco.itest.Web3jTestService.MINING_TIMEOUT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.*;
import static org.awaitility.Awaitility.await;

@Slf4j
Expand Down Expand Up @@ -237,6 +240,51 @@ void shouldMatchOrdersWithoutDataset() throws IOException {
}
}

@ParameterizedTest
@MethodSource("provideValidTags")
void shouldMatchOrdersWithValidTags(final String appTag, final String datasetTag, final String requestTag, final String workerpoolTag) throws IOException {
final Map<String, String> deployedAddresses = iexecHubService.deployAssets();
final AppOrder signedAppOrder = ordersService.buildSignedAppOrder(deployedAddresses.get("app"), appTag);
final DatasetOrder signedDatasetOrder = ordersService.buildSignedDatasetOrder(deployedAddresses.get("dataset"), datasetTag);
final WorkerpoolOrder signedWorkerpoolOrder = ordersService.buildSignedWorkerpoolOrder(deployedAddresses.get("workerpool"), BigInteger.ONE, workerpoolTag);
final RequestOrder signedRequestOrder = ordersService.buildSignedRequestOrder(
signedAppOrder, signedDatasetOrder, signedWorkerpoolOrder, BigInteger.ONE, requestTag);

final String matchOrdersTxData = MatchOrdersDataEncoder.encode(signedAppOrder, signedDatasetOrder, signedWorkerpoolOrder, signedRequestOrder);
assertThatNoException().isThrownBy(() -> signerService.estimateGas(IEXEC_HUB_ADDRESS, matchOrdersTxData));
}

static Stream<Arguments> provideValidTags() {
return Stream.of(
Arguments.of("0x1", "0x1", "0x1", "0x1"),
Arguments.of("0x1", "0x1", "0x0", "0x1"),
Arguments.of("0x1", "0x0", "0x1", "0x1"),
Arguments.of("0x1", "0x0", "0x0", "0x1"),
Arguments.of("0x0", "0x0", "0x0", "0x1"));
}

@ParameterizedTest
@MethodSource("provideInvalidTags")
void shouldNotMatchOrdersWithInvalidTags(final String appTag, final String datasetTag, final String requestTag, final String workerpoolTag) throws IOException {
final Map<String, String> deployedAddresses = iexecHubService.deployAssets();
final AppOrder signedAppOrder = ordersService.buildSignedAppOrder(deployedAddresses.get("app"), appTag);
final DatasetOrder signedDatasetOrder = ordersService.buildSignedDatasetOrder(deployedAddresses.get("dataset"), datasetTag);
final WorkerpoolOrder signedWorkerpoolOrder = ordersService.buildSignedWorkerpoolOrder(deployedAddresses.get("workerpool"), BigInteger.ONE, workerpoolTag);
final RequestOrder signedRequestOrder = ordersService.buildSignedRequestOrder(
signedAppOrder, signedDatasetOrder, signedWorkerpoolOrder, BigInteger.ONE, requestTag);

final String matchOrdersTxData = MatchOrdersDataEncoder.encode(signedAppOrder, signedDatasetOrder, signedWorkerpoolOrder, signedRequestOrder);
assertThatThrownBy(() -> signerService.estimateGas(IEXEC_HUB_ADDRESS, matchOrdersTxData))
.isInstanceOf(JsonRpcError.class)
.hasMessage("iExecV5-matchOrders-0x07");
}

static Stream<Arguments> provideInvalidTags() {
return Stream.of(
Arguments.of("0x0", "0x0", "0x1", "0x1"),
Arguments.of("0x0", "0x1", "0x0", "0x1"));
}

// region utils
private DatasetOrder.DatasetOrderBuilder getValidOrderBuilder(final String datasetAddress) {
return DatasetOrder.builder()
Expand All @@ -257,8 +305,7 @@ private Map<DatasetOrder, String> getInvalidOrders(final String datasetAddress)
Map.entry(getValidOrderBuilder(datasetAddress).apprestrict(IEXEC_HUB_ADDRESS).build(), "App restriction not satisfied"),
Map.entry(getValidOrderBuilder(datasetAddress).workerpoolrestrict(IEXEC_HUB_ADDRESS).build(), "Workerpool restriction not satisfied"),
Map.entry(getValidOrderBuilder(datasetAddress).requesterrestrict(IEXEC_HUB_ADDRESS).build(), "Requester restriction not satisfied"),
Map.entry(getValidOrderBuilder(datasetAddress).tag(OrderTag.TEE_GRAMINE.getValue()).build(), "Tag compatibility not satisfied"),
Map.entry(getValidOrderBuilder(datasetAddress).tag(OrderTag.TEE_TDX.getValue()).build(), "Tag compatibility not satisfied")
Map.entry(getValidOrderBuilder(datasetAddress).tag("0xFF").build(), "Tag compatibility not satisfied")
);
}

Expand Down
34 changes: 26 additions & 8 deletions src/test/java/com/iexec/commons/poco/itest/OrdersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ public OrdersService(final EIP712Domain domain, final SignerService signerServic
this.signerService = signerService;
}

public AppOrder buildSignedAppOrder(String appAddress) {
public AppOrder buildSignedAppOrder(final String appAddress) {
return buildSignedAppOrder(appAddress, OrderTag.TEE_SCONE.getValue());
}

public AppOrder buildSignedAppOrder(final String appAddress, final String tag) {
final AppOrder appOrder = AppOrder.builder()
.app(appAddress)
.appprice(BigInteger.ZERO)
.volume(BigInteger.ONE)
.tag(OrderTag.TEE_SCONE.getValue())
.tag(tag)
.datasetrestrict(BytesUtils.EMPTY_ADDRESS)
.workerpoolrestrict(BytesUtils.EMPTY_ADDRESS)
.requesterrestrict(BytesUtils.EMPTY_ADDRESS)
Expand All @@ -61,12 +65,16 @@ public AppOrder buildSignedAppOrder(String appAddress) {
return (AppOrder) signerService.signOrderForDomain(appOrder, domain);
}

public DatasetOrder buildSignedDatasetOrder(String datasetAddress) {
public DatasetOrder buildSignedDatasetOrder(final String datasetAddress) {
return buildSignedDatasetOrder(datasetAddress, OrderTag.TEE_SCONE.getValue());
}

public DatasetOrder buildSignedDatasetOrder(final String datasetAddress, final String tag) {
final DatasetOrder datasetOrder = DatasetOrder.builder()
.dataset(datasetAddress)
.datasetprice(BigInteger.ZERO)
.volume(BigInteger.ONE)
.tag(OrderTag.TEE_SCONE.getValue())
.tag(tag)
.apprestrict(BytesUtils.EMPTY_ADDRESS)
.workerpoolrestrict(BytesUtils.EMPTY_ADDRESS)
.requesterrestrict(BytesUtils.EMPTY_ADDRESS)
Expand All @@ -75,12 +83,16 @@ public DatasetOrder buildSignedDatasetOrder(String datasetAddress) {
return (DatasetOrder) signerService.signOrderForDomain(datasetOrder, domain);
}

public WorkerpoolOrder buildSignedWorkerpoolOrder(String workerpoolAddress, BigInteger trust) {
public WorkerpoolOrder buildSignedWorkerpoolOrder(final String workerpoolAddress, final BigInteger trust) {
return buildSignedWorkerpoolOrder(workerpoolAddress, trust, OrderTag.TEE_SCONE.getValue());
}

public WorkerpoolOrder buildSignedWorkerpoolOrder(final String workerpoolAddress, final BigInteger trust, final String tag) {
final WorkerpoolOrder workerpoolOrder = WorkerpoolOrder.builder()
.workerpool(workerpoolAddress)
.workerpoolprice(BigInteger.ZERO)
.volume(BigInteger.ONE)
.tag(OrderTag.TEE_SCONE.getValue())
.tag(tag)
.category(BigInteger.ZERO)
.trust(trust)
.apprestrict(BytesUtils.EMPTY_ADDRESS)
Expand All @@ -91,7 +103,13 @@ public WorkerpoolOrder buildSignedWorkerpoolOrder(String workerpoolAddress, BigI
return (WorkerpoolOrder) signerService.signOrderForDomain(workerpoolOrder, domain);
}

public RequestOrder buildSignedRequestOrder(AppOrder appOrder, DatasetOrder datasetOrder, WorkerpoolOrder workerpoolOrder, BigInteger trust) {
public RequestOrder buildSignedRequestOrder(
final AppOrder appOrder, final DatasetOrder datasetOrder, final WorkerpoolOrder workerpoolOrder, final BigInteger trust) {
return buildSignedRequestOrder(appOrder, datasetOrder, workerpoolOrder, trust, OrderTag.TEE_SCONE.getValue());
}

public RequestOrder buildSignedRequestOrder(
final AppOrder appOrder, final DatasetOrder datasetOrder, final WorkerpoolOrder workerpoolOrder, final BigInteger trust, final String tag) {
final TreeMap<String, String> iexecSecrets = new TreeMap<>(Map.of(
"1", "first-secret",
"2", "second-secret",
Expand All @@ -111,7 +129,7 @@ public RequestOrder buildSignedRequestOrder(AppOrder appOrder, DatasetOrder data
.workerpoolmaxprice(workerpoolOrder.getWorkerpoolprice())
.requester(signerService.getAddress())
.volume(BigInteger.ONE)
.tag(OrderTag.TEE_SCONE.getValue())
.tag(tag)
.category(BigInteger.ZERO)
.trust(trust)
.beneficiary(signerService.getAddress())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Web3jTestService(String chainNodeAddress) {
}

public Web3jTestService(String chainNodeAddress, float gasPriceMultiplier, long gasPriceCap) {
this(chainNodeAddress, gasPriceMultiplier, gasPriceCap, true);
this(chainNodeAddress, gasPriceMultiplier, gasPriceCap, false);
}

public Web3jTestService(String chainNodeAddress, float gasPriceMultiplier, long gasPriceCap, boolean isSidechain) {
Expand Down