Skip to content

Commit

Permalink
ci(changesets): versioning packages (#719)
Browse files Browse the repository at this point in the history
* ci(scripts): update docs

* ci(changesets): versioning packages

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and github-actions[bot] authored Jan 6, 2023
1 parent 217f981 commit 5bad2d0
Show file tree
Hide file tree
Showing 72 changed files with 688 additions and 66 deletions.
5 changes: 0 additions & 5 deletions .changeset/gorgeous-trains-glow.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sixty-bugs-ring.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tiny-mayflies-guess.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/_data/versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated-file
fuels: 0.28.0
fuels: 0.28.1
fuel-core: 0.15.1
sway: 0.32.2
forc: 0.32.2
8 changes: 8 additions & 0 deletions docs/guide/local-docs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
title: "Local Docs"
has_children: false
has_toc: false
nav_order: -3
---

[info]: this file is autogenerated
There are two parts to the fuels-ts repository documentation

## Part One: Typedoc
Expand Down
48 changes: 45 additions & 3 deletions docs/guide/providers/connecting-to-an-external-node.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
[nav_order: 2]
---
title: "Connecting To An External Node"
parent: "Providers"
grand_parent: "Guide"
nav_order: 2
---

[info]: this file is autogenerated


# Connecting to the Testnet or an external node

We can interact with the `Testnet` node by using the following example.

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:provider-testnet)

```typescript
import { Provider, WalletUnlocked } from 'fuels';
const provider = new Provider('node-beta-2.fuel.network');
// Setup a private key
const PRIVATE_KEY = 'a1447cd75accc6b71a976fd3401a1f6ce318d27ba660b0315ee6ac347bf39568';

// Create the wallet, passing provider
const wallet: WalletUnlocked = Wallet.fromPrivateKey(PRIVATE_KEY, provider);

const signer = new Signer(PRIVATE_KEY);
// validate address
expect(wallet.address).toEqual(signer.address);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L243-L257)

---


In the code example, we connected a new provider to the Testnet node and created a new wallet from a private key.

Expand All @@ -20,4 +45,21 @@ In the code example, we connected a new provider to the Testnet node and created
If you want to connect to another node just change the url or IP and port. For example, to connect to a local node that was created with `fuel-core` you can use:

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:provider-local)

```typescript
import { Provider, WalletUnlocked } from 'fuels';
const localProvider = new Provider('http://127.0.0.1:4000/graphql');
// Setup a private key
const PRIVATE_KEY = 'a1447cd75accc6b71a976fd3401a1f6ce318d27ba660b0315ee6ac347bf39568';

// Create the wallet, passing provider
const wallet: WalletUnlocked = Wallet.fromPrivateKey(PRIVATE_KEY, localProvider);

const signer = new Signer(PRIVATE_KEY);
// validate address
expect(wallet.address).toEqual(signer.address);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L261-L273)

---

10 changes: 9 additions & 1 deletion docs/guide/providers/connection.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[nav_order: 1]
---
title: "Connection"
parent: "Providers"
grand_parent: "Guide"
nav_order: 1
---

[info]: this file is autogenerated


# Connecting to a Fuel node

Expand Down
11 changes: 10 additions & 1 deletion docs/guide/providers/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[nav_order: 3]
---
title: "Providers"
parent: "Guide"
has_children: true
has_toc: false
nav_order: 3
---

[info]: this file is autogenerated


# Providers

Expand Down
77 changes: 73 additions & 4 deletions docs/guide/providers/querying-the-chain.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[nav_order: 3]
---
title: "Querying The Chain"
parent: "Providers"
grand_parent: "Guide"
nav_order: 3
---

[info]: this file is autogenerated


# Interacting with the blockchain

Expand All @@ -20,16 +28,77 @@ See [connecting](./connecting.md)

This method returns all coins (of an optional given asset ID) from a wallet, including spent ones.

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:wallet-query)

```typescript
import { Provider, TestUtils } from 'fuels';
const provider = new Provider('http://127.0.0.1:4000/graphql');
const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101';

const wallet = await TestUtils.generateTestWallet(provider, [
[42, NativeAssetId],
[100, assetIdA],
]);

// get single coin
const coin = await wallet.getCoins(NativeAssetId);

// get all coins
const coins = await wallet.getCoins();

expect(coin.length).toEqual(1);
expect(coin).toEqual([
expect.objectContaining({
assetId: NativeAssetId,
amount: bn(42),
}),
]);
expect(coins).toEqual([
expect.objectContaining({
assetId: NativeAssetId,
amount: bn(42),
}),
expect.objectContaining({
assetId: assetIdA,
amount: bn(100),
}),
]);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L277-L310)

---


## Get spendable resources from an address

The last argument says how much you want to spend. This method returns only spendable, i.e., unspent coins (of a given asset ID). If you ask for more spendable than the amount of unspent coins you have, it returns an error.

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:wallet-get-spendable-resources)

```typescript
const spendableResources = await wallet.getResourcesToSpend([
{ amount: 32, assetId: NativeAssetId, max: 42 },
{ amount: 50, assetId: assetIdA },
]);
expect(spendableResources[0].amount).toEqual(bn(42));
expect(spendableResources[1].amount).toEqual(bn(100));
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L320-L327)

---


## Get balances from an address

Get all the spendable balances of all assets for an address. This is different from getting the coins because we only return the numbers (the sum of UTXOs coins amount for each asset id) and not the UTXOs coins themselves.

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:wallet-get-balances)

```typescript
const walletBalances = await wallet.getBalances();
expect(walletBalances).toEqual([
{ assetId: NativeAssetId, amount: bn(42) },
{ assetId: assetIdA, amount: bn(100) },
]);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L312-L318)

---

11 changes: 10 additions & 1 deletion docs/guide/testing/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[nav_order: 7]
---
title: "Testing"
parent: "Guide"
has_children: true
has_toc: false
nav_order: 7
---

[info]: this file is autogenerated


# Testing

Expand Down
62 changes: 60 additions & 2 deletions docs/guide/testing/testing-with-jest.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
---
title: "Testing With Jest"
parent: "Testing"
grand_parent: "Guide"
---

[info]: this file is autogenerated
# Testing with Jest

As noted in [the testing intro](./index.md), you are free to test your Sway and TS-SDK code with any JS framework available. Below we have an example of how to load and test a contract using Jest, but the general principles and steps are the same for any testing harness.

Here is a simple Sway program that takes an input and then returns it:
[@code:rust](./packages/example-contract/src/main.sw#typedoc:Testing-with-jest-contract)

```rust
contract;

abi ExampleContract {
fn return_input(input: u64) -> u64;
}

impl ExampleContract for Contract {
fn return_input(input: u64) -> u64 {
input
}
}
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/example-contract/src/main.sw#L1-L13)

---


Here is JavaScript code testing the above program using a conventional Jest setup:
[@code:typescript](./packages/example-contract/src/example-contract.test.ts#typedoc:Testing-with-jest)

```typescript
import fs from 'fs';
import { ContractFactory, NativeAssetId, Provider, TestUtils, toHex } from 'fuels';
import path from 'path';

import { ExampleContractAbi__factory } from './example-contract-types';

describe('ExampleContract', () => {
it('should return the input', async () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');
const wallet = await TestUtils.generateTestWallet(provider, [[1_000, NativeAssetId]]);

// Deploy
const bytecode = fs.readFileSync(path.join(__dirname, '../out/debug/example-contract.bin'));
const factory = new ContractFactory(bytecode, ExampleContractAbi__factory.abi, wallet);
const contract = await factory.deployContract();

// Call
const { value } = await contract.functions.return_input(1337).call();

// Assert
expect(value.toHex()).toEqual(toHex(1337));

// You can also make a call using the factory
const contractInstance = ExampleContractAbi__factory.connect(contract.id, wallet);
const { value: v2 } = await contractInstance.functions.return_input(1337).call();
expect(v2.toHex()).toBe(toHex(1337));
});
});
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/example-contract/src/example-contract.test.ts#L1-L30)

---

27 changes: 25 additions & 2 deletions docs/guide/wallets/checking-balances-and-coins.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
---
title: "Checking Balances And Coins"
parent: "Wallets"
grand_parent: "Guide"
---

[info]: this file is autogenerated
# Checking balances and coins

First, one should remember that, with UTXOs, each _coin_ is unique. Each UTXO corresponds to a unique _coin_, and said _coin_ has a corresponding _amount_ (the same way a dollar bill has either 10$ or 5$ face value). So, when you want to query the balance for a given asset ID, you want to query the sum of the amount in each unspent coin. This querying is done very easily with a wallet:

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:wallet-check-balance)

```typescript
import { Wallet, WalletUnlocked, BigNumberish} from 'fuels';
const balance: BigNumberish = await myWallet.getBalance(NativeAssetId);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L175-L178)

---


If you want to query all the balances (i.e., get the balance for each asset ID in that wallet), then it is as simple as:

[@code:typescript](./packages/fuel-gauge/src/doc-examples.test.ts#typedoc:wallet-check-balances)

```typescript
import { Wallet, WalletUnlocked, CoinQuantity} from 'fuels';
const balances: CoinQuantity[] = await myWallet.getBalances();
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/src/doc-examples.test.ts#L180-L183)

---

20 changes: 19 additions & 1 deletion docs/guide/wallets/encrypting-and-storing-wallets.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
title: "Encrypting And Storing Wallets"
parent: "Wallets"
grand_parent: "Guide"
---

[info]: this file is autogenerated
# Encrypting and storing wallets

## Creating a wallet and storing an encrypted JSON wallet on disk
Expand All @@ -6,7 +13,18 @@ You can also manage a wallet using [JSON wallets](https://cryptobook.nakov.com/s

You can create a random wallet and, at the same time, encrypt and store it. Then, later, you can recover the wallet if you know the master password:

[@code:typescript](./packages/wallet-manager/src/wallet-manager.test.ts#typedoc:wallet-manager-create)

```typescript
const walletManager = new WalletManager();
const password = '0b540281-f87b-49ca-be37-2264c7f260f7';
const wallet = Wallet.generate();

await walletManager.unlock(password);
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/wallet-manager/src/wallet-manager.test.ts#L123-L129)

---


## Encrypting and storing a wallet created from a mnemonic or private key

Expand Down
11 changes: 10 additions & 1 deletion docs/guide/wallets/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[nav_order: 2]
---
title: "Wallets"
parent: "Guide"
has_children: true
has_toc: false
nav_order: 2
---

[info]: this file is autogenerated


# Managing wallets

Expand Down
Loading

0 comments on commit 5bad2d0

Please sign in to comment.