diff --git a/CHANGELOG.md b/CHANGELOG.md index ef939c8e5..d843be7f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,64 @@ A breaking change will get clearly marked in this log. ## Unreleased +### Breaking Changes + +- `ContractClient` functionality previously added in [v11.3.0](https://github.com/stellar/js-stellar-sdk/releases/tag/v11.3.0) was exported in a non-standard way. You can now import it as any other stellar-sdk module. + + ```diff + - import { ContractClient } from '@stellar/stellar-sdk/lib/contract_client' + - import { ContractClient } from '@stellar/stellar-sdk' + ``` + + Note that this top-level export is now a container for all ContractClient-related functionality. The ContractClient class is now available at `ContractClient.Client`. + + Additionally, it is available from the `/ContractClient` entrypoint, if your version of Node ([and TypeScript!](https://stackoverflow.com/a/70020984/249801)) supports [the `exports` declaration](https://nodejs.org/api/packages.html#exports). Finally, some of its exports have been renamed. + + ```diff + import { + - ContractClient, + + Client, + AssembledTransaction, + - ContractClientOptions, + + Options, + SentTransaction, + -} from '@stellar/stellar-sdk/lib/contract_client' + +} from '@stellar/stellar-sdk/ContractClient' + ``` + + +- `ContractSpec` class now nested under `ContractClient` module, and has been renamed to `Spec`. + + ```diff + -import { ContractSpec } from '@stellar/stellar-sdk' + +import { ContractClient } from '@stellar/stellar-sdk' + +const { Spec } = ContractClient + ``` + + Alternatively, you can import this from the `ContractClient` entrypoint. + + ```diff + -import { ContractSpec } from '@stellar/stellar-sdk' + +import { Spec } from '@stellar/stellar-sdk/ContractClient' + ``` + +### Added + +- `SorobanRpc` module is now also exported as `Rpc`. You can import it with either name. + + ```diff + import { SorobanRpc } from '@stellar/stellar-sdk' + +// OR + +import { Rpc } from '@stellar/stellar-sdk' + ``` + + You can also now import its exports at the `/Rpc` entrypoint, if your version of Node ([and TypeScript!](https://stackoverflow.com/a/70020984/249801)) supports [the `exports` declaration](https://nodejs.org/api/packages.html#exports). + + ```diff + -import { SorobanRpc } from '@stellar/stellar-sdk' + -const { Api } = SorobanRpc + +import { Api } from '@stellar/stellar-sdk/Rpc' + ``` ## [v12.0.0-rc.2](https://github.com/stellar/js-stellar-sdk/compare/v11.3.0...v12.0.0-rc.2) diff --git a/README.md b/README.md index 6edbabf81..1317425fd 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ The usage documentation for this library lives in a handful of places: You can also refer to: * the [documentation](https://developers.stellar.org/network/horizon) for the Horizon REST API (if using the `Horizon` module) and - * the [documentation](https://soroban.stellar.org/docs/reference/rpc) for Soroban RPC's API (if using the `SorobanRpc` module) + * the [documentation](https://soroban.stellar.org/docs/reference/rpc) for Soroban RPC's API (if using the `Rpc` module) ### Usage with React-Native diff --git a/package.json b/package.json index db33995ba..09229e3aa 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,21 @@ "/lib", "/dist" ], + "exports": { + ".": { + "browser": "./dist/stellar-sdk.min.js", + "types": "./lib/index.d.ts", + "default": "./lib/index.js" + }, + "./ContractClient": { + "types": "./lib/contract_client/index.d.ts", + "default": "./lib/contract_client/index.js" + }, + "./Rpc": { + "types": "./lib/rpc/index.d.ts", + "default": "./lib/rpc/index.js" + } + }, "scripts": { "build": "cross-env NODE_ENV=development yarn _build", "build:prod": "cross-env NODE_ENV=production yarn _build", @@ -164,4 +179,4 @@ ], "timeout": "2m" } -} +} \ No newline at end of file diff --git a/src/soroban/contract_client/assembled_transaction.ts b/src/contract_client/assembled_transaction.ts similarity index 97% rename from src/soroban/contract_client/assembled_transaction.ts rename to src/contract_client/assembled_transaction.ts index a8436fc3d..a7f2c965e 100644 --- a/src/soroban/contract_client/assembled_transaction.ts +++ b/src/contract_client/assembled_transaction.ts @@ -12,15 +12,15 @@ import { } from "@stellar/stellar-base"; import type { AssembledTransactionOptions, - ContractClientOptions, + Options, MethodOptions, Tx, XDR_BASE64, } from "./types"; -import { Server } from "../server"; -import { Api } from "../api"; -import { assembleTransaction } from "../transaction"; -import type { ContractClient } from "./client"; +import { Server } from "../rpc/server"; +import { Api } from "../rpc/api"; +import { assembleTransaction } from "../rpc/transaction"; +import type { Client } from "./client"; import { Err } from "./rust_result"; import { DEFAULT_TIMEOUT, @@ -33,7 +33,7 @@ export const NULL_ACCOUNT = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF"; /** - * The main workhorse of {@link ContractClient}. This class is used to wrap a + * The main workhorse of {@link Client}. This class is used to wrap a * transaction-under-construction and provide high-level interfaces to the most * common workflows, while still providing access to low-level stellar-sdk * transaction manipulation. @@ -70,7 +70,7 @@ export const NULL_ACCOUNT = * ``` * * While that looks pretty complicated, most of the time you will use this in - * conjunction with {@link ContractClient}, which simplifies it to: + * conjunction with {@link Client}, which simplifies it to: * * ```ts * const { result } = await client.myReadMethod({ @@ -94,7 +94,7 @@ export const NULL_ACCOUNT = * const sentTx = await assembledTx.signAndSend() * ``` * - * Here we're assuming that you're using a {@link ContractClient}, rather than + * Here we're assuming that you're using a {@link Client}, rather than * constructing `AssembledTransaction`'s directly. * * Note that `sentTx`, the return value of `signAndSend`, is a @@ -118,7 +118,7 @@ export const NULL_ACCOUNT = * * If you need more control over the transaction before simulating it, you can * set various {@link MethodOptions} when constructing your - * `AssembledTransaction`. With a {@link ContractClient}, this is passed as a + * `AssembledTransaction`. With a {@link Client}, this is passed as a * second object after the arguments (or the only object, if the method takes * no arguments): * @@ -521,7 +521,7 @@ export class AssembledTransaction { /** * TSDoc: You must provide this here if you did not provide one before */ - signTransaction?: ContractClientOptions["signTransaction"]; + signTransaction?: Options["signTransaction"]; } = {}): Promise> => { if (!this.built) { throw new Error("Transaction has not yet been simulated"); @@ -669,7 +669,7 @@ export class AssembledTransaction { * the `signAuthEntry` function from the `ContractClient` options. Must * sign things as the given `publicKey`. */ - signAuthEntry?: ContractClientOptions["signAuthEntry"]; + signAuthEntry?: Options["signAuthEntry"]; } = {}): Promise => { if (!this.built) throw new Error("Transaction has not yet been assembled or simulated"); diff --git a/src/soroban/contract_client/basic_node_signer.ts b/src/contract_client/basic_node_signer.ts similarity index 89% rename from src/soroban/contract_client/basic_node_signer.ts rename to src/contract_client/basic_node_signer.ts index db1834815..9e50327cd 100644 --- a/src/soroban/contract_client/basic_node_signer.ts +++ b/src/contract_client/basic_node_signer.ts @@ -1,9 +1,9 @@ import { Keypair, TransactionBuilder, hash } from "@stellar/stellar-base"; import type { AssembledTransaction } from "./assembled_transaction"; -import type { ContractClient } from "./client"; +import type { Client } from "./client"; /** - * For use with {@link ContractClient} and {@link AssembledTransaction}. + * For use with {@link Client} and {@link AssembledTransaction}. * Implements `signTransaction` and `signAuthEntry` with signatures expected by * those classes. This is useful for testing and maybe some simple Node * applications. Feel free to use this as a starting point for your own diff --git a/src/soroban/contract_client/client.ts b/src/contract_client/client.ts similarity index 80% rename from src/soroban/contract_client/client.ts rename to src/contract_client/client.ts index a90edc5d1..ea4214139 100644 --- a/src/soroban/contract_client/client.ts +++ b/src/contract_client/client.ts @@ -1,9 +1,9 @@ import { xdr } from "@stellar/stellar-base"; -import { ContractSpec } from "../../contract_spec"; +import { Spec } from "./spec"; import { AssembledTransaction } from "./assembled_transaction"; -import type { ContractClientOptions, MethodOptions } from "./types"; +import type { Options, MethodOptions } from "./types"; -export class ContractClient { +export class Client { /** * Generate a class from the contract spec that where each contract method * gets included with an identical name. @@ -13,10 +13,10 @@ export class ContractClient { * transaction. */ constructor( - /** {@link ContractSpec} to construct a Client for */ - public readonly spec: ContractSpec, - /** see {@link ContractClientOptions} */ - public readonly options: ContractClientOptions, + /** {@link Spec} to construct a Client for */ + public readonly spec: Spec, + /** see {@link Options} */ + public readonly options: Options, ) { this.spec.funcs().forEach((xdrFn) => { const method = xdrFn.name().toString(); @@ -34,7 +34,7 @@ export class ContractClient { ...acc, [curr.value()]: { message: curr.doc().toString() }, }), - {} as Pick, + {} as Pick, ), parseResultXdr: (result: xdr.ScVal) => spec.funcResToNative(method, result), diff --git a/src/soroban/contract_client/index.ts b/src/contract_client/index.ts similarity index 88% rename from src/soroban/contract_client/index.ts rename to src/contract_client/index.ts index b9d7498cd..8b9e1dc5e 100644 --- a/src/soroban/contract_client/index.ts +++ b/src/contract_client/index.ts @@ -3,5 +3,5 @@ export * from "./basic_node_signer"; export * from "./client"; export * from "./rust_result"; export * from "./sent_transaction"; +export * from "./spec"; export * from "./types"; -export * from "./utils"; diff --git a/src/soroban/contract_client/rust_result.ts b/src/contract_client/rust_result.ts similarity index 100% rename from src/soroban/contract_client/rust_result.ts rename to src/contract_client/rust_result.ts diff --git a/src/soroban/contract_client/sent_transaction.ts b/src/contract_client/sent_transaction.ts similarity index 96% rename from src/soroban/contract_client/sent_transaction.ts rename to src/contract_client/sent_transaction.ts index f2c3974f3..a4a1c0988 100644 --- a/src/soroban/contract_client/sent_transaction.ts +++ b/src/contract_client/sent_transaction.ts @@ -1,9 +1,9 @@ /* disable max-classes rule, because extending error shouldn't count! */ /* eslint max-classes-per-file: 0 */ import { SorobanDataBuilder, TransactionBuilder } from "@stellar/stellar-base"; -import type { ContractClientOptions, MethodOptions, Tx } from "./types"; -import { Server } from "../server" -import { Api } from "../api" +import type { Options, MethodOptions, Tx } from "./types"; +import { Server } from "../rpc/server" +import { Api } from "../rpc/api" import { DEFAULT_TIMEOUT, withExponentialBackoff } from "./utils"; import type { AssembledTransaction } from "./assembled_transaction"; @@ -53,7 +53,7 @@ export class SentTransaction { }; constructor( - public signTransaction: ContractClientOptions["signTransaction"], + public signTransaction: Options["signTransaction"], public assembled: AssembledTransaction, ) { if (!signTransaction) { @@ -73,7 +73,7 @@ export class SentTransaction { */ static init = async ( /** More info in {@link MethodOptions} */ - signTransaction: ContractClientOptions["signTransaction"], + signTransaction: Options["signTransaction"], /** {@link AssembledTransaction} from which this SentTransaction was initialized */ assembled: AssembledTransaction, ): Promise> => { diff --git a/src/contract_spec.ts b/src/contract_client/spec.ts similarity index 99% rename from src/contract_spec.ts rename to src/contract_client/spec.ts index dc80f9a1d..937875fbb 100644 --- a/src/contract_spec.ts +++ b/src/contract_client/spec.ts @@ -7,7 +7,7 @@ import { Contract, scValToBigInt, } from "@stellar/stellar-base" -import { Ok } from "./soroban/contract_client/rust_result" +import { Ok } from "./rust_result" export interface Union { tag: string; @@ -48,7 +48,7 @@ function readObj(args: object, input: xdr.ScSpecFunctionInputV0): any { * console.log(result); // {success: true} * ``` */ -export class ContractSpec { +export class Spec { public entries: xdr.ScSpecEntry[] = []; /** diff --git a/src/soroban/contract_client/types.ts b/src/contract_client/types.ts similarity index 94% rename from src/soroban/contract_client/types.ts rename to src/contract_client/types.ts index 70c8b3b47..740ebd7d8 100644 --- a/src/soroban/contract_client/types.ts +++ b/src/contract_client/types.ts @@ -1,7 +1,7 @@ /* disable PascalCase naming convention, to avoid breaking change */ /* eslint-disable @typescript-eslint/naming-convention */ import { BASE_FEE, Memo, MemoType, Operation, Transaction, xdr } from "@stellar/stellar-base"; -import type { ContractClient } from "./client"; +import type { Client } from "./client"; import type { AssembledTransaction } from "./assembled_transaction"; import { DEFAULT_TIMEOUT } from "./utils"; @@ -23,7 +23,7 @@ export type Duration = bigint; */ export type Tx = Transaction, Operation[]>; -export type ContractClientOptions = { +export type Options = { /** * The public key of the account that will send this transaction. You can * override this for specific methods later, like @@ -74,14 +74,14 @@ export type ContractClientOptions = { allowHttp?: boolean; /** * This gets filled in automatically from the ContractSpec when you - * instantiate a {@link ContractClient}. + * instantiate a {@link Client}. * * Background: If the contract you're calling uses the `#[contracterror]` * macro to create an `Error` enum, then those errors get included in the * on-chain XDR that also describes your contract's methods. Each error will * have a specific number. * - * A ContractClient makes method calls with an {@link AssembledTransaction}. + * A Client makes method calls with an {@link AssembledTransaction}. * When one of these method calls encounters an error, `AssembledTransaction` * will first attempt to parse the error as an "official" `contracterror` * error, by using this passed-in `errorTypes` object. See @@ -112,7 +112,7 @@ export type MethodOptions = { }; export type AssembledTransactionOptions = MethodOptions & - ContractClientOptions & { + Options & { method: string; args?: any[]; parseResultXdr: (xdr: xdr.ScVal) => T; diff --git a/src/soroban/contract_client/utils.ts b/src/contract_client/utils.ts similarity index 100% rename from src/soroban/contract_client/utils.ts rename to src/contract_client/utils.ts diff --git a/src/index.ts b/src/index.ts index ec315bd0c..d2dc299ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,8 +17,11 @@ export * as Friendbot from './friendbot'; export * as Horizon from './horizon'; // Soroban RPC-related classes to expose -export * as SorobanRpc from './soroban'; -export * from './contract_spec'; +export * as Rpc from './rpc'; +export * as SorobanRpc from './rpc'; + +// Soroban Contract-related classes to expose +export * as ContractClient from './contract_client' // expose classes and functions from stellar-base export * from '@stellar/stellar-base'; diff --git a/src/soroban/api.ts b/src/rpc/api.ts similarity index 100% rename from src/soroban/api.ts rename to src/rpc/api.ts diff --git a/src/soroban/axios.ts b/src/rpc/axios.ts similarity index 100% rename from src/soroban/axios.ts rename to src/rpc/axios.ts diff --git a/src/soroban/browser.ts b/src/rpc/browser.ts similarity index 100% rename from src/soroban/browser.ts rename to src/rpc/browser.ts diff --git a/src/soroban/index.ts b/src/rpc/index.ts similarity index 88% rename from src/soroban/index.ts rename to src/rpc/index.ts index 45702b70d..99ee2ba2a 100644 --- a/src/soroban/index.ts +++ b/src/rpc/index.ts @@ -9,6 +9,5 @@ export { Server, Durability } from "./server"; export { default as AxiosClient } from "./axios"; export { parseRawSimulation, parseRawEvents } from "./parsers"; export * from "./transaction"; -export * as ContractClient from "./contract_client"; export default module.exports; diff --git a/src/soroban/jsonrpc.ts b/src/rpc/jsonrpc.ts similarity index 100% rename from src/soroban/jsonrpc.ts rename to src/rpc/jsonrpc.ts diff --git a/src/soroban/parsers.ts b/src/rpc/parsers.ts similarity index 100% rename from src/soroban/parsers.ts rename to src/rpc/parsers.ts diff --git a/src/soroban/server.ts b/src/rpc/server.ts similarity index 100% rename from src/soroban/server.ts rename to src/rpc/server.ts diff --git a/src/soroban/transaction.ts b/src/rpc/transaction.ts similarity index 100% rename from src/soroban/transaction.ts rename to src/rpc/transaction.ts diff --git a/src/soroban/utils.ts b/src/rpc/utils.ts similarity index 100% rename from src/soroban/utils.ts rename to src/rpc/utils.ts diff --git a/test/e2e/src/test-custom-types.js b/test/e2e/src/test-custom-types.js index 88ccdc703..ab3f96f53 100644 --- a/test/e2e/src/test-custom-types.js +++ b/test/e2e/src/test-custom-types.js @@ -1,9 +1,7 @@ const test = require('ava') -const { Address, SorobanRpc } = require('../../..') +const { Address, ContractClient } = require('../../..') const { clientFor } = require('./util') -const { Ok, Err } = SorobanRpc.ContractClient - test.before(async t => { const { client, keypair, contractId } = await clientFor('customTypes') const publicKey = keypair.publicKey() @@ -31,11 +29,11 @@ test('woid', async t => { test('u32_fail_on_even', async t => { t.deepEqual( (await t.context.client.u32_fail_on_even({ u32_: 1 })).result, - new Ok(1) + new ContractClient.Ok(1) ) t.deepEqual( (await t.context.client.u32_fail_on_even({ u32_: 2 })).result, - new Err({ message: "Please provide an odd number" }) + new ContractClient.Err({ message: "Please provide an odd number" }) ) }) diff --git a/test/e2e/src/test-swap.js b/test/e2e/src/test-swap.js index d36f698f5..9da03cb46 100644 --- a/test/e2e/src/test-swap.js +++ b/test/e2e/src/test-swap.js @@ -1,9 +1,7 @@ const test = require('ava') -const { SorobanRpc } = require('../../..') +const { ContractClient } = require('../../..') const { clientFor, generateFundedKeypair } = require('./util') -const { AssembledTransaction } = SorobanRpc.ContractClient - const amountAToSwap = 2n const amountBToSwap = 1n @@ -53,7 +51,7 @@ test('calling `signAndSend()` too soon throws descriptive error', async t => { min_b_for_a: amountBToSwap, }) const error = await t.throwsAsync(tx.signAndSend()) - t.true(error instanceof AssembledTransaction.Errors.NeedsMoreSignatures, `error is not of type 'NeedsMoreSignaturesError'; instead it is of type '${error?.constructor.name}'`) + t.true(error instanceof ContractClient.AssembledTransaction.Errors.NeedsMoreSignatures, `error is not of type 'NeedsMoreSignaturesError'; instead it is of type '${error?.constructor.name}'`) if (error) t.regex(error.message, /needsNonInvokerSigningBy/) }) @@ -112,7 +110,7 @@ test('alice swaps bob 10 A for 1 B', async t => { ) t.is( result.getTransactionResponse.status, - SorobanRpc.Api.GetTransactionStatus.SUCCESS, + Rpc.Api.GetTransactionStatus.SUCCESS, `tx failed: ${JSON.stringify(result.getTransactionResponse, null, 2)}` ) diff --git a/test/e2e/src/util.js b/test/e2e/src/util.js index a7d1e731c..764d5f064 100644 --- a/test/e2e/src/util.js +++ b/test/e2e/src/util.js @@ -1,9 +1,5 @@ const { spawnSync } = require('node:child_process') -const { ContractSpec, Keypair, SorobanRpc } = require('../../..') -const { - ContractClient, - basicNodeSigner, -} = SorobanRpc.ContractClient +const { ContractClient, Keypair } = require('../../..') const contracts = { customTypes: { @@ -40,7 +36,7 @@ async function generateFundedKeypair() { module.exports.generateFundedKeypair = generateFundedKeypair /** - * Generates a ContractClient for the contract with the given name. + * Generates a Contrat.Client for the contract with the given name. * Also generates a new account to use as as the keypair of this contract. This * account is funded by friendbot. You can pass in an account to re-use the * same account with multiple contract clients. @@ -57,9 +53,9 @@ async function clientFor(contract, { keypair = generateFundedKeypair(), contract } keypair = await keypair // eslint-disable-line no-param-reassign - const wallet = basicNodeSigner(keypair, networkPassphrase) + const wallet = ContractClient.basicNodeSigner(keypair, networkPassphrase) - const spec = new ContractSpec(contracts[contract].xdr) + const spec = new ContractClient.Spec(contracts[contract].xdr) const wasmHash = contracts[contract].hash; if (!wasmHash) { @@ -76,7 +72,7 @@ async function clientFor(contract, { keypair = generateFundedKeypair(), contract wasmHash, ], { shell: true, encoding: "utf8" }).stdout.trim(); - const client = new ContractClient(spec, { + const client = new ContractClient.Client(spec, { networkPassphrase, contractId, rpcUrl, diff --git a/test/unit/server/soroban/constructor_test.js b/test/unit/server/soroban/constructor_test.js index 82c4465e1..34f37893a 100644 --- a/test/unit/server/soroban/constructor_test.js +++ b/test/unit/server/soroban/constructor_test.js @@ -1,4 +1,4 @@ -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server.constructor", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_account_test.js b/test/unit/server/soroban/get_account_test.js index b6781f76c..5b72843d8 100644 --- a/test/unit/server/soroban/get_account_test.js +++ b/test/unit/server/soroban/get_account_test.js @@ -1,5 +1,5 @@ const { Account, Keypair, StrKey, hash, xdr } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getAccount", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_contract_data_test.js b/test/unit/server/soroban/get_contract_data_test.js index 1fb004a61..b05804b1c 100644 --- a/test/unit/server/soroban/get_contract_data_test.js +++ b/test/unit/server/soroban/get_contract_data_test.js @@ -1,5 +1,5 @@ const { Address, xdr, nativeToScVal, hash } = StellarSdk; -const { Server, AxiosClient, Durability } = StellarSdk.SorobanRpc; +const { Server, AxiosClient, Durability } = StellarSdk.Rpc; describe("Server#getContractData", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_events_test.js b/test/unit/server/soroban/get_events_test.js index 8b3f4f8e7..b1f2dc6dd 100644 --- a/test/unit/server/soroban/get_events_test.js +++ b/test/unit/server/soroban/get_events_test.js @@ -1,5 +1,5 @@ -const { nativeToScVal, SorobanRpc } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { nativeToScVal, Rpc } = StellarSdk; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getEvents", function () { beforeEach(function () { @@ -225,7 +225,7 @@ function setupMock(axiosMock, params, result) { } function parseEvents(result) { - return SorobanRpc.parseRawEvents(result); + return Rpc.parseRawEvents(result); } const contractId = "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE"; diff --git a/test/unit/server/soroban/get_health_test.js b/test/unit/server/soroban/get_health_test.js index 917a945f6..a2054f480 100644 --- a/test/unit/server/soroban/get_health_test.js +++ b/test/unit/server/soroban/get_health_test.js @@ -1,4 +1,4 @@ -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getHealth", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_latest_ledger_test.js b/test/unit/server/soroban/get_latest_ledger_test.js index 6aa048033..7c3749a97 100644 --- a/test/unit/server/soroban/get_latest_ledger_test.js +++ b/test/unit/server/soroban/get_latest_ledger_test.js @@ -1,4 +1,4 @@ -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getLatestLedger", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_ledger_entries_test.js b/test/unit/server/soroban/get_ledger_entries_test.js index cf11dc5f3..fd540e831 100644 --- a/test/unit/server/soroban/get_ledger_entries_test.js +++ b/test/unit/server/soroban/get_ledger_entries_test.js @@ -1,5 +1,5 @@ const { xdr, nativeToScVal, Durability, hash } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getLedgerEntries", function () { const address = "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5"; diff --git a/test/unit/server/soroban/get_network_test.js b/test/unit/server/soroban/get_network_test.js index a5b4e05a7..771432d13 100644 --- a/test/unit/server/soroban/get_network_test.js +++ b/test/unit/server/soroban/get_network_test.js @@ -1,4 +1,4 @@ -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getNetwork", function () { beforeEach(function () { diff --git a/test/unit/server/soroban/get_transaction_test.js b/test/unit/server/soroban/get_transaction_test.js index a63b7aa21..a7a6caae6 100644 --- a/test/unit/server/soroban/get_transaction_test.js +++ b/test/unit/server/soroban/get_transaction_test.js @@ -6,7 +6,7 @@ const { nativeToScVal, XdrLargeInt, } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#getTransaction", function () { let keypair = Keypair.random(); diff --git a/test/unit/server/soroban/request_airdrop_test.js b/test/unit/server/soroban/request_airdrop_test.js index 74e0c6486..fa9a787cb 100644 --- a/test/unit/server/soroban/request_airdrop_test.js +++ b/test/unit/server/soroban/request_airdrop_test.js @@ -1,5 +1,5 @@ const { Account, Keypair, StrKey, Networks, xdr, hash } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#requestAirdrop", function () { function accountLedgerEntryData(accountId, sequence) { diff --git a/test/unit/server/soroban/send_transaction_test.js b/test/unit/server/soroban/send_transaction_test.js index be235e8bb..e628548d9 100644 --- a/test/unit/server/soroban/send_transaction_test.js +++ b/test/unit/server/soroban/send_transaction_test.js @@ -1,5 +1,5 @@ const { xdr } = StellarSdk; -const { Server, AxiosClient } = StellarSdk.SorobanRpc; +const { Server, AxiosClient } = StellarSdk.Rpc; describe("Server#sendTransaction", function () { let keypair = StellarSdk.Keypair.random(); diff --git a/test/unit/server/soroban/simulate_transaction_test.js b/test/unit/server/soroban/simulate_transaction_test.js index f1c2bacbc..f1d0c73a6 100644 --- a/test/unit/server/soroban/simulate_transaction_test.js +++ b/test/unit/server/soroban/simulate_transaction_test.js @@ -2,13 +2,13 @@ const { Account, Keypair, Networks, - SorobanRpc, + Rpc, SorobanDataBuilder, authorizeInvocation, authorizeEntry, xdr, } = StellarSdk; -const { Server, AxiosClient, parseRawSimulation } = StellarSdk.SorobanRpc; +const { Server, AxiosClient, parseRawSimulation } = StellarSdk.Rpc; const randomSecret = Keypair.random().secret(); @@ -134,7 +134,7 @@ describe("Server#simulateTransaction", async function (done) { const parsed = parseRawSimulation(simResponse); expect(parsed).to.deep.equal(parsedCopy); - expect(SorobanRpc.Api.isSimulationSuccess(parsed)).to.be.true; + expect(Rpc.Api.isSimulationSuccess(parsed)).to.be.true; }); it("works with no auth", async function () { @@ -146,7 +146,7 @@ describe("Server#simulateTransaction", async function (done) { const parsed = parseRawSimulation(simResponse); expect(parsed).to.be.deep.equal(parsedCopy); - expect(SorobanRpc.Api.isSimulationSuccess(parsed)).to.be.true; + expect(Rpc.Api.isSimulationSuccess(parsed)).to.be.true; }); }); @@ -160,7 +160,7 @@ describe("Server#simulateTransaction", async function (done) { }; const parsed = parseRawSimulation(simResponse); - expect(SorobanRpc.Api.isSimulationRestore(parsed)).to.be.true; + expect(Rpc.Api.isSimulationRestore(parsed)).to.be.true; expect(parsed).to.be.deep.equal(expected); }, ); @@ -180,7 +180,7 @@ describe("Server#simulateTransaction", async function (done) { const parsed = parseRawSimulation(simResponse); expect(parsed).to.be.deep.equal(expected); - expect(SorobanRpc.Api.isSimulationError(parsed)).to.be.true; + expect(Rpc.Api.isSimulationError(parsed)).to.be.true; }); xit("simulates fee bump transactions"); @@ -302,7 +302,7 @@ describe("works with real responses", function () { }; it("parses the schema", function () { - expect(SorobanRpc.Api.isSimulationRaw(schema)).to.be.true; + expect(Rpc.Api.isSimulationRaw(schema)).to.be.true; const parsed = parseRawSimulation(schema); diff --git a/test/unit/spec/contract_spec.ts b/test/unit/spec/contract_spec.ts index 861a7c968..c81b6cf6e 100644 --- a/test/unit/spec/contract_spec.ts +++ b/test/unit/spec/contract_spec.ts @@ -1,4 +1,4 @@ -import { xdr, Address, ContractSpec, Keypair } from "../../../lib"; +import { xdr, Address, ContractClient, Keypair } from "../../.."; import { JSONSchemaFaker } from "json-schema-faker"; import spec from "../spec.json"; @@ -6,7 +6,7 @@ import { expect } from "chai"; const publicKey = "GCBVOLOM32I7OD5TWZQCIXCXML3TK56MDY7ZMTAILIBQHHKPCVU42XYW"; const addr = Address.fromString(publicKey); -let SPEC: ContractSpec; +let SPEC: ContractClient.Spec; JSONSchemaFaker.format("address", () => { let keypair = Keypair.random(); @@ -14,12 +14,12 @@ JSONSchemaFaker.format("address", () => { }); before(() => { - SPEC = new ContractSpec(spec); + SPEC = new ContractClient.Spec(spec); }); it("throws if no entries", () => { - expect(() => new ContractSpec([])).to.throw( - /Contract spec must have at least one entry/i + expect(() => new ContractClient.Spec([])).to.throw( + /ContractClient spec must have at least one entry/i ); }); @@ -36,7 +36,7 @@ describe("Can round trip custom types", function () { } async function jsonSchema_roundtrip( - spec: ContractSpec, + spec: ContractClient.Spec, funcName: string, num: number = 100 ) { @@ -70,7 +70,7 @@ describe("Can round trip custom types", function () { } describe("Json Schema", () => { - SPEC = new ContractSpec(spec); + SPEC = new ContractClient.Spec(spec); let names = SPEC.funcs().map((f) => f.name().toString()); const banned = ["strukt_hel", "not", "woid", "val", "multi_args"]; names @@ -259,7 +259,7 @@ describe.skip("Print contract spec", function () { describe("parsing and building ScVals", function () { it("Can parse entries", function () { - let spec = new ContractSpec([GIGA_MAP, func]); + let spec = new ContractClient.Spec([GIGA_MAP, func]); let fn = spec.findEntry("giga_map"); let gigaMap = spec.findEntry("GigaMap"); expect(gigaMap).deep.equal(GIGA_MAP); diff --git a/test/unit/transaction_test.js b/test/unit/transaction_test.js index d5a1b3633..8054f9cf7 100644 --- a/test/unit/transaction_test.js +++ b/test/unit/transaction_test.js @@ -1,4 +1,4 @@ -const { xdr, SorobanRpc } = StellarSdk; +const { xdr, Rpc } = StellarSdk; describe("assembleTransaction", () => { xit("works with keybump transactions"); @@ -80,7 +80,7 @@ describe("assembleTransaction", () => { it("simulate updates the tx data from simulation response", () => { const txn = singleContractFnTransaction(); - const result = SorobanRpc.assembleTransaction( + const result = Rpc.assembleTransaction( txn, simulationResponse, ).build(); @@ -97,7 +97,7 @@ describe("assembleTransaction", () => { it("simulate adds the auth to the host function in tx operation", () => { const txn = singleContractFnTransaction(); - const result = SorobanRpc.assembleTransaction( + const result = Rpc.assembleTransaction( txn, simulationResponse, ).build(); @@ -141,7 +141,7 @@ describe("assembleTransaction", () => { const txn = singleContractFnTransaction(); let simulateResp = JSON.parse(JSON.stringify(simulationResponse)); simulateResp.results[0].auth = null; - const result = SorobanRpc.assembleTransaction(txn, simulateResp).build(); + const result = Rpc.assembleTransaction(txn, simulateResp).build(); expect( result @@ -170,7 +170,7 @@ describe("assembleTransaction", () => { .build(); expect(() => { - SorobanRpc.assembleTransaction(txn, { + Rpc.assembleTransaction(txn, { transactionData: {}, events: [], minResourceFee: "0", @@ -198,7 +198,7 @@ describe("assembleTransaction", () => { .addOperation(op) .build(); - const tx = SorobanRpc.assembleTransaction( + const tx = Rpc.assembleTransaction( txn, simulationResponse, ).build(); @@ -208,7 +208,7 @@ describe("assembleTransaction", () => { it("doesn't overwrite auth if it's present", function () { const txn = singleContractFnTransaction([fnAuth, fnAuth, fnAuth]); - const tx = SorobanRpc.assembleTransaction( + const tx = Rpc.assembleTransaction( txn, simulationResponse, ).build();