Skip to content

Commit

Permalink
Merge pull request #93 from iExecBlockchainComputing/release/8.6.0
Browse files Browse the repository at this point in the history
Release 8.6.0
  • Loading branch information
nabil-Tounarti authored Dec 20, 2024
2 parents 53de8d0 + 2801494 commit 93b01a1
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 76 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes to this project will be documented in this file.

## [[8.6.0]](https://github.com/iExecBlockchainComputing/tee-worker-pre-compute/releases/tag/v8.6.0) 2024-12-20

### New Features

- Use new `FileHashUtils` API. (#90)

### Quality

- Keep `itest` task empty in `build.gradle` to avoid a warning during build. (#91)

### Dependency Upgrades

- Upgrade to `eclipse-temurin:11.0.24_8-jre-focal`. (#88)
- Upgrade to Gradle 8.10.2. (#89)
- Upgrade to `iexec-commons-poco` 4.2.0. (#92)
- Upgrade to `iexec-common` 8.6.0. (#92)

## [[8.5.0]](https://github.com/iExecBlockchainComputing/tee-worker-pre-compute/releases/tag/v8.5.0) 2024-06-18

### Quality
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:11.0.22_7-jre-focal
FROM eclipse-temurin:11.0.24_8-jre-focal

ARG jar

Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'io.freefair.lombok' version '8.6'
id 'io.freefair.lombok' version '8.10.2'
id 'jacoco'
id 'org.sonarqube' version '5.0.0.4638'
id 'org.sonarqube' version '5.1.0.4882'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.gradleup.shadow' version '8.3.3'
}

ext {
Expand Down Expand Up @@ -91,6 +91,11 @@ tasks.withType(Test).configureEach {
finalizedBy jacocoTestReport
}

tasks.register('itest') {
group 'Verification'
description 'Runs the integration tests.'
}

// sonarqube code coverage requires jacoco XML report
jacocoTestReport {
reports {
Expand Down Expand Up @@ -133,8 +138,3 @@ tasks.register('buildSconeImage', Exec) {
environment 'IMG_TO', ociTeeImageName
commandLine 'docker/sconify.sh'
}

tasks.register('itest', Test) {
group 'Verification'
description 'Runs the integration tests.'
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version=8.5.0
iexecCommonVersion=8.5.0
iexecCommonsPocoVersion=4.1.0
version=8.6.0
iexecCommonVersion=8.6.0
iexecCommonsPocoVersion=4.2.0

nexusUser
nexusPassword
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/iexec/worker/compute/pre/PreComputeApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.iexec.common.replicate.ReplicateStatusCause;
import com.iexec.common.security.CipherUtils;
import com.iexec.common.utils.FileHashUtils;
import com.iexec.common.utils.FileHelper;
import com.iexec.commons.poco.utils.HashUtils;
import com.iexec.commons.poco.utils.MultiAddressHelper;
Expand All @@ -39,7 +40,7 @@ public PreComputeApp(String chainTaskId) {
/**
* Download, decrypt, and save the plain dataset file in "/iexec_in".
* If the decrypted file is an archive, it won't be extracted.
*
*
* @throws PreComputeException if dataset or input files could not be made available for the application enclave
*/
void run() throws PreComputeException {
Expand All @@ -55,7 +56,7 @@ void run() throws PreComputeException {

/**
* Check that output folder (/iexec_in) folder exists.
*
*
* @throws PreComputeException if output folder not found
*/
void checkOutputFolder() throws PreComputeException {
Expand All @@ -72,7 +73,7 @@ void checkOutputFolder() throws PreComputeException {

/**
* Download encrypted dataset file and check its checksum.
*
*
* @return downloaded file bytes
* @throws PreComputeException if download fails or bad file checksum
*/
Expand Down Expand Up @@ -110,7 +111,7 @@ byte[] downloadEncryptedDataset() throws PreComputeException {

/**
* Decrypt dataset content.
*
*
* @param encryptedContent bytes
* @return plain dataset content bytes
* @throws PreComputeException if decryption fails
Expand All @@ -132,7 +133,7 @@ byte[] decryptDataset(byte[] encryptedContent) throws PreComputeException {
* Save plain dataset content in output folder (iexec_in).
* The created file will have the name provided in the env
* variable IEXEC_DATASET_FILENAME.
*
*
* @param plainContent bytes
* @throws PreComputeException if saving the file fails
*/
Expand All @@ -152,21 +153,22 @@ void savePlainDatasetFile(byte[] plainContent) throws PreComputeException {
/**
* Download files and save them in the output folder (iexec_in)
* if the list is not empty.
*
* @throws PreComputeException if download of one of the
* files fails
*
* @throws PreComputeException if download of one of the files fails
*/
void downloadInputFiles() throws PreComputeException {
for (String url : getPreComputeArgs().getInputFiles()) {
log.info("Downloading input file [chainTaskId:{}, url:{}]", chainTaskId, url);
if (FileHelper.downloadFile(url, getPreComputeArgs().getOutputDir()).isEmpty()) {
if (FileHelper.downloadFile(url, getPreComputeArgs().getOutputDir(), FileHashUtils.createFileNameFromUri(url))
.isEmpty()) {
throw new PreComputeException(ReplicateStatusCause.PRE_COMPUTE_INPUT_FILE_DOWNLOAD_FAILED);
}
}
}

/**
* Added for testing purpose.
*
* @return A {@link PreComputeArgs} instance
*/
PreComputeArgs getPreComputeArgs() {
Expand Down
105 changes: 53 additions & 52 deletions src/test/java/com/iexec/worker/compute/pre/PreComputeAppTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package com.iexec.worker.compute.pre;

import com.iexec.common.replicate.ReplicateStatusCause;
import com.iexec.common.utils.FileHashUtils;
import com.iexec.common.utils.FileHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

Expand All @@ -42,6 +43,7 @@
* This is a primary validation test for
* pre-compute execution.
*/
@ExtendWith(MockitoExtension.class)
@ExtendWith(SystemStubsExtension.class)
class PreComputeAppTests {

Expand Down Expand Up @@ -70,59 +72,58 @@ class PreComputeAppTests {

@BeforeEach
void beforeEach() {
MockitoAnnotations.openMocks(this);
preComputeApp = spy(new PreComputeApp(CHAIN_TASK_ID));
}

//region run
@Test
void shouldRunSuccessfullyWithDataset(EnvironmentVariables environment) throws PreComputeException {
environment.set(
IEXEC_TASK_ID, CHAIN_TASK_ID,
IEXEC_PRE_COMPUTE_OUT, outputDir.getAbsolutePath(),
IS_DATASET_REQUIRED, true,
IEXEC_DATASET_URL, HTTP_DATASET_URL,
IEXEC_DATASET_KEY, FileHelper.readFile(KEY_FILE),
IEXEC_DATASET_CHECKSUM, DATASET_CHECKSUM,
IEXEC_DATASET_FILENAME, DATASET_FILENAME,
IEXEC_INPUT_FILES_NUMBER, 2,
IEXEC_INPUT_FILE_URL_PREFIX + "1", INPUT_FILE_1_URL,
IEXEC_INPUT_FILE_URL_PREFIX + "2", INPUT_FILE_2_URL
);

final byte[] encryptedDataset = "encryptedDataset".getBytes();
final byte[] plainContent = "plainContent".getBytes();

doNothing().when(preComputeApp).checkOutputFolder();
doReturn(encryptedDataset).when(preComputeApp).downloadEncryptedDataset();
doReturn(plainContent).when(preComputeApp).decryptDataset(encryptedDataset);
doNothing().when(preComputeApp).savePlainDatasetFile(plainContent);
doNothing().when(preComputeApp).downloadInputFiles();

assertDoesNotThrow(() -> preComputeApp.run());
}

@Test
void shouldRunSuccessfullyWithoutDataset(EnvironmentVariables environment) throws PreComputeException {
environment.set(
IEXEC_TASK_ID, CHAIN_TASK_ID,
IEXEC_PRE_COMPUTE_OUT, outputDir.getAbsolutePath(),
IS_DATASET_REQUIRED, false,
IEXEC_INPUT_FILES_NUMBER, 2,
IEXEC_INPUT_FILE_URL_PREFIX + "1", INPUT_FILE_1_URL,
IEXEC_INPUT_FILE_URL_PREFIX + "2", INPUT_FILE_2_URL
);

doNothing().when(preComputeApp).checkOutputFolder();
doNothing().when(preComputeApp).downloadInputFiles();

assertDoesNotThrow(() -> preComputeApp.run());

verify(preComputeApp, never()).downloadEncryptedDataset();
verify(preComputeApp, never()).decryptDataset(any());
verify(preComputeApp, never()).savePlainDatasetFile(any());
}
//endregion
@Test
void shouldRunSuccessfullyWithDataset(EnvironmentVariables environment) throws PreComputeException {
environment.set(
IEXEC_TASK_ID, CHAIN_TASK_ID,
IEXEC_PRE_COMPUTE_OUT, outputDir.getAbsolutePath(),
IS_DATASET_REQUIRED, true,
IEXEC_DATASET_URL, HTTP_DATASET_URL,
IEXEC_DATASET_KEY, FileHelper.readFile(KEY_FILE),
IEXEC_DATASET_CHECKSUM, DATASET_CHECKSUM,
IEXEC_DATASET_FILENAME, DATASET_FILENAME,
IEXEC_INPUT_FILES_NUMBER, 2,
IEXEC_INPUT_FILE_URL_PREFIX + "1", INPUT_FILE_1_URL,
IEXEC_INPUT_FILE_URL_PREFIX + "2", INPUT_FILE_2_URL
);

final byte[] encryptedDataset = "encryptedDataset".getBytes();
final byte[] plainContent = "plainContent".getBytes();

doNothing().when(preComputeApp).checkOutputFolder();
doReturn(encryptedDataset).when(preComputeApp).downloadEncryptedDataset();
doReturn(plainContent).when(preComputeApp).decryptDataset(encryptedDataset);
doNothing().when(preComputeApp).savePlainDatasetFile(plainContent);
doNothing().when(preComputeApp).downloadInputFiles();

assertDoesNotThrow(() -> preComputeApp.run());
}

@Test
void shouldRunSuccessfullyWithoutDataset(EnvironmentVariables environment) throws PreComputeException {
environment.set(
IEXEC_TASK_ID, CHAIN_TASK_ID,
IEXEC_PRE_COMPUTE_OUT, outputDir.getAbsolutePath(),
IS_DATASET_REQUIRED, false,
IEXEC_INPUT_FILES_NUMBER, 2,
IEXEC_INPUT_FILE_URL_PREFIX + "1", INPUT_FILE_1_URL,
IEXEC_INPUT_FILE_URL_PREFIX + "2", INPUT_FILE_2_URL
);

doNothing().when(preComputeApp).checkOutputFolder();
doNothing().when(preComputeApp).downloadInputFiles();

assertDoesNotThrow(() -> preComputeApp.run());

verify(preComputeApp, never()).downloadEncryptedDataset();
verify(preComputeApp, never()).decryptDataset(any());
verify(preComputeApp, never()).savePlainDatasetFile(any());
}
//endregion

@Test
void shouldFindOutputFolder() {
Expand Down Expand Up @@ -290,8 +291,8 @@ void shouldDownloadInputFiles() throws Exception {
final PreComputeArgs preComputeArgs = getPreComputeArgsBuilder(HTTP_DATASET_URL).build();
doReturn(preComputeArgs).when(preComputeApp).getPreComputeArgs();
preComputeApp.downloadInputFiles();
assertThat(new File(outputDir, "plain-data.txt")).exists();
assertThat(new File(outputDir, "key.txt")).exists();
assertThat(new File(outputDir, FileHashUtils.createFileNameFromUri(INPUT_FILE_1_URL))).exists();
assertThat(new File(outputDir, FileHashUtils.createFileNameFromUri(INPUT_FILE_2_URL))).exists();
}

@Test
Expand Down

0 comments on commit 93b01a1

Please sign in to comment.