Skip to content

Commit

Permalink
build: CI test bindings typescript-generated libs (#11)
Browse files Browse the repository at this point in the history
* build: add bindings-ts github workflow

* fix: update bindings to use new soroban-client and ContractSpec class

* Need to enable base64 in stellar-xdr

---------

Co-authored-by: Willem Wyndham <willem@ahalabs.dev>

* feat(CLI): add dotenv so directories can now set CLI args

* fix: don't fail if wasm already exists and log associated error as debug

* fix: update to use use .env and store standalone in local config

* fix: add standalone

* fix: return to src

Was a temp try to get cargo run to work, but isn't needed any more

* build: test generated lib for test-wasms/hello_world

* build: add auth test

* build: add signing to test wallet

* fix: parse returnValue

* build: update comment and typecheck

* rust: appease clippy and fmt with after new Rust release (stellar#899)

* fix: update soroban-client

---------

Co-authored-by: Willem Wyndham <willem@ahalabs.dev>
  • Loading branch information
chadoh and willemneal committed Aug 25, 2023
1 parent 8e607cb commit 5e28f84
Show file tree
Hide file tree
Showing 34 changed files with 483 additions and 62 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/bindings-ts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: bindings typescript

on: [push]

jobs:
test:
name: test generated libraries
runs-on: ubuntu-20.04
services:
rpc:
image: stellar/quickstart:soroban-dev@sha256:a6b03cf6b0433c99f2f799b719f0faadbb79684b1b763e7674ba749fb0f648ee
ports:
- 8000:8000
env:
ENABLE_LOGS: true
NETWORK: standalone
ENABLE_SOROBAN_RPC: true
options: >-
--health-cmd "curl -X POST \"http://localhost:8000/soroban/rpc\""
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- run: echo $CARGO_TARGET_DIR
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rustup update
- run: cargo build
- run: rustup target add wasm32-unknown-unknown
- run: make build-test-wasms
- run: npm ci && npm run test
working-directory: cmd/crates/soroban-spec-typescript/ts-tests
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
target/
.soroban/
!test.toml

cmd/crates/soroban-spec-typescript/fixtures/ts/package-lock.json
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/crates/soroban-spec-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn generate_from_wasm(wasm: &[u8]) -> Result<String, FromWasmError> {
Ok(json)
}

/// # Panics
pub fn generate(spec: &[ScSpecEntry]) -> String {
let collected: Vec<_> = spec.iter().map(Entry::from).collect();
serde_json::to_string_pretty(&collected).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/crates/soroban-spec-typescript/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::generate;
static PROJECT_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/src/project_template");

const NETWORK_PASSPHRASE_FUTURENET: &str = "Test SDF Future Network ; October 2022";
const NETWORK_PASSPHRASE_LOCALNET: &str = "Standalone Network ; February 2017";
const NETWORK_PASSPHRASE_STANDALONE: &str = "Standalone Network ; February 2017";

pub struct Project(PathBuf);

Expand Down Expand Up @@ -112,8 +112,8 @@ impl Project {
fn format_networks_object(contract_id: &str, network_passphrase: &str) -> String {
let network = if network_passphrase == NETWORK_PASSPHRASE_FUTURENET {
"futurenet"
} else if network_passphrase == NETWORK_PASSPHRASE_LOCALNET {
"localnet"
} else if network_passphrase == NETWORK_PASSPHRASE_STANDALONE {
"standalone"
} else {
"unknown"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"@stellar/freighter-api": "1.5.1",
"buffer": "6.0.3",
"soroban-client": "0.11.0"
"soroban-client": "0.11.1"
},
"scripts": {
"build": "node ./scripts/build.mjs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function invoke<R extends ResponseTypes, T = string>({
contractId,
wallet,
}: InvokeArgs<R, T>): Promise<T | string | SomeRpcResponse> {
wallet = wallet ?? (await import("@stellar/freighter-api"));
wallet = wallet ?? (await import("@stellar/freighter-api")).default;
let parse = parseResultXdr;
const server = new SorobanClient.Server(rpcUrl, {
allowHttp: rpcUrl.startsWith("http://"),
Expand Down Expand Up @@ -165,8 +165,8 @@ export async function invoke<R extends ResponseTypes, T = string>({
if (responseType === "full") return raw;

// if `sendTx` awaited the inclusion of the tx in the ledger, it used
// `getTransaction`, which has a `resultXdr` field
if ("resultXdr" in raw) return parse(raw.resultXdr.result().toXDR("base64"));
// `getTransaction`, which has a `returnValue` field
if ("returnValue" in raw) return parse(raw.returnValue);

// otherwise, it returned the result of `sendTransaction`
if ("errorResultXdr" in raw) return parse(raw.errorResultXdr);
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOROBAN_NETWORK=standalone
4 changes: 3 additions & 1 deletion cmd/crates/soroban-spec-typescript/ts-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build
node_modules
yarn.lock
yarn.lock
!.soroban/network/standalone.toml
contract-id-*.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rpc_url = "http://localhost:8000/soroban/rpc"
network_passphrase = "Standalone Network ; February 2017"
Loading

0 comments on commit 5e28f84

Please sign in to comment.