diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78dc1a28..a0bdc2f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,6 +115,10 @@ jobs: contract-executor/target/contract-executor-*.jar sc-api-support/target/sc-api-support-*.jar + # after the upload: the jars above are the ones the package step built + - name: Unit tests of the Thrift handler + run: $MVN -pl contract-executor -am test -Dtest=ContractExecutorHandlerTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false + # The token scenarios of EnzinoBB/node (ci/contracts/executor_harness.py) on the release executor and # on this build, through their Thrift interface with a stub of the node: every answer (status, return # value, state hashes, emitted transactions) must be the same, or contracts would give different diff --git a/contract-executor/src/main/java/com/credits/thrift/ContractExecutorHandler.java b/contract-executor/src/main/java/com/credits/thrift/ContractExecutorHandler.java index 8314070c..73c5fd30 100644 --- a/contract-executor/src/main/java/com/credits/thrift/ContractExecutorHandler.java +++ b/contract-executor/src/main/java/com/credits/thrift/ContractExecutorHandler.java @@ -205,7 +205,10 @@ public CompileSourceCodeResult compileSourceCode(String sourceCode, short versio } catch (Throwable e) { result = new CompileSourceCodeResult(defineFailureCode(e), emptyList()); } - logger.debug("compileBytecode --> {} amountByteCodeObjects={}", result.status, result.byteCodeObjects.size()); + // byteCodeObjects stays null after a CompilationException: a NullPointerException here would + // replace the compiler's error list with "Internal error processing compileSourceCode" + logger.debug("compileBytecode --> {} amountByteCodeObjects={}", + result.status, result.byteCodeObjects == null ? 0 : result.byteCodeObjects.size()); return result; } diff --git a/contract-executor/src/test/java/tests/credits/thrift/ContractExecutorHandlerTest.java b/contract-executor/src/test/java/tests/credits/thrift/ContractExecutorHandlerTest.java index 4155bd82..0d3b5c71 100644 --- a/contract-executor/src/test/java/tests/credits/thrift/ContractExecutorHandlerTest.java +++ b/contract-executor/src/test/java/tests/credits/thrift/ContractExecutorHandlerTest.java @@ -7,6 +7,7 @@ import com.credits.general.thrift.generated.ByteCodeObject; import com.credits.general.thrift.generated.ClassObject; import com.credits.general.thrift.generated.Variant; +import com.credits.general.util.compiler.CompilationException; import com.credits.scapi.v2.SmartContract; import com.credits.thrift.ContractExecutorHandler; import exception.ContractExecutorException; @@ -184,6 +185,21 @@ void checkAppVersionTest() { invalidVersion).getStatus()); } + @Test + @DisplayName("compileSourceCode must return the compiler errors of a CompilationException") + void compileSourceCodeReturnsCompilationErrors() throws Exception { + when(mockCEService.compileContractClass(any())).thenThrow( + new CompilationException("Contract", List.of(new CompilationException.Error(7, "';' expected"), + new CompilationException.Error(12, "cannot find symbol")))); + + var result = contractExecutorHandler.compileSourceCode("broken source", API_VERSION); + + assertThat(result.getStatus().code, is(FAILURE.code)); + assertThat(result.getStatus().getMessage(), containsString("CompilationException")); + assertThat(result.getStatus().getMessage(), containsString("7:';' expected")); + assertThat(result.getStatus().getMessage(), containsString("12:cannot find symbol")); + } + @Test @DisplayName("results with exceptions must returned with failure status") void executeByteCodeThrowException() {