From e70a89c7d2346377e605e436882927575047ff68 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 21:23:11 +0100 Subject: [PATCH 1/2] executor: return the compiler errors of compileSourceCode After a CompilationException the result has no byteCodeObjects (null), and the debug log called .size() on it: the NullPointerException turned the answer into "Internal error processing compileSourceCode" and the compiler's error list (line numbers and messages) never reached the node or its API clients. The log now counts a null list as 0, so the FAILURE status with the errors is returned. A unit test of the handler checks it, and the Build workflow now runs the handler tests (after the jars are uploaded). Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 4 ++++ .../credits/thrift/ContractExecutorHandler.java | 5 ++++- .../thrift/ContractExecutorHandlerTest.java | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78dc1a28..11e14a4b 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 + # 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() { From 285d391eda46b95aaec93f4c98e0ecdfe51a2615 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 21:30:06 +0100 Subject: [PATCH 2/2] ci: the handler tests do not fail on modules without them Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11e14a4b..a0bdc2f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -117,7 +117,7 @@ jobs: # 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 + 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