From 533544d2ae7d7c0cebcb8565c1b56a057593b224 Mon Sep 17 00:00:00 2001 From: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Date: Thu, 17 Aug 2023 13:50:48 -0400 Subject: [PATCH] build: add bindings-ts github workflow --- .github/workflows/bindings-ts.yml | 40 +++++++++++++++++++ .../ts-tests/package-lock.json | 13 ++++++ .../ts-tests/package.json | 1 + .../soroban-spec-typescript/ts-tests/soroban | 3 ++ .../ts-tests/src/test.ts | 6 +-- 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/bindings-ts.yml create mode 100755 cmd/crates/soroban-spec-typescript/ts-tests/soroban diff --git a/.github/workflows/bindings-ts.yml b/.github/workflows/bindings-ts.yml new file mode 100644 index 000000000..3fb8c407e --- /dev/null +++ b/.github/workflows/bindings-ts.yml @@ -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 diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json b/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json index 954928b09..8e539e50d 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json @@ -4,6 +4,7 @@ "requires": true, "packages": { "": { + "hasInstallScript": true, "devDependencies": { "@ava/typescript": "^4.1.0", "@types/node": "^20.4.9", @@ -11,6 +12,18 @@ "typescript": "^5.1.6" } }, + "../fixtures/test_custom_types": { + "version": "0.0.0", + "extraneous": true, + "dependencies": { + "@stellar/freighter-api": "1.5.1", + "buffer": "6.0.3", + "soroban-client": "0.9.2" + }, + "devDependencies": { + "typescript": "5.1.6" + } + }, "node_modules/@ava/typescript": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-4.1.0.tgz", diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/package.json b/cmd/crates/soroban-spec-typescript/ts-tests/package.json index c840d9335..0011ad6b1 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/package.json +++ b/cmd/crates/soroban-spec-typescript/ts-tests/package.json @@ -2,6 +2,7 @@ "private": true, "type": "module", "scripts": { + "postinstall": "curl -X POST \"http://localhost:8000/soroban/rpc\" && ./soroban config network add standalone --rpc-url \"http://localhost:8000/soroban/rpc\" --network-passphrase \"Standalone Network ; February 2017\" && ./soroban config identity fund --network standalone && export CONTRACT_ID=$(./soroban contract deploy --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm --network standalone) && ./soroban contract bindings typescript --contract-id $CONTRACT_ID --network standalone --output-dir ./node_modules/test-custom-types --overwrite || { echo \"Make sure you're running standalone RPC network on localhost:8000\" && exit 1; }", "test": "ava" }, "devDependencies": { diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/soroban b/cmd/crates/soroban-spec-typescript/ts-tests/soroban new file mode 100755 index 000000000..93b0bf350 --- /dev/null +++ b/cmd/crates/soroban-spec-typescript/ts-tests/soroban @@ -0,0 +1,3 @@ +#!/bin/bash + +../../../../target/debug/soroban "$@" diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/src/test.ts b/cmd/crates/soroban-spec-typescript/ts-tests/src/test.ts index 32e92bacb..58824c248 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/src/test.ts +++ b/cmd/crates/soroban-spec-typescript/ts-tests/src/test.ts @@ -1,11 +1,11 @@ import test from 'ava' -import { Contract, Ok, Err, networks } from '../../fixtures/test_custom_types/dist/esm/index.js' +import { Contract, Ok, Err, networks } from 'test-custom-types' const rpcUrl = 'https://rpc-futurenet.stellar.org' const publicKey = 'GCBVOLOM32I7OD5TWZQCIXCXML3TK56MDY7ZMTAILIBQHHKPCVU42XYW' const contract = new Contract({ - ...networks.futurenet, + ...networks[Object.keys(networks)[0] as keyof typeof networks], rpcUrl, wallet: { isConnected: () => Promise.resolve(true), @@ -185,4 +185,4 @@ test('tuple_strukt', async t => { const arg = [{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }] as const const res = [{ a: 0, b: true, c: 'hello' }, ['First']] t.deepEqual(await contract.tupleStrukt({ tuple_strukt: arg }), res) -}) \ No newline at end of file +})