From 3c82e36ef49f389f5e3413aa0eebaf86dc2eb69f Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 21:26:38 +0100 Subject: [PATCH 1/3] api: ContractAllMethodsGet reports the annotations of methods and arguments The executor returns every method with its annotations (@Getter, @UsingContract, @ContractAddress, @ContractMethod and the others), but ContractAllMethodsGet copied only the name, return type and argument names and types, so a client could not tell a getter from a method that changes the state. The annotations of the methods and of their arguments now reach the client, in the fields the IDL already has (general.MethodDescription.annotations, MethodArgument.annotations). ci: contracts.py compiles samples/contracts/Counter.java and checks that ContractAllMethodsGet marks its three getters, and only them, with @Getter. Co-Authored-By: Claude Opus 5.5 --- api/src/apihandler.cpp | 5 +++++ ci/testnet/contracts.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/api/src/apihandler.cpp b/api/src/apihandler.cpp index 5ab7ac1ad..f1b3b4bfb 100644 --- a/api/src/apihandler.cpp +++ b/api/src/apihandler.cpp @@ -2498,10 +2498,15 @@ void APIHandler::ContractAllMethodsGet(ContractAllMethodsGetResult& _return, con ::general::MethodDescription method; method.name = met.name; method.returnType = met.returnType; + // the annotations the executor reports (e.g. @Getter on a method, @ContractAddress on an + // argument): a client tells a getter, which it may run for free, from a method that + // changes the state only through them + method.annotations = met.annotations; for (auto arg : met.arguments) { ::general::MethodArgument argument; argument.type = arg.type; argument.name = arg.name; + argument.annotations = arg.annotations; method.arguments.push_back(argument); } _return.methods.push_back(method); diff --git a/ci/testnet/contracts.py b/ci/testnet/contracts.py index 49aff8379..22767ab94 100644 --- a/ci/testnet/contracts.py +++ b/ci/testnet/contracts.py @@ -18,6 +18,8 @@ (Violations::SubsequentCall), and executor build 1518 fails an undeclared invokeExternalContract with an AccessControlException (its configuration is created lazily inside the contract sandbox). +ContractAllMethodsGet must report the @Getter annotations of samples/contracts/Counter.java. + Then, once --final-file exists (run.sh creates it when every node reached its target sequence), it compares the contract states on nodes 1 to --check-nodes (default ; run.sh adds a node that joined later). @@ -194,6 +196,33 @@ """ +# the examples of samples/contracts, read by the checks below +SAMPLES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "samples", "contracts") +GETTER = "com.credits.scapi.annotations.Getter" + + +def check_getter_annotations(client): + """ContractAllMethodsGet passes on the annotations the executor reports: the @Getter methods of + samples/contracts/Counter.java carry it and its state-changing methods do not, so a client can + tell what it may run as a free getter. Returns the number of failures.""" + with open(os.path.join(SAMPLES, "Counter.java")) as f: + source = f.read() + compiled = client.SmartContractCompile(source) + if compiled.status.code != 0: + print(f"ContractAllMethodsGet annotations: FAILED, compile: {compiled.status.message}", flush=True) + return 1 + got = client.ContractAllMethodsGet(compiled.byteCodeObjects) + if got.code != 0: + print(f"ContractAllMethodsGet annotations: FAILED, {got.message}", flush=True) + return 1 + annotated = sorted(m.name for m in got.methods if any(a.name == GETTER for a in (m.annotations or []))) + getters, others = {"getValue", "getNote", "getOwner"}, {"increment", "add", "setNote"} + ok = getters <= set(annotated) and not (others & set(annotated)) + print(f"ContractAllMethodsGet annotations: {'ok' if ok else 'FAILED'} (@Getter on {annotated}, " + f"expected {sorted(getters)} and not {sorted(others)})", flush=True) + return 0 if ok else 1 + + def write_sources(directory): """Write the test contracts as Java files, for a compile check before the network starts.""" placeholder = "11111111111111111111111111111111" @@ -539,6 +568,7 @@ def call_callers(when, via): call_callers("before restart", 1) failures = 0 + failures += check_getter_annotations(client_for(1)) calls = 0 for n in range(args.calls_before): calls += 1 From 86c3271536bcf0df14e11043bc0af98e36a80541 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 21:28:07 +0100 Subject: [PATCH 2/3] docs: CHANGES row for #164 Co-Authored-By: Claude Opus 5.5 --- docs/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 371603ce6..a1b59c008 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -48,6 +48,7 @@ lines under the new release. | #160 | packaging: the Docker health check read the last written block from the older of the two newest log files after a log rotation, so a node at the head was reported unhealthy; it now reads the newest file last | | #161 | samples: smart-contract examples (`samples/contracts/`: Counter, the test token CTT, the payable TipJar, a Faucet that reads its own balance, with a README on writing, deploying and calling contracts, getters, fees and payable) and the commands `deploy`, `call`, `get` and `methods` in every sample client (arguments in the declared types), checked offline against the fake node (`samples.yml`); ci: `testnet.yml` input `sample_contracts` deploys and calls the examples with the Python and Java clients on the private network and checks the token API (`ci/testnet/sample_contracts.sh`) | | #163 | ci: the testnet script stops at the start when a pruned node is in the run and `TARGET_SEQ` is below 2100: a pruned node prunes first at the checkpoint of block 2000, so a lower target only failed after the whole run with "never pruned its storage" | +| #164 | api: `ContractAllMethodsGet` now returns the annotations the executor reports for each method and argument (`@Getter`, `@UsingContract`, `@ContractAddress`, `@ContractMethod`, in the IDL fields `MethodDescription.annotations` and `MethodArgument.annotations` that were always left empty), so a client can tell a getter; ci: `contracts.py` checks the `@Getter` methods of `samples/contracts/Counter.java` | ## community.16 — 2026-11-03 From 637fc420358ca11941c8623fa592dc79d52e641a Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 21:29:14 +0100 Subject: [PATCH 3/3] ci: report the compile errors of the executor under test With executor_ref (mixed executors), contracts.py compiles a source with two errors on the even nodes and prints what SmartContractCompile returns: the compiler's errors with their line numbers once the executor has CreditsCommunity/contract-executor#13. Reported only; nodes running the release executor are left out, as its failure makes the node reopen its executor connection. Co-Authored-By: Claude Opus 5.5 --- ci/testnet/contracts.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ci/testnet/contracts.py b/ci/testnet/contracts.py index 22767ab94..8be93d890 100644 --- a/ci/testnet/contracts.py +++ b/ci/testnet/contracts.py @@ -223,6 +223,25 @@ def check_getter_annotations(client): return 0 if ok else 1 +def report_compile_errors(client_for, nodes): + """With mixed executors (EXECUTOR_JAR_ALT, testnet.yml input executor_ref): SmartContractCompile + of a source with two errors (lines 11 and 12) on the even nodes, which run the executor under + test. Reported, not checked. An executor with CreditsCommunity/contract-executor#13 returns the + compiler's errors with their line numbers; the release executor (build 1555 and before) fails + with "Internal error processing compileSourceCode", and the node then drops and reopens its + executor connection, so the nodes running it are left out.""" + if not os.environ.get("EXECUTOR_JAR_ALT"): + return + broken = COUNTER.replace("value += 1;", "value += missingA;\n value += missingB;") + for i in range(2, nodes + 1, 2): + try: + got = client_for(i).SmartContractCompile(broken) + lines = [l for l in (got.status.message or "").splitlines() if not l.lstrip().startswith("at ")][:4] + print(f"SmartContractCompile with errors on n{i} (reported): status {got.status.code}, {' | '.join(lines)!r}", flush=True) + except Exception as e: + print(f"SmartContractCompile with errors on n{i} (reported): {type(e).__name__}: {e}", flush=True) + + def write_sources(directory): """Write the test contracts as Java files, for a compile check before the network starts.""" placeholder = "11111111111111111111111111111111" @@ -569,6 +588,7 @@ def call_callers(when, via): failures = 0 failures += check_getter_annotations(client_for(1)) + report_compile_errors(client_for, args.nodes) calls = 0 for n in range(args.calls_before): calls += 1