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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Loading