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
38 changes: 36 additions & 2 deletions .github/scripts/codegen-compile-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# they target, so this job checks that pairing: the SDK release must already
# exist before the templates may target it.
#
# Usage: codegen-compile-check.sh <rust-client|ts-client|python-client|go-client|swift-client> [path/to/tx3c]
# Needs the matching toolchain on PATH: cargo, node/npm, python3, go, or swift.
# Usage: codegen-compile-check.sh <rust-client|ts-client|python-client|go-client|java-client|swift-client> [path/to/tx3c]
# Needs the matching toolchain on PATH: cargo, node/npm, python3, go, a JDK
# (java-client also needs git; Maven comes from the SDK checkout's wrapper), or swift.
set -euo pipefail

template="$1"
Expand All @@ -19,6 +20,28 @@ template_dir="$repo_root/bin/tx3c/templates/$template"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT

# Until land.tx3:tx3-sdk:0.15.0 is on Maven Central, the Java client compiles
# against the java-sdk repository at this commit, installed into the local
# Maven repository as 0.15.0-SNAPSHOT and selected through the generated
# project's tx3.sdk.version property. Once the release exists, drop this block
# and the -Dtx3.sdk.version override so the check builds against the
# published package like the other languages.
java_sdk_repo="https://github.com/tx3-lang/java-sdk.git"
java_sdk_pin="d7a6dc4da56f73a7a47fe2e77444ad056885cfe7"
java_sdk_version="0.15.0-SNAPSHOT"
mvn=""
if [ "$template" = "java-client" ]; then
sdk="$work/java-sdk"
git clone --quiet "$java_sdk_repo" "$sdk"
git -C "$sdk" checkout --quiet "$java_sdk_pin"
mvn="$sdk/mvnw"
(
cd "$sdk"
"$mvn" -B -ntp -q versions:set -DnewVersion="$java_sdk_version" -DgenerateBackupPoms=false
"$mvn" -B -ntp -q -DskipTests install
)
fi

# The Swift client pins swift-sdk `from: "0.15.0"`, which has no tagged release
# yet. Until it does, the check builds against the swift-sdk repository at this
# commit: a clone tagged `0.15.0` locally stands in for the release through a
Expand Down Expand Up @@ -77,6 +100,17 @@ PY
go-client)
(cd "$gen" && go mod tidy && go build ./...)
;;
java-client)
# Compile the generated Maven project, then run a smoke consumer inside
# it: the rendered files are the only thing in the directory, so the
# client runs without its source TII.
mkdir -p "$gen/src/main/java/smoke"
cp "$repo_root/.github/scripts/java-client-smoke/$fixture/Smoke.java" "$gen/src/main/java/smoke/"
"$mvn" -B -ntp -q -f "$gen/pom.xml" -Dtx3.sdk.version="$java_sdk_version" verify
"$mvn" -B -ntp -q -f "$gen/pom.xml" -Dtx3.sdk.version="$java_sdk_version" \
dependency:build-classpath -Dmdep.outputFile="$gen/classpath.txt"
java -cp "$gen/target/classes:$(cat "$gen/classpath.txt")" smoke.Smoke
;;
swift-client)
swift package --package-path "$gen" config set-mirror \
--original "$swift_sdk_url" --mirror "file://$swift_sdk"
Expand Down
64 changes: 64 additions & 0 deletions .github/scripts/java-client-smoke/complex/Smoke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package smoke;

import java.math.BigInteger;
import java.net.URI;
import java.util.List;
import java.util.Map;
import land.tx3.generated.complexTypes.ComplexTypesClient;
import land.tx3.sdk.Address;
import land.tx3.sdk.ArgValue;
import land.tx3.sdk.ClientOptions;
import land.tx3.sdk.UtxoRef;

/**
* Runs the client generated from the complex fixture without the source TII: the single-profile
* constructor and a typed transaction method whose parameters cover every schema kind, so each
* static {@code ArgValue} construction path executes. Nothing is resolved, so no TRP endpoint is
* contacted.
*/
public final class Smoke {
private Smoke() {}

public static void main(String[] args) {
check("complex-types".equals(ComplexTypesClient.PROTOCOL_NAME), "protocol name");
check(ComplexTypesClient.Profile.values().length == 1, "one profile");

var client =
new ComplexTypesClient(
ClientOptions.forEndpoint(URI.create("http://localhost:8164")),
ComplexTypesClient.Profile.LOCAL);

var params =
new ComplexTypesClient.ComplexParams(
BigInteger.TEN,
true,
ArgValue.struct(0, List.of()),
new Address("addr_test1recipient"),
new UtxoRef(new byte[32], 1),
ArgValue.string("any-asset"),
List.of(BigInteger.ONE, BigInteger.TWO),
new ComplexTypesClient.ComplexParams.ComplexParamsPair(BigInteger.ZERO, new byte[] {1, 2}),
Map.of("b", BigInteger.TWO, "a", BigInteger.ONE),
new ComplexTypesClient.AssetClass(new byte[] {3}, new byte[] {4}),
new ComplexTypesClient.Side.Sell(BigInteger.valueOf(42)));

check(client.complex(params) != null, "complex builder");
check(
new ComplexTypesClient.Side.Buy().toArgValue() instanceof ArgValue.Struct buy
&& buy.constructor() == 0
&& buy.fields().isEmpty(),
"variant case index");
check(
params.asset().toArgValue() instanceof ArgValue.Struct asset
&& asset.constructor() == 0
&& asset.fields().size() == 2,
"record fields");
System.out.println("java-client smoke passed for complex");
}

private static void check(boolean condition, String what) {
if (!condition) {
throw new IllegalStateException("smoke check failed: " + what);
}
}
}
43 changes: 43 additions & 0 deletions .github/scripts/java-client-smoke/transfer/Smoke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package smoke;

import java.math.BigInteger;
import java.net.URI;
import land.tx3.generated.unknown.UnknownClient;
import land.tx3.sdk.Address;
import land.tx3.sdk.ClientOptions;
import land.tx3.sdk.Party;

/**
* Runs the client generated from the transfer fixture without the source TII: every constructor
* variant the fixture offers, a typed party binder, and a typed transaction method building its
* tagged arguments. Nothing is resolved, so no TRP endpoint is contacted.
*/
public final class Smoke {
private Smoke() {}

public static void main(String[] args) {
check("unknown".equals(UnknownClient.PROTOCOL_NAME), "protocol name");
check("0.0.1".equals(UnknownClient.PROTOCOL_VERSION), "protocol version");
check("v1beta0".equals(UnknownClient.TARGET_TII_VERSION), "target TII version");
check("hex".equals(UnknownClient.TRANSFER_TIR.encoding()), "embedded TIR");
check(UnknownClient.Profile.values().length == 2, "two profiles");

var options = ClientOptions.forEndpoint(URI.create("http://localhost:8164"));
for (var profile : UnknownClient.Profile.values()) {
var client =
new UnknownClient(options, profile)
.withSender(Party.address(new Address("addr_test1sender")))
.withReceiver(Party.address(new Address("addr_test1receiver")))
.withMiddleman(Party.address(new Address("addr_test1middleman")));
var builder = client.transfer(new UnknownClient.TransferParams(BigInteger.valueOf(10_000_000)));
check(builder != null, "transfer builder for " + profile.profileName());
}
System.out.println("java-client smoke passed for transfer");
}

private static void check(boolean condition, String what) {
if (!condition) {
throw new IllegalStateException("smoke check failed: " + what);
}
}
}
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
strategy:
fail-fast: false
matrix:
template: [rust-client, ts-client, python-client, go-client, swift-client]
template: [rust-client, ts-client, python-client, go-client, java-client, swift-client]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -89,5 +89,11 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.24"
- if: matrix.template == 'java-client'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: maven
- run: cargo build -p tx3c --locked
- run: bash .github/scripts/codegen-compile-check.sh ${{ matrix.template }} target/debug/tx3c
Loading
Loading