diff --git a/.github/workflows/bindings-ts.yml b/.github/workflows/bindings-ts.yml new file mode 100644 index 0000000000..62469fd7d5 --- /dev/null +++ b/.github/workflows/bindings-ts.yml @@ -0,0 +1,43 @@ + +name: bindings typescript + +on: + push: + branches: [main, release/**] + pull_request: + +jobs: + test: + name: test generated libraries + runs-on: ubuntu-22.04 + services: + rpc: + image: stellar/quickstart:soroban-dev@sha256:0ad51035cf7caba2fd99c7c1fad0945df6932be7d5c893e1520ccdef7d6a6ffe + ports: + - 8000:8000 + env: + ENABLE_LOGS: true + NETWORK: local + ENABLE_SOROBAN_RPC: true + options: >- + --health-cmd "curl --no-progress-meter --fail-with-body -X POST \"http://localhost:8000/soroban/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getNetwork\"}' && curl --no-progress-meter \"http://localhost:8000/friendbot\" | grep '\"invalid_field\": \"addr\"'" + --health-interval 10s + --health-timeout 5s + --health-retries 50 + steps: + - 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/src/project_template/package.json b/cmd/crates/soroban-spec-typescript/src/project_template/package.json index 3c6b89642a..99d120dac7 100644 --- a/cmd/crates/soroban-spec-typescript/src/project_template/package.json +++ b/cmd/crates/soroban-spec-typescript/src/project_template/package.json @@ -4,7 +4,7 @@ "dependencies": { "@stellar/freighter-api": "1.7.1", "buffer": "6.0.3", - "stellar-sdk": "11.1.0" + "stellar-sdk": "11.2.0" }, "scripts": { "build": "node ./scripts/build.mjs" @@ -15,6 +15,6 @@ }, "typings": "dist/types/index.d.ts", "devDependencies": { - "typescript": "5.1.6" + "typescript": "5.3.3" } } diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/.nvmrc b/cmd/crates/soroban-spec-typescript/ts-tests/.nvmrc deleted file mode 100644 index 03db17dcc4..0000000000 --- a/cmd/crates/soroban-spec-typescript/ts-tests/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -v20.6.0 diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh b/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh index 9a2a83b63b..621be2bc3f 100755 --- a/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh +++ b/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh @@ -16,22 +16,28 @@ echo " Passphrase: \"$SOROBAN_NETWORK_PASSPHRASE\"" NETWORK_STATUS=$(curl -s -X POST "http://localhost:8000/soroban/rpc" -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 8675309, "method": "getHealth" }' | sed 's/.*"status":"\(.*\)".*/\1/') || { echo "Make sure you're running local RPC network on localhost:8000" && exit 1; } echo " Status: $NETWORK_STATUS" +if [[ "$NETWORK_STATUS" != "healthy" ]]; then + echo "Network is not healthy (not running?), exiting" + exit 1 +fi + # Print command before executing, from https://stackoverflow.com/a/23342259/249801 # Discussion: https://github.com/stellar/soroban-tools/pull/1034#pullrequestreview-1690667116 exe() { echo"${@/eval/}" ; "$@" ; } function fund_all() { - exe eval "./soroban config identity fund" - exe eval "./soroban config identity generate alice" - exe eval "./soroban config identity fund alice" - exe eval "./soroban config identity generate bob" - exe eval "./soroban config identity fund bob" + exe eval "./soroban keys generate root" + exe eval "./soroban keys fund root" + exe eval "./soroban keys generate alice" + exe eval "./soroban keys fund alice" + exe eval "./soroban keys generate bob" + exe eval "./soroban keys fund bob" } function upload() { - exe eval "(./soroban contract $1 --wasm $2 --ignore-checks) > $3" + exe eval "(./soroban contract $1 --source root --wasm $2 --ignore-checks) > $3" } function deploy() { - exe eval "(./soroban contract deploy --wasm-hash $(cat $1) --ignore-checks) > $2" + exe eval "(./soroban contract deploy --source root --wasm-hash $(cat $1) --ignore-checks) > $2" } function deploy_all() { upload deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt @@ -42,7 +48,7 @@ function deploy_all() { deploy contract-token-hash.txt contract-id-token-b.txt } function initialize() { - exe eval "./soroban contract invoke --id $(cat $1) -- initialize --admin $(./soroban config identity address) --decimal 0 --name 'Token $2' --symbol '$2'" + exe eval "./soroban contract invoke --source root --id $(cat $1) -- initialize --admin $(./soroban keys address root) --decimal 0 --name 'Token $2' --symbol '$2'" } function initialize_all() { initialize contract-id-token-a.txt A @@ -59,14 +65,13 @@ function bind_all() { } function mint() { - exe eval "./soroban contract invoke --id $(cat $1) -- mint --amount 2000000 --to $(./soroban config identity address $2)" + exe eval "./soroban contract invoke --source root --id $(cat $1) -- mint --amount 2000000 --to $(./soroban keys address $2)" } function mint_all() { mint contract-id-token-a.txt alice mint contract-id-token-b.txt bob } -curl -X POST "http://localhost:8000/soroban/rpc" || { echo "Make sure you're running standalone RPC network on localhost:8000" && exit 1; } fund_all deploy_all initialize_all 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 1ed2de71f0..de202a0e9c 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json @@ -13,8 +13,8 @@ "ava": "^5.3.1", "dotenv": "^16.3.1", "eslint": "^8.53.0", - "stellar-sdk": "11.1.0", - "typescript": "^5.1.6" + "stellar-sdk": "11.2.0", + "typescript": "^5.3.3" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -649,12 +649,12 @@ } }, "node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", + "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", "dev": true, "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.4", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -1586,9 +1586,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -2923,13 +2923,13 @@ } }, "node_modules/stellar-sdk": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/stellar-sdk/-/stellar-sdk-11.1.0.tgz", - "integrity": "sha512-fIdo77ogpU+ecHgs59pk9velpXd4F/ch0DzOI4QZw8zVZApc3oeNWP3+X6ui7BWpeRHAGsP2CHQzBLxm0JTIgg==", + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/stellar-sdk/-/stellar-sdk-11.2.0.tgz", + "integrity": "sha512-rmAJsJ7jXm/75pKOEwiREIaHr8tv53fMwdsDNOhIpOV/K5Twn/q13DTkbmNjcCvcgU9yOMF/j/dv5nZsfqKYXg==", "dev": true, "dependencies": { "@stellar/stellar-base": "10.0.1", - "axios": "^1.6.0", + "axios": "^1.6.5", "bignumber.js": "^9.1.2", "eventsource": "^2.0.2", "randombytes": "^2.1.0", diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/package.json b/cmd/crates/soroban-spec-typescript/ts-tests/package.json index 37633c7d49..35364e17ff 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/package.json +++ b/cmd/crates/soroban-spec-typescript/ts-tests/package.json @@ -14,8 +14,8 @@ "ava": "^5.3.1", "dotenv": "^16.3.1", "eslint": "^8.53.0", - "stellar-sdk": "11.1.0", - "typescript": "^5.1.6" + "stellar-sdk": "11.2.0", + "typescript": "^5.3.3" }, "ava": { "typescript": { diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/src/test-custom-types.ts b/cmd/crates/soroban-spec-typescript/ts-tests/src/test-custom-types.ts index 75f261d947..3b07dc3d42 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/src/test-custom-types.ts +++ b/cmd/crates/soroban-spec-typescript/ts-tests/src/test-custom-types.ts @@ -2,7 +2,6 @@ import test from 'ava' import { root, rpcUrl, wallet } from './util.js' import { Contract, Ok, Err, networks } from 'test-custom-types' -const addr = root.address; const publicKey = root.keypair.publicKey(); const contract = new Contract({ ...networks.standalone, rpcUrl, wallet }); @@ -50,18 +49,21 @@ test("strukt", async (t) => { }) test('simple first', async t => { - const simple = { tag: 'First', values: undefined } as const - t.deepEqual((await contract.simple({ simple })).result, simple) + const arg = { tag: 'First', values: undefined } as const + const ret = { tag: 'First' } + t.deepEqual((await contract.simple({ simple: arg })).result, ret) }) test('simple second', async t => { - const simple = { tag: 'Second', values: undefined } as const - t.deepEqual((await contract.simple({ simple })).result, simple) + const arg = { tag: 'Second', values: undefined } as const + const ret = { tag: 'Second' } + t.deepEqual((await contract.simple({ simple: arg })).result, ret) }) test('simple third', async t => { - const simple = { tag: 'Third', values: undefined } as const - t.deepEqual((await contract.simple({ simple })).result, simple) + const arg = { tag: 'Third', values: undefined } as const + const ret = { tag: 'Third' } + t.deepEqual((await contract.simple({ simple: arg })).result, ret) }) test('complex with struct', async t => { @@ -72,29 +74,30 @@ test('complex with struct', async t => { test('complex with tuple', async t => { const arg = { tag: 'Tuple', values: [[{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }]] } as const - const ret = { tag: 'Tuple', values: [[{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }]] } + const ret = { tag: 'Tuple', values: [[{ a: 0, b: true, c: 'hello' }, { tag: 'First' }]] } t.deepEqual((await contract.complex({ complex: arg })).result, ret) }) test('complex with enum', async t => { const arg = { tag: 'Enum', values: [{ tag: 'First', values: undefined }] } as const - const ret = { tag: 'Enum', values: [{ tag: 'First', values: undefined }] } + const ret = { tag: 'Enum', values: [{ tag: 'First' }] } t.deepEqual((await contract.complex({ complex: arg })).result, ret) }) test('complex with asset', async t => { const arg = { tag: 'Asset', values: [publicKey, 1n] } as const - const ret = { tag: 'Asset', values: [addr, 1n] } + const ret = { tag: 'Asset', values: [publicKey, 1n] } t.deepEqual((await contract.complex({ complex: arg })).result, ret) }) test('complex with void', async t => { - const complex = { tag: 'Void', values: undefined } as const - t.deepEqual((await contract.complex({ complex })).result, complex) + const arg = { tag: 'Void', values: undefined } as const + const ret = { tag: 'Void' } + t.deepEqual((await contract.complex({ complex: arg })).result, ret) }) test('addresse', async t => { - t.deepEqual((await contract.addresse({ addresse: publicKey })).result, addr) + t.deepEqual((await contract.addresse({ addresse: publicKey })).result, publicKey) }) test('bytes', async t => { @@ -138,7 +141,8 @@ test('map', async t => { map.set(1, true) map.set(2, false) // map.set(3, 'hahaha') // should throw an error - t.deepEqual((await contract.map({ map })).result, map) + const ret = Array.from(map.entries()) + t.deepEqual((await contract.map({ map })).result, ret) }) test('vec', async t => { @@ -178,6 +182,6 @@ test('string', async t => { 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' }, { tag: 'First', values: undefined }] + const res = [{ a: 0, b: true, c: 'hello' }, { tag: 'First' }] t.deepEqual((await contract.tupleStrukt({ tuple_strukt: arg })).result, res) }) diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/src/test-hello-world.ts b/cmd/crates/soroban-spec-typescript/ts-tests/src/test-hello-world.ts index 5ccdde7881..e658c4552b 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/src/test-hello-world.ts +++ b/cmd/crates/soroban-spec-typescript/ts-tests/src/test-hello-world.ts @@ -14,7 +14,7 @@ test("auth", async (t) => { addr: root.keypair.publicKey(), world: 'lol' })).result, - root.address + root.keypair.publicKey() ) }); diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts b/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts index 69c15350ec..102989427e 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts +++ b/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts @@ -2,9 +2,9 @@ import { spawnSync } from "node:child_process"; import { Keypair, TransactionBuilder, hash } from "stellar-sdk"; import { Address } from 'test-custom-types' -const rootKeypair = Keypair.fromSecret(spawnSync("./soroban", ["config", "identity", "show"], { shell: true, encoding: "utf8" }).stdout.trim()); -const aliceKeypair = Keypair.fromSecret(spawnSync("./soroban", ["config", "identity", "show", "alice"], { shell: true, encoding: "utf8" }).stdout.trim()); -const bobKeypair = Keypair.fromSecret(spawnSync("./soroban", ["config", "identity", "show", "bob"], { shell: true, encoding: "utf8" }).stdout.trim()); +const rootKeypair = Keypair.fromSecret(spawnSync("./soroban", ["keys", "show", "root"], { shell: true, encoding: "utf8" }).stdout.trim()); +const aliceKeypair = Keypair.fromSecret(spawnSync("./soroban", ["keys", "show", "alice"], { shell: true, encoding: "utf8" }).stdout.trim()); +const bobKeypair = Keypair.fromSecret(spawnSync("./soroban", ["keys", "show", "bob"], { shell: true, encoding: "utf8" }).stdout.trim()); export const root = { keypair: rootKeypair,