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
58 changes: 32 additions & 26 deletions src/itest/java/com/iexec/blockchain/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import com.iexec.blockchain.api.BlockchainAdapterApiClient;
import com.iexec.blockchain.api.BlockchainAdapterApiClientBuilder;
import com.iexec.blockchain.broker.BrokerService;
import com.iexec.blockchain.chain.ChainConfig;
import com.iexec.blockchain.chain.IexecHubService;
import com.iexec.blockchain.chain.Web3jService;
import com.iexec.blockchain.command.generic.SubmittedTx;
import com.iexec.common.chain.adapter.args.TaskFinalizeArgs;
import com.iexec.common.sdk.broker.BrokerOrder;
import com.iexec.commons.poco.chain.*;
import com.iexec.commons.poco.eip712.EIP712Domain;
import com.iexec.commons.poco.encoding.LogTopic;
import com.iexec.commons.poco.encoding.MatchOrdersDataEncoder;
import com.iexec.commons.poco.order.AppOrder;
import com.iexec.commons.poco.order.DatasetOrder;
import com.iexec.commons.poco.order.RequestOrder;
Expand All @@ -44,14 +45,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.web3j.crypto.Hash;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.TransactionException;
import org.web3j.utils.Numeric;

Expand All @@ -76,7 +78,6 @@

@Slf4j
@Testcontainers
@ActiveProfiles("itest")
@SpringBootTest(properties = {"chain.max-allowed-tx-per-block=2"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class IntegrationTests {

Expand Down Expand Up @@ -107,8 +108,8 @@ class IntegrationTests {
@DynamicPropertySource
static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("chain.id", () -> "65535");
registry.add("chain.hubAddress", () -> IEXEC_HUB_ADDRESS);
registry.add("chain.nodeAddress", () -> getServiceUrl(
registry.add("chain.hub-address", () -> IEXEC_HUB_ADDRESS);
registry.add("chain.node-address", () -> getServiceUrl(
environment.getServiceHost(CHAIN_SVC_NAME, CHAIN_SVC_PORT),
environment.getServicePort(CHAIN_SVC_NAME, CHAIN_SVC_PORT)));
registry.add("spring.data.mongodb.host", () -> environment.getServiceHost(MONGO_SVC_NAME, MONGO_SVC_PORT));
Expand All @@ -121,7 +122,6 @@ static void registerProperties(DynamicPropertyRegistry registry) {
private final IexecHubService iexecHubService;
private final Web3jService web3jService;
private final SignerService signerService;
private final BrokerService brokerService;
private final EIP712Domain domain;
private BlockchainAdapterApiClient appClient;

Expand All @@ -133,12 +133,10 @@ static void registerProperties(DynamicPropertyRegistry registry) {
IntegrationTests(final IexecHubService iexecHubService,
final Web3jService web3jService,
final SignerService signerService,
final BrokerService brokerService,
final ChainConfig chainConfig) throws IOException {
this.iexecHubService = iexecHubService;
this.web3jService = web3jService;
this.signerService = signerService;
this.brokerService = brokerService;
this.domain = new EIP712Domain(chainConfig.getId(), chainConfig.getHubAddress());
this.appRegistryAddress = toEthereumAddress(signerService.sendCall(IEXEC_HUB_ADDRESS, APP_REGISTRY_SELECTOR));
this.datasetRegistryAddress = toEthereumAddress(signerService.sendCall(IEXEC_HUB_ADDRESS, DATASET_REGISTRY_SELECTOR));
Expand Down Expand Up @@ -193,7 +191,7 @@ void shouldBeFinalized() throws IOException, TransactionException {
}

@Test
void shouldBurstTransactionsWithAverageOfOneTxPerBlock() throws IOException {
void shouldBurstTransactionsWithAverageOfOneTxPerBlock() throws IOException, TransactionException {
int taskVolume = 10;//small volume ensures reasonable execution time on CI/CD
final String dealId = triggerDeal(taskVolume);
final List<CompletableFuture<Void>> txCompletionWatchers = new ArrayList<>();
Expand Down Expand Up @@ -223,7 +221,7 @@ void shouldBurstTransactionsWithAverageOfOneTxPerBlock() throws IOException {
txCompletionWatchers.forEach(CompletableFuture::join);
}

private String triggerDeal(int taskVolume) throws IOException {
private String triggerDeal(int taskVolume) throws IOException, TransactionException {
BigInteger nonce = signerService.getNonce();
final String appTxData = encodeApp(
signerService.getAddress(),
Expand Down Expand Up @@ -271,14 +269,30 @@ private String triggerDeal(int taskVolume) throws IOException {
.iexecResultStorageProvider("ipfs")
.iexecResultStorageProxy("https://v6.result.goerli.iex.ec")
.build());
final BrokerOrder brokerOrder = BrokerOrder.builder()
.appOrder(signedAppOrder)
.workerpoolOrder(signedWorkerpoolOrder)
.requestOrder(signedRequestOrder)
.datasetOrder(signedDatasetOrder)
.build();

final String dealId = brokerService.matchOrders(brokerOrder);
nonce = nonce.add(BigInteger.ONE);
final String matchOrdersTxData = MatchOrdersDataEncoder.encode(
signedAppOrder, signedDatasetOrder, signedWorkerpoolOrder, signedRequestOrder);
final BigInteger gasLimit = signerService.estimateGas(IEXEC_HUB_ADDRESS, matchOrdersTxData);
final String matchOrdersTxHash = signerService.signAndSendTransaction(
nonce, BigInteger.ZERO, gasLimit, IEXEC_HUB_ADDRESS, matchOrdersTxData);
final TransactionReceipt receipt = iexecHubService.waitForTxMined(
new SubmittedTx(nonce, gasLimit, matchOrdersTxData, matchOrdersTxHash));
log.info("block {}, hash {}, status {}", receipt.getBlockNumber(), receipt.getTransactionHash(), receipt.getStatus());
log.info("logs count {}", receipt.getLogs().size());

final String workerpoolAddress = Numeric.toHexStringWithPrefixZeroPadded(
Numeric.toBigInt(signedWorkerpoolOrder.getWorkerpool()), 64);
final List<String> expectedTopics = List.of(LogTopic.SCHEDULER_NOTICE_EVENT, workerpoolAddress);
List<String> events = receipt.getLogs().stream()
.filter(log -> expectedTopics.equals(log.getTopics()))
.map(Log::getData)
.toList();
log.info("logs {}", events);
if (events.size() != 1) {
throw new IllegalStateException("A single deal should have been created, not " + events.size());
}
final String dealId = events.get(0);
assertThat(dealId).isNotEmpty();
log.info("Created deal: {}", dealId);
// no need to wait since broker is synchronous, just checking deal existence
Expand Down Expand Up @@ -349,13 +363,6 @@ private RequestOrder buildRequestOrder(
DatasetOrder datasetOrder,
String requesterAddress,
DealParams dealParams) {
boolean isCompatibleVolume =
appOrder.getVolume().equals(workerpoolOrder.getVolume())
&& appOrder.getVolume().equals(datasetOrder.getVolume());
if (!isCompatibleVolume) {
log.info("Volumes are not compatible");
return null;
}
final RequestOrder requestOrder = RequestOrder.builder()
.app(appOrder.getApp())
.appmaxprice(appOrder.getAppprice())
Expand All @@ -370,7 +377,6 @@ private RequestOrder buildRequestOrder(
.beneficiary(BytesUtils.EMPTY_ADDRESS)
.requester(requesterAddress)
.callback(BytesUtils.EMPTY_ADDRESS)
//.params("{\"iexec_result_storage_provider\":\"ipfs\",\"iexec_result_storage_proxy\":\"https://v6.result.goerli.iex.ec\",\"iexec_args\":\"abc\"}")
.params(dealParams.toJsonString())
.salt(Hash.sha3String(RandomStringUtils.randomAlphanumeric(20)))
.build();
Expand Down
222 changes: 0 additions & 222 deletions src/main/java/com/iexec/blockchain/broker/BrokerService.java

This file was deleted.

Loading
Loading