diff --git a/CHANGELOG.md b/CHANGELOG.md index 2069346..1a98948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,17 +2,42 @@ All notable changes to this project will be documented in this file. +## [[3.2.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.2.0) 2023-12-19 + +### New Features + +- Add `contributionDeadline` and `finalDeadline` fields to `TaskDescription`. (#65) + +### Bug Fixes + +- Remove unsupported `post-compute` related fields from `DealParams` and `TaskDescription`. (#58) +- Dataset names can be empty in Poco deals. (#59) +- Catch all exceptions when reading the latest block number on the blockchain network. (#60) +- Remove methods from `IexecHubAbstractService`, they were unused or moved to `iexec-core`. (#63) +- Write PoCo orders classes `toString` implementations with compliant fields ordering. (#64) + +### Dependency Upgrades + +- Upgrade to Spring Boot 2.7.17. (#62) +- Upgrade to `jenkins-library` 2.7.4. (#61) +- Upgrade to `testcontainers` 1.19.3. (#62) + ## [[3.1.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.1.0) 2023-09-25 ### New Features + - Add `isEligibleToContributeAndFinalize` method to `TaskDescription`. (#53) - Use `RawTransactionManager` instance to create App, Dataset and Workerpool on-chain in one block. (#54) + ### Quality + - Do not run tests in `itest` task to avoid executing them twice. (#47) - Upgrade to Gradle 8.2.1 with up-to-date plugins. (#49) - Fetch contribution deadline ratio during `@PostConstruct` execution in `IexecHubAbstractService`. (#51) - Remove dead code in `IexecHubAbstractService` and `Web3jAbstractService`. (#54 #55) + ### Dependency Upgrades + - Upgrade to Spring Boot 2.7.14. (#48) - Upgrade to `testcontainers` 1.19.0. (#50) - Upgrade to `jenkins-library` 2.7.3. (#52) @@ -20,36 +45,47 @@ All notable changes to this project will be documented in this file. ## [[3.0.5]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.5) 2023-06-26 ### Bug Fixes + - Fix regression on dataset URI decryption in `TaskDescription`. The regression concerned bad interpretation of IPFS MultiAddress URIs. (#45) ## [[3.0.4]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.4) 2023-06-23 ### Bug Fixes + - Fix regression on `DealParams` deserialization. (#43) ## [[3.0.3]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.3) 2023-06-22 ### New Features + - Add IPFS gateways list and replace `convertToURI` with `isMultiAddress` in `MultiAddressHelper`. (#40) + ### Quality + - Improve `Web3jAbstractService` as well as its coverage. (#41) ## [[3.0.2]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.2) 2023-06-07 ### Bug Fixes + - Do not check connection on blockchain node in `Web3jAbstractService` constructor. (#37) - Properly handle `InterruptedException` instances caught in `WaitUtils`. (#37) ## [[3.0.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.0) 2023-06-05 ### New Features + - Call `IexecHubContract#viewDeal` instead of legacy ABI in `IexecHubAbstractService#getChainDeal`. (#24) - Representations of on-chain and off-chain objects are now immutable. (#24 #25 #26 #30 #34) + ### Bug Fixes + - Do not cast `retryDelay` to `int` in `IexecHubAbstractService` and `Retryer`. (#32) - Move `blockTime` from `IexecHubAbstractService` to `Web3jAbstractService`. (#33) - Set some logs to `debug` level in `EIP712Entity`. (#33) + ### Quality + - Move methods to get event blocks to `iexec-core`. (#28) - Add `IexecHubTestService` and `Web3jTestService` classes for tests. (#29) - Load `IexecHubContract` instance only once in `IexecHubAbstractService`. (#31) @@ -57,14 +93,18 @@ All notable changes to this project will be documented in this file. ## [[2.0.1]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v2.0.1) 2023-05-22 ### New Features + - Add purge cached task descriptions ability. (#20) + ### Bug Fixes + - Pull `poco-chain` image before tests. (#18) - Keep a security factor of 10 for callback gas consumption during `finalize` and `contributeAndFinalize`. (#22) ## [[2.0.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v2.0.0) 2023-05-11 ### New Features + - Upgrade `web3j` dependency from 4.8.9 to 4.9.7. (#8) - Regenerate all wrappers with new web3j cli version. (#8) - Update the readme file with the generation instructions. (#8) @@ -72,19 +112,20 @@ All notable changes to this project will be documented in this file. - Add `com.iexec.commmons.poco.order` package. (#10) - Add `com.iexec.commons.poco.eip712` package. (#11) - Add `MatchOrdersTests` on nethermind `poco-chain`. (#12) + ### Bug Fixes + - Set `protected` visibility on abstract classes constructors. (#13) ## [[1.0.2]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v1.0.2) 2023-04-11 ### Bug Fixes + - Remove unused `guava` dependency. (#5) ## [[1.0.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v1.0.0) 2023-04-06 ### New Features + - Init Gradle project. (#1 #2) -- Migrate from `iexec-common` library to this `iexec-commons-poco` library packages related to blockchain and iExec PoCo protocol. (#3) -### Bug Fixes -### Quality -### Dependency Upgrades +- Migrate from `iexec-common` library to this `iexec-commons-poco` library packages related to blockchain and iExec PoCo protocol. (#3) diff --git a/Jenkinsfile b/Jenkinsfile index 12c705a..f92538c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,5 @@ -@Library('global-jenkins-library@2.7.3') _ +@Library('global-jenkins-library@2.7.4') _ buildJavaProject( - buildInfo: getBuildInfo(), - integrationTestsEnvVars: [], shouldPublishJars: true, shouldPublishDockerImages: false ) diff --git a/build.gradle b/build.gradle index 8f69a30..54573c6 100644 --- a/build.gradle +++ b/build.gradle @@ -9,14 +9,14 @@ plugins { group = 'com.iexec.commons' ext { - testContainersVersion = '1.19.0' + testContainersVersion = '1.19.3' } if (!project.hasProperty('gitBranch')) { ext.gitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim() } -if (gitBranch != 'main' && gitBranch != 'master' && ! (gitBranch ==~ '(release|hotfix|support)/.*')) { +if (gitBranch != 'main' && gitBranch != 'master' && !(gitBranch ==~ '(release|hotfix|support)/.*')) { version += '-NEXT-SNAPSHOT' } @@ -34,7 +34,7 @@ repositories { } dependencies { - implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.14') + implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.17') // web3j api 'org.web3j:core:4.9.7' @@ -44,15 +44,15 @@ dependencies { // multiaddresses (IPFS) implementation 'com.github.multiformats:java-multiaddr:v1.4.6' - + // jaxb required with Java 11 DataTypeConverter in BytesUtils implementation 'javax.xml.bind:jaxb-api' - + // failsafe implementation 'net.jodah:failsafe:2.4.4' //TODO Migrate from Awaitility to Failsafe everywhere implementation 'org.awaitility:awaitility' - + // javax annotations like PostConstruct implementation 'javax.annotation:javax.annotation-api' @@ -72,8 +72,10 @@ dependencies { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) + languageVersion.set(JavaLanguageVersion.of(17)) } + sourceCompatibility = "11" + targetCompatibility = "11" withJavadocJar() withSourcesJar() } @@ -84,11 +86,6 @@ tasks.withType(Test).configureEach { } test { - doFirst { - exec { - commandLine 'docker', 'compose', 'pull', '-q' - } - } reports { junitXml.required = true html.required = true diff --git a/gradle.properties b/gradle.properties index 3893de5..95d24a1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,3 @@ -version=3.1.0 - +version=3.2.0 nexusUser nexusPassword diff --git a/src/main/java/com/iexec/commons/poco/chain/DealParams.java b/src/main/java/com/iexec/commons/poco/chain/DealParams.java index ad079dc..94ab425 100644 --- a/src/main/java/com/iexec/commons/poco/chain/DealParams.java +++ b/src/main/java/com/iexec/commons/poco/chain/DealParams.java @@ -100,6 +100,10 @@ public class DealParams { @JsonProperty("iexec_input_files") List iexecInputFiles = Collections.emptyList(); + /** + * @deprecated will be removed in next major version + */ + @Deprecated(forRemoval = true) @JsonProperty("iexec_developer_logger") boolean iexecDeveloperLoggerEnabled; @@ -117,19 +121,27 @@ public class DealParams { @JsonProperty("iexec_secrets") Map iexecSecrets = Collections.emptyMap(); - //Should be set by SDK + /** + * @deprecated will be removed in next major version + */ + @Deprecated(forRemoval = true) @JsonProperty("iexec_tee_post_compute_image") String iexecTeePostComputeImage; - //Should be set by SDK + /** + * @deprecated will be removed in next major version + */ + @Deprecated(forRemoval = true) @JsonProperty("iexec_tee_post_compute_fingerprint") String iexecTeePostComputeFingerprint; @JsonPOJOBuilder(withPrefix = "") - public static class DealParamsBuilder{} + public static class DealParamsBuilder { + } /** * Creates an instance from a JSON string representation. + * * @param paramString data to create a DealParams instance. * The value will be parsed if it is a valid JSON string, * it will be used as iexecArgs value otherwise. @@ -151,6 +163,7 @@ public static DealParams createFromString(String paramString) { /** * Represents the instance as a JSON string that will be written on chain. + * * @return the JSON string representing the instance */ public String toJsonString() { 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 e7350eb..5e29dd5 100644 --- a/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java @@ -47,8 +47,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; -import static com.iexec.commons.poco.chain.ChainContributionStatus.CONTRIBUTED; -import static com.iexec.commons.poco.chain.ChainContributionStatus.REVEALED; import static com.iexec.commons.poco.tee.TeeEnclaveConfiguration.buildEnclaveConfigurationFromJsonString; import static com.iexec.commons.poco.utils.BytesUtils.isNonZeroedBytes32; import static org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH; @@ -71,7 +69,6 @@ public abstract class IexecHubAbstractService { protected IexecHubContract iexecHubContract; private final Web3jAbstractService web3jAbstractService; private long maxNbOfPeriodsForConsensus = -1; - private final int nbBlocksToWaitPerRetry; private final long retryDelay;// ms private final int maxRetries; private final Map taskDescriptions = new HashMap<>(); @@ -85,11 +82,12 @@ protected IexecHubAbstractService( /** * Base constructor for the IexecHubAbstractService - * @param credentials credentials for sending transaction - * @param web3jAbstractService custom web3j service - * @param iexecHubAddress address of the iExec Hub contract + * + * @param credentials credentials for sending transaction + * @param web3jAbstractService custom web3j service + * @param iexecHubAddress address of the iExec Hub contract * @param nbBlocksToWaitPerRetry nb block to wait per retry - * @param maxRetries maximum reties + * @param maxRetries maximum reties */ protected IexecHubAbstractService( Credentials credentials, @@ -100,7 +98,6 @@ protected IexecHubAbstractService( this.credentials = credentials; this.web3jAbstractService = web3jAbstractService; this.iexecHubAddress = iexecHubAddress; - this.nbBlocksToWaitPerRetry = nbBlocksToWaitPerRetry; this.retryDelay = nbBlocksToWaitPerRetry * this.web3jAbstractService.getBlockTime().toMillis(); this.maxRetries = maxRetries; @@ -165,12 +162,9 @@ public IexecHubContract getHubContract() { return iexecHubContract; } - // TODO move workerpool methods to their own class (e.g.: WorkerpoolManager) - - // ###################### - // # Workerpool # - // ###################### + // region workerpool + // TODO move workerpool methods to their own class (e.g.: WorkerpoolManager) public Workerpool getWorkerpoolContract(String workerpoolAddress) { ExceptionInInitializerError exceptionInInitializerError = new ExceptionInInitializerError("Failed to load Workerpool " + @@ -323,7 +317,7 @@ public String predictWorkerpool(String owner, String name) { return null; } - RemoteFunctionCall call = workerpoolRegistry.predictWorkerpool(owner,name); + RemoteFunctionCall call = workerpoolRegistry.predictWorkerpool(owner, name); String address = ""; try { address = call.send(); @@ -333,12 +327,11 @@ public String predictWorkerpool(String owner, String name) { return address; } - // TODO move app methods to its own class (e.g.: AppManager) + // endregion - // ###################### - // # App # - // ###################### + // region app + // TODO move app methods to its own class (e.g.: AppManager) public App getAppContract(String appAddress) { ExceptionInInitializerError exceptionInInitializerError = new ExceptionInInitializerError("Failed to load App " + @@ -396,7 +389,7 @@ public AppRegistry getAppRegistryContract(ContractGasProvider contractGasProvide * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce) */ public String createApp(String name, String multiAddress, String type, - String checksum, String mrEnclave, int secondsTimeout, int secondsPollingInterval) { + String checksum, String mrEnclave, int secondsTimeout, int secondsPollingInterval) { String owner = credentials.getAddress(); final String paramsPrinter = " [owner:{}, name:{}]"; @@ -406,7 +399,7 @@ public String createApp(String name, String multiAddress, String type, } AppRegistry appRegistry = - getAppRegistryContract(web3jAbstractService.getContractGasProvider()); + getAppRegistryContract(web3jAbstractService.getContractGasProvider()); if (appRegistry == null) { log.error("Failed to get appRegistry" + paramsPrinter, owner, name); return ""; @@ -478,7 +471,7 @@ public String createApp(String name, String multiAddress, String type, * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce) */ public String createApp(String name, String multiAddress, String type, - String checksum, String mrEnclave) { + String checksum, String mrEnclave) { return createApp(name, multiAddress, type, checksum, mrEnclave, 10 * 60, 5); } @@ -492,7 +485,7 @@ public String createApp(String name, String multiAddress, String type, * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce) */ public String predictApp(String owner, String name, String multiAddress, String type, - String checksum, String mrEnclave) { + String checksum, String mrEnclave) { final String paramsPrinter = " [owner:{}, name:{}, multiAddress:{}, checksum:{}]"; if (StringUtils.isEmpty(owner) || StringUtils.isEmpty(name) @@ -524,12 +517,11 @@ public String predictApp(String owner, String name, String multiAddress, String return address; } - // TODO move dataset methods to its own class (e.g.: DatasetManager) + // endregion - // ###################### - // # Dataset # - // ###################### + // region dataset + // TODO move dataset methods to its own class (e.g.: DatasetManager) public Dataset getDatasetContract(String datasetAddress) { ExceptionInInitializerError exceptionInInitializerError = new ExceptionInInitializerError("Failed to load Dataset " + @@ -715,6 +707,8 @@ public String predictDataset(String owner, String name, String multiAddress, return address; } + // endregion + /** * Retrieves on-chain deal with a retryer * @@ -808,7 +802,7 @@ public Optional getChainTask(String chainTaskId) { ChainTask chainTask = ChainTask.tuple2ChainTask(iexecHubContract .viewTaskABILegacy(BytesUtils.stringToBytes(chainTaskId)).send()); String chainDealId = chainTask.getDealid(); - if (isNonZeroedBytes32(chainDealId)){ + if (isNonZeroedBytes32(chainDealId)) { return Optional.of(chainTask); } else { log.debug("Failed to get consistent ChainTask [chainTaskId:{}]", @@ -927,9 +921,8 @@ public Optional getChainApp(App app) { chainAppBuilder.enclaveConfiguration( buildEnclaveConfigurationFromJsonString(mrEnclave)); } catch (Exception e) { - log.error("Failed to get tee chain app enclave configuration " + - "[chainAppId:{}, mrEnclave:{}]", app.getContractAddress(), - mrEnclave, e); + log.error("Failed to get tee chain app enclave configuration [chainAppId:{}, mrEnclave:{}]", + app.getContractAddress(), mrEnclave, e); return Optional.empty(); } return Optional.of(chainAppBuilder.build()); @@ -1040,7 +1033,7 @@ public boolean hasEnoughGas(String address) { * */ public TaskDescription getTaskDescription(String chainTaskId) { - if(!taskDescriptions.containsKey(chainTaskId)) { + if (!taskDescriptions.containsKey(chainTaskId)) { repeatGetTaskDescriptionFromChain(chainTaskId, retryDelay, maxRetries) .ifPresent(taskDescription -> taskDescriptions.putIfAbsent(chainTaskId, taskDescription)); @@ -1055,7 +1048,7 @@ public Optional getTaskDescriptionFromChain(String chainTaskId) public Optional repeatGetTaskDescriptionFromChain(String chainTaskId, long retryDelay, int maxRetry) { - if (retryDelay == 0){ + if (retryDelay == 0) { return Optional.empty(); } Optional optionalChainTask = @@ -1077,9 +1070,7 @@ public Optional repeatGetTaskDescriptionFromChain(String chainT ChainDeal chainDeal = optionalChainDeal.get(); TaskDescription taskDescription = - TaskDescription.toTaskDescription(chainTaskId, - chainTask.getIdx(), - chainDeal); + TaskDescription.toTaskDescription(chainDeal, chainTask); return taskDescription != null ? Optional.of(taskDescription) : Optional.empty(); } @@ -1096,47 +1087,8 @@ public boolean isTeeTask(String chainTaskId) { return oTaskDescription.get().isTeeTask(); } - public boolean repeatIsContributedTrue(String chainTaskId, String walletAddress) { - return web3jAbstractService.repeatCheck(nbBlocksToWaitPerRetry, maxRetries, - "isContributedTrue", this::isContributedTrue, chainTaskId, walletAddress); - } - - public boolean repeatIsRevealedTrue(String chainTaskId, String walletAddress) { - return web3jAbstractService.repeatCheck(nbBlocksToWaitPerRetry, maxRetries, - "isRevealedTrue", this::isRevealedTrue, chainTaskId, walletAddress); - } - - private boolean isContributedTrue(String... args) { - return this.isStatusTrueOnChain(args[0], args[1], CONTRIBUTED); - } - - private boolean isRevealedTrue(String... args) { - return this.isStatusTrueOnChain(args[0], args[1], REVEALED); - } - - public boolean isStatusTrueOnChain(String chainTaskId, String walletAddress, - ChainContributionStatus wishedStatus) { - Optional optional = - getChainContribution(chainTaskId, walletAddress); - if (optional.isEmpty()) { - return false; - } - - ChainContribution chainContribution = optional.get(); - ChainContributionStatus chainStatus = chainContribution.getStatus(); - switch (wishedStatus) { - case CONTRIBUTED: - // has at least contributed - return chainStatus.equals(CONTRIBUTED) || chainStatus.equals(REVEALED); - case REVEALED: - // has at least revealed - return chainStatus.equals(REVEALED); - default: - return false; - } - } - // region Purge + /** * Purge description of given task. * @@ -1160,5 +1112,6 @@ protected boolean purgeTask(String chainTaskId) { protected void purgeAllTasksData() { taskDescriptions.clear(); } + // 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 0d66853..afa7939 100644 --- a/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java @@ -73,12 +73,12 @@ public abstract class Web3jAbstractService { * OkHttpClient which ensures a proper connection pool management * guaranteeing sockets are properly reused. * - * @param chainId ID of the blockchain network - * @param chainNodeAddress address of the blockchain node - * @param blockTime block time as a duration + * @param chainId ID of the blockchain network + * @param chainNodeAddress address of the blockchain node + * @param blockTime block time as a duration * @param gasPriceMultiplier gas price multiplier - * @param gasPriceCap gas price cap - * @param isSidechain true if iExec native chain, false if iExec token chain + * @param gasPriceCap gas price cap + * @param isSidechain true if iExec native chain, false if iExec token chain */ protected Web3jAbstractService( int chainId, @@ -105,7 +105,7 @@ protected Web3jAbstractService( @PostConstruct public void checkConnection() { final int fewSeconds = 5; - for (int attempt = 1; attempt <= maxAttempts; attempt++ ) { + for (int attempt = 1; attempt <= maxAttempts; attempt++) { log.debug("Connection attempt {}", attempt); if (isConnected()) { return; @@ -137,13 +137,20 @@ public EthBlock.Block getLatestBlock() throws IOException { return web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock(); } + /** + * Gets the latest block number from the blockchain network. + *

+ * All exceptions are caught in order to always provide a numerical result. + * + * @return the block number, {@literal 0L} otherwise. + */ public long getLatestBlockNumber() { try { return web3j.ethBlockNumber().send().getBlockNumber().longValue(); - } catch (IOException e) { + } catch (Exception e) { log.error("ethBlockNumber call failed", e); } - return 0; + return 0L; } public EthBlock.Block getBlock(long blockNumber) throws IOException { @@ -155,7 +162,7 @@ public EthBlock.Block getBlock(long blockNumber) throws IOException { // blockNumber is different than 0 only for status the require a check on the blockchain, so the scheduler should // already have this block, otherwise it should wait for a maximum of 10 blocks. public boolean isBlockAvailable(long blockNumber) { - // if the blocknumer is already available then simply returns true + // if the block number is already available then simply returns true if (blockNumber <= getLatestBlockNumber()) { return true; } @@ -250,7 +257,7 @@ public Optional getBalance(String address) { public Optional getNetworkGasPrice() { try { BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice(); - if (gasPrice != null && gasPrice.signum() > 0){ + if (gasPrice != null && gasPrice.signum() > 0) { return Optional.of(gasPrice); } } catch (IOException e) { diff --git a/src/main/java/com/iexec/commons/poco/order/AppOrder.java b/src/main/java/com/iexec/commons/poco/order/AppOrder.java index d86e10b..debd90f 100644 --- a/src/main/java/com/iexec/commons/poco/order/AppOrder.java +++ b/src/main/java/com/iexec/commons/poco/order/AppOrder.java @@ -21,7 +21,6 @@ import com.iexec.commons.poco.contract.generated.IexecHubContract; import lombok.Builder; import lombok.EqualsAndHashCode; -import lombok.ToString; import lombok.Value; import org.web3j.utils.Numeric; @@ -29,7 +28,6 @@ @Value @EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) @JsonDeserialize(builder = AppOrder.AppOrderBuilder.class) public class AppOrder extends Order { @@ -59,7 +57,8 @@ public class AppOrder extends Order { } @JsonPOJOBuilder(withPrefix = "") - public static class AppOrderBuilder{} + public static class AppOrderBuilder { + } @Override public AppOrder withSignature(String signature) { @@ -84,4 +83,13 @@ public IexecHubContract.AppOrder toHubContract() { Numeric.hexStringToByteArray(this.sign) ); } + + public String toString() { + return "AppOrder{app=" + app + ", appprice=" + appprice + + ", volume=" + volume + ", tag=" + tag + + ", datasetrestrict=" + datasetrestrict + + ", workerpoolrestrict=" + workerpoolrestrict + + ", requesterrestrict=" + requesterrestrict + + ", salt=" + salt + ", sign=" + sign + "}"; + } } diff --git a/src/main/java/com/iexec/commons/poco/order/DatasetOrder.java b/src/main/java/com/iexec/commons/poco/order/DatasetOrder.java index f301f7d..75765d2 100644 --- a/src/main/java/com/iexec/commons/poco/order/DatasetOrder.java +++ b/src/main/java/com/iexec/commons/poco/order/DatasetOrder.java @@ -21,7 +21,6 @@ import com.iexec.commons.poco.contract.generated.IexecHubContract; import lombok.Builder; import lombok.EqualsAndHashCode; -import lombok.ToString; import lombok.Value; import org.web3j.utils.Numeric; @@ -29,7 +28,6 @@ @Value @EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) @JsonDeserialize(builder = DatasetOrder.DatasetOrderBuilder.class) public class DatasetOrder extends Order { @@ -59,7 +57,8 @@ public class DatasetOrder extends Order { } @JsonPOJOBuilder(withPrefix = "") - public static class DatasetOrderBuilder{} + public static class DatasetOrderBuilder { + } public DatasetOrder withSignature(String signature) { return new DatasetOrder( @@ -83,4 +82,13 @@ public IexecHubContract.DatasetOrder toHubContract() { Numeric.hexStringToByteArray(this.sign) ); } + + public String toString() { + return "DatasetOrder{dataset=" + dataset + ", datasetprice=" + datasetprice + + ", volume=" + volume + ", tag=" + tag + + ", apprestrict=" + apprestrict + + ", workerpoolrestrict=" + workerpoolrestrict + + ", requesterrestrict=" + requesterrestrict + + ", salt=" + salt + ", sign=" + sign + "}"; + } } diff --git a/src/main/java/com/iexec/commons/poco/order/Order.java b/src/main/java/com/iexec/commons/poco/order/Order.java index 8d4e6d0..b7580fa 100644 --- a/src/main/java/com/iexec/commons/poco/order/Order.java +++ b/src/main/java/com/iexec/commons/poco/order/Order.java @@ -39,6 +39,7 @@ public boolean isSigned() { /** * Converts all characters to Lowercase or returns empty + * * @param s String to convert * @return the String, converted to lowercase or an empty string */ diff --git a/src/main/java/com/iexec/commons/poco/order/RequestOrder.java b/src/main/java/com/iexec/commons/poco/order/RequestOrder.java index d9fd86a..0172083 100644 --- a/src/main/java/com/iexec/commons/poco/order/RequestOrder.java +++ b/src/main/java/com/iexec/commons/poco/order/RequestOrder.java @@ -21,7 +21,6 @@ import com.iexec.commons.poco.contract.generated.IexecHubContract; import lombok.Builder; import lombok.EqualsAndHashCode; -import lombok.ToString; import lombok.Value; import org.web3j.utils.Numeric; @@ -29,7 +28,6 @@ @Value @EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) @JsonDeserialize(builder = RequestOrder.RequestOrderBuilder.class) public class RequestOrder extends Order { @@ -80,7 +78,8 @@ public class RequestOrder extends Order { } @JsonPOJOBuilder(withPrefix = "") - public static class RequestOrderBuilder{} + public static class RequestOrderBuilder { + } @Override public RequestOrder withSignature(String signature) { @@ -113,4 +112,15 @@ public IexecHubContract.RequestOrder toHubContract() { Numeric.hexStringToByteArray(this.sign) ); } + + public String toString() { + return "RequestOrder{" + + "app=" + app + ", appmaxprice=" + appmaxprice + + ", dataset=" + dataset + ", datasetmaxprice=" + datasetmaxprice + + ", workerpool=" + workerpool + ", workerpoolmaxprice=" + workerpoolmaxprice + + ", requester=" + requester + ", volume=" + volume + ", tag=" + tag + + ", category=" + category + ", trust=" + trust + + ", beneficiary=" + beneficiary + ", callback=" + callback + ", params=" + params + + ", salt=" + salt + ", sign=" + sign + "}"; + } } diff --git a/src/main/java/com/iexec/commons/poco/order/WorkerpoolOrder.java b/src/main/java/com/iexec/commons/poco/order/WorkerpoolOrder.java index 5504632..30cfbc7 100644 --- a/src/main/java/com/iexec/commons/poco/order/WorkerpoolOrder.java +++ b/src/main/java/com/iexec/commons/poco/order/WorkerpoolOrder.java @@ -65,7 +65,8 @@ public class WorkerpoolOrder extends Order { } @JsonPOJOBuilder(withPrefix = "") - public static class WorkerpoolOrderBuilder{} + public static class WorkerpoolOrderBuilder { + } @Override public WorkerpoolOrder withSignature(String signature) { @@ -92,4 +93,14 @@ public IexecHubContract.WorkerpoolOrder toHubContract() { Numeric.hexStringToByteArray(this.sign) ); } + + public String toString() { + return "WorkerpoolOrder{workerpool=" + workerpool + ", workerpoolprice=" + workerpoolprice + + ", volume=" + volume + ", tag=" + tag + + ", category=" + category + ", trust=" + trust + + ", apprestrict=" + apprestrict + + ", datasetrestrict=" + datasetrestrict + + ", requesterrestrict=" + requesterrestrict + + ", salt=" + salt + ", sign=" + sign + "}"; + } } diff --git a/src/main/java/com/iexec/commons/poco/task/TaskDescription.java b/src/main/java/com/iexec/commons/poco/task/TaskDescription.java index aae0a35..5c1b296 100644 --- a/src/main/java/com/iexec/commons/poco/task/TaskDescription.java +++ b/src/main/java/com/iexec/commons/poco/task/TaskDescription.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.iexec.commons.poco.chain.ChainDeal; +import com.iexec.commons.poco.chain.ChainTask; import com.iexec.commons.poco.dapp.DappType; import com.iexec.commons.poco.tee.TeeEnclaveConfiguration; import com.iexec.commons.poco.tee.TeeFramework; @@ -46,10 +47,8 @@ public class TaskDescription { String appAddress; TeeEnclaveConfiguration appEnclaveConfiguration; String cmd; - long maxExecutionTime; boolean isTeeTask; TeeFramework teeFramework; - int botIndex; int botSize; int botFirstIndex; String datasetAddress; @@ -62,9 +61,12 @@ public class TaskDescription { String resultStorageProxy; String smsUrl; Map secrets; - String teePostComputeImage; - String teePostComputeFingerprint; BigInteger trust; + // from task + int botIndex; + long maxExecutionTime; // timeref ? + long contributionDeadline; + long finalDeadline; /** * Check if this task includes a dataset or not. The task is considered @@ -73,7 +75,7 @@ public class TaskDescription { * information since they, inevitably, break the workflow. In the case * where those datasets are ignored, the worker will contribute an * application error caused by the missing dataset file. - * + * * @return true if all dataset fields are all non-null, * non-empty values, false otherwise. */ @@ -81,13 +83,12 @@ public boolean containsDataset() { return !StringUtils.isEmpty(datasetAddress) && !datasetAddress.equals(BytesUtils.EMPTY_ADDRESS) && !StringUtils.isEmpty(datasetUri) && - !StringUtils.isEmpty(datasetChecksum) && - !StringUtils.isEmpty(datasetName); + !StringUtils.isEmpty(datasetChecksum); } /** - * Check if a callback is requested for this task. - * + * Check if a callback is requested for this task. + * * @return true if a callback address is found in the deal, false otherwise. */ public boolean containsCallback() { @@ -96,24 +97,13 @@ public boolean containsCallback() { /** * Check if this task includes some input files. - * + * * @return true if at least one input file is present, false otherwise */ public boolean containsInputFiles() { return inputFiles != null && !inputFiles.isEmpty(); } - /** - * Check if this task contains a post-compute image uri and its fingerprint. - * - * @return true if and only if both image uri and fingerprint are present, - * false otherwise - */ - public boolean containsPostCompute() { - return !StringUtils.isEmpty(teePostComputeImage) && - !StringUtils.isEmpty(teePostComputeFingerprint); - } - public String getAppCommand() { String appArgs = appEnclaveConfiguration.getEntrypoint(); //TODO: Add unit test @@ -143,16 +133,13 @@ public boolean isEligibleToContributeAndFinalize() { /** * Create a {@link TaskDescription} from the provided chain deal. This method * if preferred to constructors or the builder method. - * - * @param chainTaskId - * @param taskIdx - * @param chainDeal + * + * @param chainDeal On-chain deal from PoCo smart contracts + * @param chainTask On-chain task from PoCo smart contracts * @return the created taskDescription */ - public static TaskDescription toTaskDescription(String chainTaskId, - int taskIdx, - ChainDeal chainDeal) { - if (chainDeal == null) { + public static TaskDescription toTaskDescription(ChainDeal chainDeal, ChainTask chainTask) { + if (chainDeal == null || chainTask == null) { return null; } String datasetAddress = ""; @@ -161,14 +148,13 @@ public static TaskDescription toTaskDescription(String chainTaskId, String datasetChecksum = ""; if (chainDeal.containsDataset()) { datasetAddress = chainDeal.getChainDataset().getChainDatasetId(); - datasetUri = MultiAddressHelper.convertToURI( - chainDeal.getChainDataset().getUri()); + datasetUri = MultiAddressHelper.convertToURI(chainDeal.getChainDataset().getUri()); datasetName = chainDeal.getChainDataset().getName(); datasetChecksum = chainDeal.getChainDataset().getChecksum(); } final String tag = chainDeal.getTag(); return TaskDescription.builder() - .chainTaskId(chainTaskId) + .chainTaskId(chainTask.getChainTaskId()) .requester(chainDeal .getRequester()) .beneficiary(chainDeal @@ -185,8 +171,6 @@ public static TaskDescription toTaskDescription(String chainTaskId, .getIexecArgs()) .inputFiles(chainDeal.getParams() .getIexecInputFiles()) - .maxExecutionTime(chainDeal.getChainCategory() - .getMaxExecutionTime()) .isTeeTask(TeeUtils .isTeeTag(tag)) .teeFramework(TeeUtils @@ -199,20 +183,18 @@ public static TaskDescription toTaskDescription(String chainTaskId, .getIexecResultStorageProxy()) .secrets(chainDeal.getParams() .getIexecSecrets()) - .teePostComputeImage(chainDeal.getParams() - .getIexecTeePostComputeImage()) - .teePostComputeFingerprint(chainDeal.getParams() - .getIexecTeePostComputeFingerprint()) .datasetAddress(datasetAddress) .datasetUri(datasetUri) .datasetName(datasetName) .datasetChecksum(datasetChecksum) - .botSize(chainDeal - .getBotSize().intValue()) - .botFirstIndex(chainDeal - .getBotFirst().intValue()) - .botIndex(taskIdx) + .botSize(chainDeal.getBotSize().intValue()) + .botFirstIndex(chainDeal.getBotFirst().intValue()) .trust(chainDeal.getTrust()) + // from task + .botIndex(chainTask.getIdx()) + .maxExecutionTime(chainDeal.getChainCategory().getMaxExecutionTime()) // https://github.com/iExecBlockchainComputing/PoCo/blob/v5/contracts/modules/delegates/IexecPoco2Delegate.sol#L111 + .contributionDeadline(chainTask.getContributionDeadline()) + .finalDeadline(chainTask.getFinalDeadline()) .build(); } } diff --git a/src/test/java/com/iexec/commons/poco/itest/ChainTests.java b/src/test/java/com/iexec/commons/poco/itest/ChainTests.java index c83986f..425c8fb 100644 --- a/src/test/java/com/iexec/commons/poco/itest/ChainTests.java +++ b/src/test/java/com/iexec/commons/poco/itest/ChainTests.java @@ -24,7 +24,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.web3j.crypto.CipherException; @@ -44,19 +44,24 @@ @Testcontainers class ChainTests { + static final String SERVICE_NAME = "poco-chain"; + static final int SERVICE_PORT = 8545; + private Credentials credentials; private IexecHubTestService iexecHubService; private Web3jTestService web3jService; @Container - static DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) + static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml")) .withExposedService("poco-chain", 8545); @BeforeEach void init() throws CipherException, IOException { credentials = WalletUtils.loadCredentials("whatever", "src/test/resources/wallet.json"); - web3jService = new Web3jTestService(environment.getServicePort("poco-chain", 8545)); + String chainNodeAddress = "http://" + environment.getServiceHost(SERVICE_NAME, SERVICE_PORT) + ":" + + environment.getServicePort(SERVICE_NAME, SERVICE_PORT); + web3jService = new Web3jTestService(chainNodeAddress); iexecHubService = new IexecHubTestService(credentials, web3jService); } @@ -78,7 +83,7 @@ void shouldGetBalance() { @Test void shouldNotGetBalance() { - Web3jTestService web3jService = new Web3jTestService(8545); + Web3jTestService web3jService = new Web3jTestService("http://localhost:8545"); assertThat(web3jService.getBalance(credentials.getAddress())).isEmpty(); } @@ -93,7 +98,7 @@ void shouldGetBlockNumber() throws IOException { @Test void shouldNotGetBlockNumber() { - Web3jTestService web3jService = new Web3jTestService(8545); + Web3jTestService web3jService = new Web3jTestService("http://localhost:8545"); assertThat(web3jService.getLatestBlockNumber()).isZero(); } 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 d949d92..a10cbd5 100644 --- a/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java +++ b/src/test/java/com/iexec/commons/poco/itest/MatchOrdersTests.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.web3j.crypto.CipherException; @@ -42,6 +42,8 @@ import java.util.Optional; import java.util.TreeMap; +import static com.iexec.commons.poco.itest.ChainTests.SERVICE_NAME; +import static com.iexec.commons.poco.itest.ChainTests.SERVICE_PORT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -58,13 +60,15 @@ class MatchOrdersTests { private OrderSigner signer; @Container - static DockerComposeContainer environment = new DockerComposeContainer<>(new File("docker-compose.yml")) + static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml")) .withExposedService("poco-chain", 8545); @BeforeEach void init() throws CipherException, IOException { credentials = WalletUtils.loadCredentials("whatever", "src/test/resources/wallet.json"); - web3jService = new Web3jTestService(environment.getServicePort("poco-chain", 8545)); + String chainNodeAddress = "http://" + environment.getServiceHost(SERVICE_NAME, SERVICE_PORT) + ":" + + environment.getServicePort(SERVICE_NAME, SERVICE_PORT); + web3jService = new Web3jTestService(chainNodeAddress); iexecHubService = new IexecHubTestService(credentials, web3jService); signer = new OrderSigner(65535, IEXEC_HUB_ADDRESS, credentials.getEcKeyPair()); } diff --git a/src/test/java/com/iexec/commons/poco/itest/Web3jTestService.java b/src/test/java/com/iexec/commons/poco/itest/Web3jTestService.java index efce4f8..2efeb7d 100644 --- a/src/test/java/com/iexec/commons/poco/itest/Web3jTestService.java +++ b/src/test/java/com/iexec/commons/poco/itest/Web3jTestService.java @@ -21,8 +21,7 @@ import java.time.Duration; public class Web3jTestService extends Web3jAbstractService { - public Web3jTestService(int chainServicePort) { - super(65535, "http://localhost:" + chainServicePort, - Duration.ofSeconds(5), 1.0f, 22_000_000_000L, true); + public Web3jTestService(String chainNodeAddress) { + super(65535, chainNodeAddress, Duration.ofSeconds(5), 1.0f, 22_000_000_000L, true); } } diff --git a/src/test/java/com/iexec/commons/poco/order/AppOrderTests.java b/src/test/java/com/iexec/commons/poco/order/AppOrderTests.java index 92da4ed..3678bc7 100644 --- a/src/test/java/com/iexec/commons/poco/order/AppOrderTests.java +++ b/src/test/java/com/iexec/commons/poco/order/AppOrderTests.java @@ -43,6 +43,10 @@ void shouldSerializeAndDeserialize() throws JsonProcessingException { "\"app\":null,\"appprice\":null,\"datasetrestrict\":\"\",\"workerpoolrestrict\":\"\",\"requesterrestrict\":\"\"}"); AppOrder parsedAppOrder = mapper.readValue(jsonString, AppOrder.class); assertThat(parsedAppOrder).usingRecursiveComparison().isEqualTo(appOrder); + assertThat(appOrder).hasToString( + "AppOrder{app=null, appprice=null, volume=null, tag=null" + + ", datasetrestrict=, workerpoolrestrict=, requesterrestrict=, salt=null, sign=null}" + ); } @Test @@ -67,6 +71,14 @@ void shouldCastToHubContract() { assertThat(web3jAppOrder.workerpoolrestrict).isEqualTo(appOrder.getWorkerpoolrestrict()); assertThat(web3jAppOrder.requesterrestrict).isEqualTo(appOrder.getRequesterrestrict()); assertThat(web3jAppOrder.salt).isEqualTo(Numeric.hexStringToByteArray(appOrder.getSalt())); + assertThat(appOrder).hasToString( + "AppOrder{app=0x1, appprice=0" + + ", volume=1, tag=0x0000000000000000000000000000000000000000000000000000000000000000" + + ", datasetrestrict=0x0000000000000000000000000000000000000000" + + ", workerpoolrestrict=0x0000000000000000000000000000000000000000" + + ", requesterrestrict=0x0000000000000000000000000000000000000000" + + ", salt=" + appOrder.getSalt() + ", sign=0x0}" + ); } } diff --git a/src/test/java/com/iexec/commons/poco/order/DatasetOrderTests.java b/src/test/java/com/iexec/commons/poco/order/DatasetOrderTests.java index 15209dd..a103eb8 100644 --- a/src/test/java/com/iexec/commons/poco/order/DatasetOrderTests.java +++ b/src/test/java/com/iexec/commons/poco/order/DatasetOrderTests.java @@ -21,6 +21,7 @@ import com.iexec.commons.poco.contract.generated.IexecHubContract; import com.iexec.commons.poco.utils.BytesUtils; import org.apache.commons.lang3.RandomStringUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.web3j.crypto.Hash; import org.web3j.utils.Numeric; @@ -41,6 +42,10 @@ void shouldSerializeAndDeserialize() throws JsonProcessingException { "\"dataset\":null,\"datasetprice\":null,\"apprestrict\":\"\",\"workerpoolrestrict\":\"\",\"requesterrestrict\":\"\"}"); DatasetOrder parsedDatasetOrder = mapper.readValue(jsonString, DatasetOrder.class); assertThat(parsedDatasetOrder).usingRecursiveComparison().isEqualTo(datasetOrder); + Assertions.assertThat(datasetOrder).hasToString( + "DatasetOrder{dataset=null, datasetprice=null, volume=null, tag=null" + + ", apprestrict=, workerpoolrestrict=, requesterrestrict=, salt=null, sign=null}" + ); } @Test @@ -65,6 +70,14 @@ void shouldCastToHubContract() { assertThat(web3jDatasetOrder.workerpoolrestrict).isEqualTo(datasetOrder.getWorkerpoolrestrict()); assertThat(web3jDatasetOrder.requesterrestrict).isEqualTo(datasetOrder.getRequesterrestrict()); assertThat(web3jDatasetOrder.salt).isEqualTo(Numeric.hexStringToByteArray(datasetOrder.getSalt())); + Assertions.assertThat(datasetOrder).hasToString( + "DatasetOrder{dataset=0x1, datasetprice=0" + + ", volume=1, tag=0x0000000000000000000000000000000000000000000000000000000000000000" + + ", apprestrict=0x0000000000000000000000000000000000000000" + + ", workerpoolrestrict=0x0000000000000000000000000000000000000000" + + ", requesterrestrict=0x0000000000000000000000000000000000000000" + + ", salt=" + datasetOrder.getSalt() + ", sign=0x0}" + ); } } diff --git a/src/test/java/com/iexec/commons/poco/order/RequestOrderTests.java b/src/test/java/com/iexec/commons/poco/order/RequestOrderTests.java index ecbba5f..2b828e6 100644 --- a/src/test/java/com/iexec/commons/poco/order/RequestOrderTests.java +++ b/src/test/java/com/iexec/commons/poco/order/RequestOrderTests.java @@ -42,6 +42,14 @@ void shouldSerializeAndDeserialize() throws JsonProcessingException { "\"requester\":\"\",\"category\":null,\"trust\":null,\"beneficiary\":\"\",\"callback\":\"\",\"params\":null}"); RequestOrder parsedRequestOrder = mapper.readValue(jsonString, RequestOrder.class); assertThat(parsedRequestOrder).usingRecursiveComparison().isEqualTo(requestOrder); + assertThat(requestOrder).hasToString( + "RequestOrder{app=, appmaxprice=null" + + ", dataset=, datasetmaxprice=null" + + ", workerpool=, workerpoolmaxprice=null" + + ", requester=, volume=null, tag=null, category=null, trust=null" + + ", beneficiary=, callback=, params=null" + + ", salt=null, sign=null}" + ); } @Test @@ -79,6 +87,15 @@ void shouldCastToHubContract() { assertThat(web3jRequestOrder.callback).isEqualTo(requestOrder.getCallback()); assertThat(web3jRequestOrder.params).isEqualTo(requestOrder.getParams()); assertThat(web3jRequestOrder.salt).isEqualTo(Numeric.hexStringToByteArray(requestOrder.getSalt())); + assertThat(requestOrder).hasToString( + "RequestOrder{app=0x1, appmaxprice=10" + + ", dataset=0x2, datasetmaxprice=10" + + ", workerpool=0x3, workerpoolmaxprice=10" + + ", requester=0x4, volume=1, tag=0x0000000000000000000000000000000000000000000000000000000000000000" + + ", category=0, trust=1, beneficiary=0x5" + + ", callback=0x0000000000000000000000000000000000000000, params=null" + + ", salt=" + requestOrder.getSalt() + ", sign=0x0}" + ); } } diff --git a/src/test/java/com/iexec/commons/poco/order/WorkerpoolOrderTests.java b/src/test/java/com/iexec/commons/poco/order/WorkerpoolOrderTests.java index c3297a9..f3534fa 100644 --- a/src/test/java/com/iexec/commons/poco/order/WorkerpoolOrderTests.java +++ b/src/test/java/com/iexec/commons/poco/order/WorkerpoolOrderTests.java @@ -41,6 +41,11 @@ void shouldSerializeAndDeserialize() throws JsonProcessingException { "\"workerpool\":null,\"workerpoolprice\":null,\"trust\":null,\"category\":null,\"apprestrict\":\"\",\"datasetrestrict\":\"\",\"requesterrestrict\":\"\"}"); WorkerpoolOrder parsedWorkerpoolOrder = mapper.readValue(jsonString, WorkerpoolOrder.class); assertThat(parsedWorkerpoolOrder).usingRecursiveComparison().isEqualTo(workerpoolOrder); + assertThat(workerpoolOrder).hasToString( + "WorkerpoolOrder{workerpool=null, workerpoolprice=null, volume=null, tag=null" + + ", category=null, trust=null" + + ", apprestrict=, datasetrestrict=, requesterrestrict=, salt=null, sign=null}" + ); } @Test @@ -69,6 +74,15 @@ void shouldCastToHubContract() { assertThat(web3jWorkerpoolOrder.datasetrestrict).isEqualTo(workerpoolOrder.getDatasetrestrict()); assertThat(web3jWorkerpoolOrder.requesterrestrict).isEqualTo(workerpoolOrder.getRequesterrestrict()); assertThat(web3jWorkerpoolOrder.salt).isEqualTo(Numeric.hexStringToByteArray(workerpoolOrder.getSalt())); + assertThat(workerpoolOrder).hasToString( + "WorkerpoolOrder{workerpool=0x1, workerpoolprice=0" + + ", volume=1, tag=0x0000000000000000000000000000000000000000000000000000000000000000" + + ", category=0, trust=1" + + ", apprestrict=0x0000000000000000000000000000000000000000" + + ", datasetrestrict=0x0000000000000000000000000000000000000000" + + ", requesterrestrict=0x0000000000000000000000000000000000000000" + + ", salt=" + workerpoolOrder.getSalt() + ", sign=0x0}" + ); } } diff --git a/src/test/java/com/iexec/commons/poco/task/TaskDescriptionTests.java b/src/test/java/com/iexec/commons/poco/task/TaskDescriptionTests.java index 1f8aa01..9b60845 100644 --- a/src/test/java/com/iexec/commons/poco/task/TaskDescriptionTests.java +++ b/src/test/java/com/iexec/commons/poco/task/TaskDescriptionTests.java @@ -59,8 +59,6 @@ class TaskDescriptionTests { public static final boolean IS_RESULT_ENCRYPTION = true; public static final String RESULT_STORAGE_PROVIDER = "resultStorageProvider"; public static final String RESULT_STORAGE_PROXY = "resultStorageProxy"; - public static final String TEE_POST_COMPUTE_IMAGE = "teePostComputeImage"; - public static final String TEE_POST_COMPUTE_FINGERPRINT = "teePostComputeFingerprint"; public static final BigInteger TRUST = BigInteger.ONE; @Test @@ -89,8 +87,6 @@ void shouldBuildAndGetTaskDescription() { .isResultEncryption(IS_RESULT_ENCRYPTION) .resultStorageProvider(RESULT_STORAGE_PROVIDER) .resultStorageProxy(RESULT_STORAGE_PROXY) - .teePostComputeImage(TEE_POST_COMPUTE_IMAGE) - .teePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) .trust(TRUST) .build(); Assertions.assertEquals(CHAIN_TASK_ID, @@ -139,10 +135,6 @@ void shouldBuildAndGetTaskDescription() { task.getResultStorageProvider()); Assertions.assertEquals(RESULT_STORAGE_PROXY, task.getResultStorageProxy()); - Assertions.assertEquals(TEE_POST_COMPUTE_IMAGE, - task.getTeePostComputeImage()); - Assertions.assertEquals(TEE_POST_COMPUTE_FINGERPRINT, - task.getTeePostComputeFingerprint()); Assertions.assertEquals(TRUST, task.getTrust()); Assertions.assertTrue(task.containsDataset()); @@ -150,7 +142,7 @@ void shouldBuildAndGetTaskDescription() { @Test void toTaskDescriptionWithNullDeal() { - Assertions.assertNull(TaskDescription.toTaskDescription("0x15", 5, null)); + Assertions.assertNull(TaskDescription.toTaskDescription(null, null)); } @Test @@ -170,8 +162,6 @@ void toTaskDescription() { .iexecResultStorageProvider(RESULT_STORAGE_PROVIDER) .iexecResultStorageProxy(RESULT_STORAGE_PROXY) .iexecResultEncryption(IS_RESULT_ENCRYPTION) - .iexecTeePostComputeImage(TEE_POST_COMPUTE_IMAGE) - .iexecTeePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) .build()) .chainDataset(ChainDataset.builder() .chainDatasetId(DATASET_ADDRESS) @@ -187,8 +177,14 @@ void toTaskDescription() { .trust(TRUST) .build(); + ChainTask chainTask = ChainTask.builder() + .dealid(chainDeal.getChainDealId()) + .chainTaskId(CHAIN_TASK_ID) + .idx(TASK_IDX) + .build(); + TaskDescription task = - TaskDescription.toTaskDescription(CHAIN_TASK_ID, TASK_IDX, chainDeal); + TaskDescription.toTaskDescription(chainDeal, chainTask); Assertions.assertEquals(CHAIN_TASK_ID, task.getChainTaskId()); @@ -234,10 +230,6 @@ void toTaskDescription() { task.getResultStorageProvider()); Assertions.assertEquals(RESULT_STORAGE_PROXY, task.getResultStorageProxy()); - Assertions.assertEquals(TEE_POST_COMPUTE_IMAGE, - task.getTeePostComputeImage()); - Assertions.assertEquals(TEE_POST_COMPUTE_FINGERPRINT, - task.getTeePostComputeFingerprint()); Assertions.assertEquals(TRUST, task.getTrust()); } @@ -251,6 +243,14 @@ void shouldContainDataset() { .datasetChecksum(DATASET_CHECKSUM) .build() .containsDataset()); + + Assertions.assertTrue(TaskDescription.builder() + .datasetAddress(DATASET_ADDRESS) + .datasetUri(DATASET_URI) + // .datasetName(DATASET_NAME) + .datasetChecksum(DATASET_CHECKSUM) + .build() + .containsDataset()); } @Test @@ -271,14 +271,6 @@ void shouldNotContainDataset() { .build() .containsDataset()); - Assertions.assertFalse(TaskDescription.builder() - .datasetAddress(DATASET_ADDRESS) - .datasetUri(DATASET_URI) - // .datasetName(DATASET_NAME) - .datasetChecksum(DATASET_CHECKSUM) - .build() - .containsDataset()); - Assertions.assertFalse(TaskDescription.builder() .datasetAddress(DATASET_ADDRESS) .datasetUri(DATASET_URI) @@ -326,46 +318,6 @@ void shouldNotContainInputFiles() { .containsInputFiles()); } - @Test - void shouldContainPostCompute() { - Assertions.assertTrue(TaskDescription.builder() - .chainTaskId(CHAIN_TASK_ID) - .teePostComputeImage(TEE_POST_COMPUTE_IMAGE) - .teePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) - .build() - .containsPostCompute()); - } - - @Test - void shouldNotContainPostComputeIfMissingImage() { - Assertions.assertFalse(TaskDescription.builder() - .chainTaskId(CHAIN_TASK_ID) - // .teePostComputeImage(TEE_POST_COMPUTE_IMAGE) - .teePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) - .build() - .containsPostCompute()); - } - - @Test - void shouldNotContainPostComputeIfMissingFingerprint() { - Assertions.assertFalse(TaskDescription.builder() - .chainTaskId(CHAIN_TASK_ID) - .teePostComputeImage(TEE_POST_COMPUTE_IMAGE) - // .teePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) - .build() - .containsPostCompute()); - } - - @Test - void shouldNotContainPostComputeIfMissingBothImageAndFingerprint() { - Assertions.assertFalse(TaskDescription.builder() - .chainTaskId(CHAIN_TASK_ID) - // .teePostComputeImage(TEE_POST_COMPUTE_IMAGE) - // .teePostComputeFingerprint(TEE_POST_COMPUTE_FINGERPRINT) - .build() - .containsPostCompute()); - } - // region isEligibleToContributeAndFinalize @Test void shouldBeEligibleToContributeAndFinalize() {