diff --git a/api/src/apihandler.cpp b/api/src/apihandler.cpp index e97561f9b..2a8700625 100644 --- a/api/src/apihandler.cpp +++ b/api/src/apihandler.cpp @@ -2507,10 +2507,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 7275610ac..b83b9c7b8 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. + It deploys samples/contracts/TipJar.java and pays it with plain CS transfers: SmartContractsListGet must still list, for the payers, exactly the contracts they deployed, and TransactionsGet must show the payments as contract replenishes. @@ -200,6 +202,50 @@ # 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 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) + + TT_CONTRACT_REPLENISH = 4 # api.TransactionType: a CS transfer that ran a contract's payable() @@ -610,6 +656,8 @@ def call_callers(when, via): call_callers("before restart", 1) failures = 0 + failures += check_getter_annotations(client_for(1)) + report_compile_errors(client_for, args.nodes) tipjar, tipjar_failures = tipjar_payments(client_for, master, [counter, ledger, caller, declared] + ([dice] if dice else [])) failures += tipjar_failures calls = 0 diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 04c37f9fc..1f29fb2e8 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -49,6 +49,7 @@ lines under the new release. | #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`) | | #162 | api: `GetNodeInfo` of the diagnostic API returns `networkUuid` (the chain identifier from block 1, the same on every node of a network: mainnet `11024959585341937636`, sent as the i64 `-7421784488367613980`) and `communityVersion` (the first line of `VERSION`), two optional fields, so that a wallet can tell mainnet from a test network; the Thrift definitions now come from the fork CreditsCommunity/thrift-interface-definitions (branch `community/network-id`; local clones need `git submodule sync` once); ci: the testnet runs check both fields on every node through the diag port (`ci/testnet/diag_info.py`), and the official node under comparison builds with its own IDL commit | | #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` | | #165 | api: a CS payment to a payable contract was recorded as a contract deployed by the payer, and `SmartContractsListGet` / `SmartContractAddressesListGet` failed on every page holding one ("No more data to read"); only a transaction carrying an invocation now counts as a deploy in that list (API only, `SmartContracts::is_deploy` and consensus unchanged); ci: `contracts.py` pays `samples/contracts/TipJar.java` and checks the lists and the payments in `TransactionsGet` | ## community.16 — 2026-11-03