Skip to content

Commit

Permalink
Run yarn fmt and disable eslint complaince when publishing (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored May 15, 2024
1 parent 1743c9b commit 1b6d7aa
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 387 deletions.
22 changes: 10 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,21 @@ import {
+} from '@stellar/stellar-sdk/contract'
```

- The `ContractSpec` class is now nested under the `contract` module, and has been renamed to `Spec`.
- The `ContractSpec` class is now nested under the `contract` module, and has been **renamed** to `Spec` ([#962](https://github.com/stellar/js-stellar-sdk/pull/962)). Alternatively, you can import this from the `contract` entrypoint, if your version of Node [and TypeScript](https://stackoverflow.com/a/70020984/249801) support [the `exports` declaration](https://nodejs.org/api/packages.html#exports):

```diff
-import { ContractSpec } from '@stellar/stellar-sdk'
+import { contract } from '@stellar/stellar-sdk'
+const { Spec } = contract
```

Alternatively, you can import this from the `contract` entrypoint, if your version of Node [and TypeScript](https://stackoverflow.com/a/70020984/249801) support [the `exports` declaration](https://nodejs.org/api/packages.html#exports).

```diff
-import { ContractSpec } from '@stellar/stellar-sdk'
// OR
+import { Spec } from '@stellar/stellar-sdk/contract'
```

- Previously, `AssembledTransaction.signAndSend()` would return a `SentTransaction` even if the transaction never finalized. That is, if it successfully sent the transaction to the network, but the transaction was still `status: 'PENDING'`, then it would `console.error` an error message, but return the indeterminate transaction anyhow. **It now throws** a `SentTransaction.Errors.TransactionStillPending` error with that error message instead ([#962](https://github.com/stellar/js-stellar-sdk/pull/962)).

### Deprecated

- `SorobanRpc` module is now also exported as `rpc`. You can import it with either name for now, but `SorobanRpc` will be removed in a future release:
- `SorobanRpc` module is now also exported as `rpc` ([#962](https://github.com/stellar/js-stellar-sdk/pull/962)). You can import it with either name for now, but `SorobanRpc` will be removed in a future release:

```diff
-import { SorobanRpc } from '@stellar/stellar-sdk'
Expand All @@ -70,12 +65,15 @@ import {
```

### Added
* New methods on `ContractClient` ([#960](https://github.com/stellar/js-stellar-sdk/pull/960)):
- `from(opts: ContractClientOptions)` instantiates the `ContractClient` by fetching the `contractId`'s WASM from the network to fill out the client's `ContractSpec`.
- `fromWasm` and `fromWasmHash` methods to instantiate a `ContractClient` when you already have the WASM bytes or hash alongside the `ContractClientOptions`.
* New methods on `SorobanRpc.Server` ([#960](https://github.com/stellar/js-stellar-sdk/pull/960)):
* New methods on `contract.Client` ([#960](https://github.com/stellar/js-stellar-sdk/pull/960)):
- `from(opts: ContractClientOptions)` instantiates `contract.Client` by fetching the `contractId`'s WASM from the network to fill out the client's `ContractSpec`.
- `fromWasm` and `fromWasmHash` methods to instantiate a `contract.Client` when you already have the WASM bytes or hash alongside the `contract.ClientOptions`.
* New methods on `rpc.Server` ([#960](https://github.com/stellar/js-stellar-sdk/pull/960)):
- `getContractWasmByContractId` and `getContractWasmByHash` to retrieve a contract's WASM bytecode via its `contractId` or `wasmHash`, respectively.

### Fixed
* The breaking changes above (strictly speaking, they are not breaking changes because importing from the inner guts of the SDK is not supported) enable the `contract` module to be used in non-Node environments.


## [v12.0.0-rc.2](https://github.com/stellar/js-stellar-sdk/compare/v11.3.0...v12.0.0-rc.2)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"test:integration": "yarn _nyc mocha --recursive 'test/integration/**/*.js'",
"test:browser": "karma start config/karma.conf.js",
"fmt": "yarn eslint -c .eslintrc.js src/ --fix && yarn _prettier",
"preversion": "yarn clean && yarn fmt && yarn build:prod && yarn test",
"preversion": "yarn clean && yarn _prettier && yarn build:prod && yarn test",
"prepare": "yarn build:prod",
"_build": "yarn build:node && yarn build:test && yarn build:browser",
"_babel": "babel --extensions '.ts' --out-dir lib/ src/",
Expand Down
107 changes: 70 additions & 37 deletions test/e2e/src/test-contract-client-constructor.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const test = require('ava')
const { spawnSync } = require('node:child_process')
const { contracts, networkPassphrase, rpcUrl, friendbotUrl } = require('./util')
const { Address, contract, Keypair } = require('../../..')
const test = require("ava");
const { spawnSync } = require("node:child_process");
const {
contracts,
networkPassphrase,
rpcUrl,
friendbotUrl,
} = require("./util");
const { Address, contract, Keypair } = require("../../..");

async function generateFundedKeypair() {
const keypair = Keypair.random()
await fetch(`${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`)
return keypair
};
const keypair = Keypair.random();
await fetch(`${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`);
return keypair;
}

/**
* Generates a Client for the contract with the given name.
Expand All @@ -18,34 +23,54 @@ async function generateFundedKeypair() {
* By default, will re-deploy the contract every time. Pass in the same
* `contractId` again if you want to re-use the a contract instance.
*/
async function clientFromConstructor(name, { keypair = generateFundedKeypair(), contractId } = {}) {
async function clientFromConstructor(
name,
{ keypair = generateFundedKeypair(), contractId } = {},
) {
if (!contracts[name]) {
throw new Error(
`Contract ${name} not found. ` +
`Pick one of: ${Object.keys(contracts).join(", ")}`
)
`Pick one of: ${Object.keys(contracts).join(", ")}`,
);
}
keypair = await keypair // eslint-disable-line no-param-reassign
const wallet = contract.basicNodeSigner(keypair, networkPassphrase)
keypair = await keypair; // eslint-disable-line no-param-reassign
const wallet = contract.basicNodeSigner(keypair, networkPassphrase);

const {path} = contracts[name];
const xdr = JSON.parse(spawnSync("./target/bin/soroban", ["contract", "inspect", "--wasm", path, "--output", "xdr-base64-array"], { shell: true, encoding: "utf8" }).stdout.trim())
const { path } = contracts[name];
const xdr = JSON.parse(
spawnSync(
"./target/bin/soroban",
["contract", "inspect", "--wasm", path, "--output", "xdr-base64-array"],
{ shell: true, encoding: "utf8" },
).stdout.trim(),
);

const spec = new contract.Spec(xdr);
let wasmHash = contracts[name].hash;
if (!wasmHash) {
wasmHash = spawnSync("./target/bin/soroban", ["contract", "install", "--wasm", path], { shell: true, encoding: "utf8" }).stdout.trim()
wasmHash = spawnSync(
"./target/bin/soroban",
["contract", "install", "--wasm", path],
{ shell: true, encoding: "utf8" },
).stdout.trim();
}

// TODO: do this with js-stellar-sdk, instead of shelling out to the CLI
contractId = contractId ?? spawnSync("./target/bin/soroban", [ // eslint-disable-line no-param-reassign
"contract",
"deploy",
"--source",
keypair.secret(),
"--wasm-hash",
wasmHash,
], { shell: true, encoding: "utf8" }).stdout.trim();
contractId =
contractId ??
spawnSync(
"./target/bin/soroban",
[
// eslint-disable-line no-param-reassign
"contract",
"deploy",
"--source",
keypair.secret(),
"--wasm-hash",
wasmHash,
],
{ shell: true, encoding: "utf8" },
).stdout.trim();

const client = new contract.Client(spec, {
networkPassphrase,
Expand All @@ -59,7 +84,7 @@ async function clientFromConstructor(name, { keypair = generateFundedKeypair(),
keypair,
client,
contractId,
}
};
}

/**
Expand All @@ -79,25 +104,33 @@ async function clientForFromTest(contractId, publicKey, keypair) {
return contract.Client.from(options);
}

test.before(async t => {
const { client, keypair, contractId } = await clientFromConstructor('customTypes')
const publicKey = keypair.publicKey()
const addr = Address.fromString(publicKey)
t.context = { client, publicKey, addr, contractId, keypair } // eslint-disable-line no-param-reassign
test.before(async (t) => {
const { client, keypair, contractId } =
await clientFromConstructor("customTypes");
const publicKey = keypair.publicKey();
const addr = Address.fromString(publicKey);
t.context = { client, publicKey, addr, contractId, keypair }; // eslint-disable-line no-param-reassign
});

test('hello from constructor', async t => {
const { result } = await t.context.client.hello({ hello: 'tests' })
t.is(result, 'tests')
})
test("hello from constructor", async (t) => {
const { result } = await t.context.client.hello({ hello: "tests" });
t.is(result, "tests");
});

test('from', async (t) => {
test("from", async (t) => {
// objects with different constructors will not pass deepEqual check
function constructorWorkaround(object) {
return JSON.parse(JSON.stringify(object));
}

const clientFromFrom = await clientForFromTest(t.context.contractId, t.context.publicKey, t.context.keypair);
t.deepEqual(constructorWorkaround(clientFromFrom), constructorWorkaround(t.context.client));
const clientFromFrom = await clientForFromTest(
t.context.contractId,
t.context.publicKey,
t.context.keypair,
);
t.deepEqual(
constructorWorkaround(clientFromFrom),
constructorWorkaround(t.context.client),
);
t.deepEqual(t.context.client.spec.entries, clientFromFrom.spec.entries);
});
Loading

0 comments on commit 1b6d7aa

Please sign in to comment.