-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(changesets): versioning packages (#719)
* ci(scripts): update docs * ci(changesets): versioning packages Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
217f981
commit 5bad2d0
Showing
72 changed files
with
688 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.