Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement playwright for browser compatibility testing #1182

Closed
Closed
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
6345f20
feat: implement playwright for browser based testing with jest
Aug 10, 2023
71bded7
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 11, 2023
8ee0391
feat: regen lock file
Aug 11, 2023
18dc128
feat: implement multiple jest configs for different environments
Aug 14, 2023
7a6b27a
feat: use jest test pattern for runner groups
Aug 15, 2023
cb4fe09
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 15, 2023
fe8c134
chore: regen lock file
Aug 15, 2023
61faf71
feat: remove runner groups syntax from test
Aug 15, 2023
4336c89
feat: implement all tests config
Aug 15, 2023
ef31bd7
chore: install nyc
Aug 15, 2023
e25d874
chore: add nyc config
Aug 15, 2023
3c93e24
chore: remove duplicate group tsdoc key
Aug 15, 2023
92cffa8
chore: changeset
Aug 15, 2023
c2aeab0
feat: implement merged coverage
Aug 15, 2023
0baf51e
feat: move more config to jest base config
Aug 16, 2023
2f5e7e8
feat: move js config to json for nyc
Aug 16, 2023
2e37b32
feat: implement constants for test envs
Aug 16, 2023
0c04a3d
feat: support nyc converage in test workflow
Aug 16, 2023
1d6e27e
feat: add missign coverage json rename
Aug 16, 2023
8cc44d8
chore: linting
Aug 16, 2023
8905f73
Aug 16, 2023
94fa353
feat: fix jest env pattern matches
Aug 16, 2023
c6b965e
feat: add browser test env to docs snippets
Aug 16, 2023
f9d5705
chore: linting
Aug 16, 2023
938815d
feat: remove usage of env tags in test declarations
Aug 16, 2023
f1cbac1
feat: use regex on file path for env test matching rather than test case
Aug 16, 2023
80149fa
feat: rename abi coder tests
Aug 16, 2023
a1fc53f
feat: rename fuel gauge packages
Aug 16, 2023
062b413
feat: add environemnt testing to abi typegen package
Aug 16, 2023
34f78dc
chore: linting
Aug 16, 2023
bcbca1a
feat: add environment tests to various packages
Aug 16, 2023
2800dc2
feat: rename more tests for environments
Aug 16, 2023
27d7665
feat: add further environment prefixes to tests
Aug 16, 2023
3c14af5
feat: add further environment prefixes to tests
Aug 16, 2023
676387f
feat: reimplement tx param in custom transaction test
Aug 16, 2023
46e3631
feat: rename further test files
Aug 16, 2023
a771b8a
feat: add github action to validate test files
Aug 16, 2023
41aeefc
feat: add pretest to ci test script
Aug 17, 2023
c3e6785
chore: force rebuild
Aug 17, 2023
9728aec
feat: alter test scripts
Aug 17, 2023
87d6c0f
fix: reintroduce unintentionally deleted file
Aug 17, 2023
460ddc5
fix: reintroduce unintentionally deleted file
Aug 17, 2023
15709dc
fix: fix crypto file indexes
Aug 17, 2023
9f094a1
chore: force rebuild
Aug 17, 2023
56de71d
chore: force rebuild
Aug 17, 2023
e1aee2f
feat: modify ci script
Aug 17, 2023
0fcb6d5
chore: forece rebuild
Aug 17, 2023
0cc3533
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 17, 2023
87c93af
feat: modify ci test script to run env tests independently
Aug 17, 2023
c26e596
feat: add coverage to ci test script
Aug 17, 2023
0349500
feat: fix gh coverage workflow
Aug 17, 2023
8506134
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 17, 2023
9847868
feat: add envs to wallet manager tests
Aug 17, 2023
a8e7ef8
feat: fix links in md files for wallet manager tests
Aug 17, 2023
ee18efe
feat: gh workflow coverage report call
Aug 17, 2023
bae9f56
feat: revert master coverage report name
Aug 17, 2023
f60c13d
feat: fix master upload file name
Aug 17, 2023
3e53b22
feat: add conditional test step to gh workflow
Aug 17, 2023
d18a30c
fix: fix gh action ref name
Aug 17, 2023
97b5a89
fix: fix gh action
Aug 17, 2023
f06b281
feat: test gh action workflow
Aug 17, 2023
cf91864
feat: retry action
Aug 17, 2023
545d814
feat: alterations to gh test script
Aug 18, 2023
0d221ae
feat: try test gh flow without coverage file
Aug 18, 2023
c15331d
feat: gh workflow alter
Aug 18, 2023
b99083c
feat: try different version of atriom coverage report
Aug 18, 2023
f26bfc2
feat: add test location in results flags to coverage reports
Aug 18, 2023
6150cad
feat: implement coverage threshhold
Aug 18, 2023
2cee062
feat: lower testing threshhold
Aug 18, 2023
ab56804
feat: finalise test coverage merging and reporting
Aug 21, 2023
6ad92d9
feat: fixes for the merge coverage script
Aug 21, 2023
e2b9a2d
feat: alter github action to support nyc
Aug 21, 2023
5c9c385
feat: add github token to nyc action
Aug 21, 2023
5e46cf6
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 21, 2023
e122ee2
feat: add coverage template
Aug 21, 2023
179a749
feat: add pretest to ci test script
Aug 21, 2023
7953c74
feat: add source to comment template
Aug 21, 2023
d1bbf7e
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 22, 2023
86ee9f4
feat: resolve pretest issue
Aug 22, 2023
ff31395
feat: attempt CI without base coverage
Aug 22, 2023
0fd0022
feat: alter git checkout fetch depth
Aug 22, 2023
8c17cf2
feat: add fetch base branch to test workflow
Aug 22, 2023
f99e7e5
feat: add base coverage file
Aug 22, 2023
8fa679b
feat: alter gh workflow fetch depth
Aug 22, 2023
8507a35
feat: alter fetch depth on origin in gh test workflow
Aug 22, 2023
f93a2b4
feat: alter base coverage file
Aug 22, 2023
69c39c9
feat: report lcov in report
Aug 22, 2023
7a4acf8
feat: add json reporting to nyc
Aug 22, 2023
da304f3
feat: use base lcov in coverage report
Aug 22, 2023
bdc20b6
feat: use diff version of cov reporter
Aug 22, 2023
3fb237d
feat: fix report action attributes
Aug 22, 2023
ac12192
feat: alter report coverage action to not filter files
Aug 22, 2023
ad89d3c
feat: alter master coverage artefact
Aug 22, 2023
abfe478
feat: download coverage using pr number
Aug 22, 2023
fadb558
feat: get coverage via run id
Aug 22, 2023
de620b1
feat: add temp gh workflow steps for this PR
Aug 22, 2023
affdac9
feat: fix temp gh action
Aug 22, 2023
9f02d6d
feat: fix github action conditional syntax
Aug 22, 2023
4ec815d
chore: testing cleanup
Aug 22, 2023
3b0f404
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 22, 2023
ff0f9da
feat: alter fuel error test file names
Aug 22, 2023
d43e422
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 23, 2023
d07fbee
feat: add missing validate test step to test CI
Aug 23, 2023
a86e75a
feat: remove byte coder test
Aug 23, 2023
4a4bda6
feat: add vecs test env
Aug 23, 2023
15eb7ec
Update scripts/merge-coverage.ts
danielbate Aug 23, 2023
04015c3
Update scripts/merge-coverage.ts
danielbate Aug 23, 2023
376beb0
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 23, 2023
f4ddc02
feat: rename test files with duplicated envs
Aug 23, 2023
8a1984a
Merge branch 'db/feat/implement-browser-testing-with-runner-groups' o…
Aug 23, 2023
11ae5df
feat: swap jest playwright ts config for js
Aug 24, 2023
8cca525
feat: modify test commands
Aug 24, 2023
f3b2e58
feat: remove test file path from node and browser test commands
Aug 24, 2023
eb6b2a4
feat: disable jest playwright collect coverage
Aug 24, 2023
5d6d903
feat: test concurrent test worlfows
Aug 24, 2023
be8fee0
feat: rename node test stage
Aug 24, 2023
f2dc574
feat: add concurrent test and report steps
Aug 24, 2023
5ccce0a
feat: fix workflow name in coverage download
Aug 24, 2023
9eb562e
feat: reinstate test yaml
Aug 24, 2023
e3511f4
feat: rename workflow in download coverage step
Aug 24, 2023
ea1378b
feat: rename workflow run triggers in test yaml
Aug 24, 2023
73d7972
chore: implement find/grep script for test files (#1209)
arboleya Aug 25, 2023
9d225e8
feat: introduce tests to check browser environment
Aug 25, 2023
58b0fc4
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 25, 2023
3b4d446
feat: add browser type to browser test
Aug 25, 2023
d93385e
feat: add sequential test commands
Aug 25, 2023
9a68691
feat: rename coverage commands
Aug 25, 2023
8fc6eb3
feat: add test groups to docs snips contracts
Aug 25, 2023
1bdf65c
feat: install expect-playwright
Aug 25, 2023
50a1231
feat: modify env tests
Aug 25, 2023
1fb2de7
feat: remove group from contracts docs snippets for test
Aug 26, 2023
0bc70cb
feat: add describe to provider time test
Aug 26, 2023
419deb9
feat: add browser test env to all test files
Aug 26, 2023
ecab299
feat: rename test files
Aug 27, 2023
ee2166c
feat: remove duplicated test grpups
Aug 27, 2023
fbff4f2
feat: remove duplicated tyest
Aug 27, 2023
4404f6e
feat: alter test validation script
Aug 27, 2023
52c6100
feat: alter test commands and coumentation
Aug 28, 2023
c0a7ef7
feat: simplify test gh workflow
Aug 28, 2023
8883afa
feat: update docs snippets links
Aug 28, 2023
6713725
feat: add support for @group
Aug 28, 2023
6774230
feat: lint fixes for check tests test
Aug 28, 2023
058e2c5
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 28, 2023
a65c9e9
feat: add built step to parallel test jobs
Aug 28, 2023
40b75f6
feat: remove support for custom tags in tsdoc
Aug 28, 2023
62a3a7c
feat: add ci setup to seperate test job
Aug 28, 2023
28e4edd
feat: reinstate ci test command
Aug 28, 2023
03a03a1
feat: remove test file paths from test comamnds
Aug 28, 2023
741bbfc
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 28, 2023
a541587
feat: rename provider snapshot test
Aug 29, 2023
d5cf553
feat: implement and skip browser tests
Aug 29, 2023
d7ef7c8
feat: add find PR step to test workflow
Aug 29, 2023
b50de5e
feat: add build step to test workflow
Aug 29, 2023
5f0ff54
feat: add correct workflow download to test runs
Aug 29, 2023
0549bbe
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Aug 30, 2023
fca23cf
feat: remove browser or node package
Aug 30, 2023
07f840c
feat: add environmennt to transaction response test
Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/grumpy-wolves-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
40 changes: 26 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,49 @@ jobs:
- name: Lint
run: pnpm lint

- name: Validate tests
run: pnpm test:validate

- name: Find PR Number
uses: jwalton/gh-find-current-pr@v1
id: findPr

- name: Run tests and collect coverage
if: ${{ !steps.findPr.outputs.number }}
run: pnpm ci:test -- --json --coverage --testLocationInResults --outputFile=report.master.json
run: pnpm ci:test && pnpm ci:test --browser && pnpm test:merge-coverage && pnpm test:report-coverage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To save CI time, we should run --browser and --node tests in parallel I CI.

Then, we'd have a third job awaiting the other two to finish and merge their coverage afterward.

I remember @Dhaiwat10 started this implementation on his first draft for this.

This comment was marked as off-topic.


- name: Upload coverage to Github artifacts
uses: actions/upload-artifact@v3
if: ${{ !steps.findPr.outputs.number }}
with:
name: coverage-reports
path: report.master.json
name: coverage-master
path: coverage/report

- name: Download coverage artifact
uses: dawidd6/action-download-artifact@v2
if: ${{ steps.findPr.outputs.number }}
# TODO: Remove PR != check once #1182 has been merged
if: ${{ (steps.findPr.outputs.number) && (steps.findPr.outputs.number != 1182)}}
with:
workflow: test.yaml
branch: master
name: coverage-reports
path: coverage-reports
name: coverage-master
path: coverage-master

# TODO: Delete once #1182 has been merged
- name: Download coverage artifact (temporary)
uses: dawidd6/action-download-artifact@v2
if: ${{ (steps.findPr.outputs.number) && (steps.findPr.outputs.number == 1182)}}
with:
workflow: test.yaml
run_id: 5940564903
name: coverage-master
path: coverage-master

- name: Run tests and post reports to PR
uses: ArtiomTr/jest-coverage-report-action@v2
- name: Report coverage
uses: romeovs/lcov-reporter-action@v0.3.1
if: ${{ steps.findPr.outputs.number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
package-manager: pnpm
annotations: failed-tests
test-script: pnpm ci:test
prnumber: ${{ steps.findPr.outputs.number }}
base-coverage-file: coverage-reports/report.master.json
lcov-file: coverage/report/lcov.info
lcov-base: coverage-master/lcov.info
delete-old-comments: true
title: "Coverage Report"
11 changes: 11 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"include": ["packages/**/*.ts", "apps/docs-snippets/**/*.ts"],
"exclude": [
"/dist/",
"/apps/demo-nextjs",
"/apps/demo-react-cra",
"/dist/demo-react-vite"
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pnpm test -- --coverage --my-other-flag
pnpm test packages/my-desired-package

# run tests for a specific file
pnpm test packages/my-desired-package/src/my.test.ts
pnpm test packages/my-desired-package/src/my.browser.test.ts
```

Or if you want to start a local Fuel-Core node and run all tests serially you can do:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Provider, fromTai64ToUnix } from 'fuels';

describe(__filename, () => {
test('produceBlocks with custom timestamp docs snippet', async () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');
const latestBlock = await provider.getBlock('latest');
if (!latestBlock) {
throw new Error('No latest block');
}
const lastBlockNumber = latestBlock.height;
// #region Provider-produceBlocks-custom-timestamp
const lastBlockTimestamp = fromTai64ToUnix(latestBlock.time);
const latestBlockNumber = await provider.produceBlocks(3, lastBlockTimestamp + 1000);
// #endregion Provider-produceBlocks-custom-timestamp
expect(latestBlockNumber.toHex()).toBe(lastBlockNumber.add(3).toHex());
});
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Address } from 'fuels';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe('EvMAddress', () => {
describe(__filename, () => {
let contract: Contract;
const Bits256: B256AddressEvm =
'0x000000000000000000000000210cf886ce41952316441ae4cac35f00f0e882a6';
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/src/guide/contracts/call-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `forward` parameter allows the sending of a specific amount of coins to a co

<!-- forward:example:end -->

<<< @/../../docs-snippets/src/guide/contracts/call-parameters.test.ts#call-params-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/call-parameters.node.browser.test.ts#call-params-1{ts:line-numbers}

## Gas Limit Parameter

Expand All @@ -29,7 +29,7 @@ The `gasLimit` refers to the maximum amount of gas that can be consumed specific

<!-- gas_limit:example:end -->

<<< @/../../docs-snippets/src/guide/contracts/call-parameters.test.ts#call-params-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/call-parameters.node.browser.test.ts#call-params-2{ts:line-numbers}

## Call Parameters `gasLimit` vs Transaction Parameters `gasLimit`

Expand All @@ -41,4 +41,4 @@ If you don't set the `gasLimit` for the Call, the Transaction `gasLimit` will be

You can set both Call Parameters and Transaction Parameters within the same contract function call.

<<< @/../../docs-snippets/src/guide/contracts/call-parameters.test.ts#call-params-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/call-parameters.node.browser.test.ts#call-params-3{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/calls-with-different-wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This guide demonstrates how to make contract calls using different wallets and p

To change the wallet associated with a contract instance, assign a new wallet to the instance's `account` property. This allows you to make contract calls with different wallets in a concise manner:

<<< @/../../docs-snippets/src/guide/contracts/calls-with-different-wallets.test.ts#calls-with-different-wallets-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/calls-with-different-wallets.node.browser.test.ts#calls-with-different-wallets-1{ts:line-numbers}

## Changing Providers

Similarly, you can assign a custom provider to a contract instance by modifying its provider property. This enables you to use a provider wrapper of your choice:

<<< @/../../docs-snippets/src/guide/contracts/calls-with-different-wallets.test.ts#calls-with-different-wallets-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/calls-with-different-wallets.node.browser.test.ts#calls-with-different-wallets-2{ts:line-numbers}

> **Note:** When connecting a different wallet to an existing contract instance, the provider used to deploy the contract takes precedence over the newly set provider. If you have two wallets connected to separate providers (each communicating with a different fuel-core instance), the provider assigned to the deploying wallet will be used for contract calls. This behavior is only relevant when multiple providers (i.e., fuel-core instances) are present and can be ignored otherwise.
6 changes: 3 additions & 3 deletions apps/docs/src/guide/contracts/configurable-constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ If each of these constants has new values that have been assigned to them, the f

During contract deployment, you can define new values for the configurable constants. This is achieved as follows:

<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.test.ts#configurable-constants-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.node.browser.test.ts#configurable-constants-2{ts:line-numbers}

You can assign new values to any of these configurable constants.

If you wish to assign a new value to just one constant, you can do the following:

<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.test.ts#configurable-constants-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.node.browser.test.ts#configurable-constants-3{ts:line-numbers}

Please note that when assigning new values for a `Struct`, all properties of the `Struct` must be defined. Failing to do so will result in an error:

<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.test.ts#configurable-constants-4{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/configurable-constants.node.browser.test.ts#configurable-constants-4{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/contract-balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The `transfer` function calls the built-in Sway function `transfer_to_address`,

Let's execute this contract and use the `getBalance` method to validate the remaining asset amount the contract has left to spend.

<<< @/../../docs-snippets/src/guide/contracts/contract-balance.test.ts#contract-balance-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/contract-balance.node.browser.test.ts#contract-balance-3{ts:line-numbers}

In this example, we first forward an asset amount greater than the amount required for the transfer and then execute the contract call.

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/cost-estimation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ The following example demonstrate how to get the estimated transaction cost for:

## 1. Single contract call transaction:

<<< @/../../docs-snippets/src/guide/contracts/cost-estimation.test.ts#cost-estimation-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/cost-estimation.node.browser.test.ts#cost-estimation-1{ts:line-numbers}

## 2. Multiple contract calls transaction:

<<< @/../../docs-snippets/src/guide/contracts/cost-estimation.test.ts#cost-estimation-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/cost-estimation.node.browser.test.ts#cost-estimation-2{ts:line-numbers}

You can use the transaction cost estimation to set the gas limit for an actual call or display the estimated cost to the user.
8 changes: 4 additions & 4 deletions apps/docs/src/guide/contracts/deploying-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ After writing a contract in Sway and compiling it with `forc build` (<a :href="i

Before deploying a contract, set up the necessary environment by importing the required SDK components and initializing a wallet and a provider.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.node.browser.test.ts#contract-setup-1{ts:line-numbers}

## 3. Loading Contract Artifacts

Load the contract bytecode and JSON ABI, generated from the Sway source, into the SDK.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.node.browser.test.ts#contract-setup-2{ts:line-numbers}

## 4. Deploying the Contract

Initialize a `ContractFactory` with the bytecode, ABI, and wallet. Deploy the contract and use its methods.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.node.browser.test.ts#contract-setup-3{ts:line-numbers}

## 5. Executing a Contract Call

Now that the contract is deployed, you can interact with it. In the following steps, you'll learn how to execute contract calls.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-4{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.node.browser.test.ts#contract-setup-4{ts:line-numbers}

For a more comprehensive TypeScript-backed Fuel usage, learn how to [generate types from ABI](../abi-typegen/generating-types-from-abi.md)
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ In the Fuel Network, contracts play a crucial role in facilitating interactions

For instance, consider a Sway contract with two ABI methods called `echo_str_8(str[8])` and `echo_u8(u8)`. After deploying the contract, you can call the methods as follows:

<<< @/../../docs-snippets/src/guide/contracts/index.test.ts#echo-values{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/index.node.browser.test.ts#echo-values{ts:line-numbers}

The example above demonstrates a simple contract call using default configurations. The following sections will explore how to further configure various parameters for contract calls, allowing for more advanced interactions with your deployed contracts in the Fuel Network.
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/inter-contract-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ The `TokenDepositor` contract imports the `SimpleToken` contract and calls its `

Once both contracts are deployed, we can use the SDK to make the `TokenDepositor` contract to call the `SimpleToken` contract.

<<< @/../../docs-snippets/src/guide/contracts/inter-contract-calls.test.ts#inter-contract-calls-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/inter-contract-calls.node.browser.test.ts#inter-contract-calls-3{ts:line-numbers}

Pay attention to the method `addContracts` called by the TokenDepositor contract. This method accepts an array of instances of deployed contracts. Without calling this method, the inter-contract call will not work.
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Consider the following example contract:

To access the logged values in TypeScript, use the `logs` property in the `FunctionInvocationResult` of a contract call result. The logs data will be stored in an `Array<any>`:

<<< @/../../docs-snippets/src/guide/contracts/logs.test.ts#log-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/logs.node.browser.test.ts#log-2{ts:line-numbers}

This approach allows you to work seamlessly with logged values in your contract, making it easier to understand and debug the contract's behavior.
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/managing-deployed-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ When you log the `contractId` property of an instantiated Contract using `consol

If you have already an instantiated and deployed contract in hands you can create another contract instance simply by using the `contractId` property and the contract JSON abi:

<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.node.browser.test.ts#managing-deployed-contracts-1{ts:line-numbers}

The previous example assumes that you have a `Contract` instance at hand. However, some Fuel tools and Sway use the [b256](../types/bits256.md) type format, a hex-encoded string-like type, for contract IDs.

You might have this format instead, for example, if you have deployed your contract with `forc deploy`.

The process of instantiating a `Contract` remains the same when using a contract ID of type `b256`:

<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.node.browser.test.ts#managing-deployed-contracts-2{ts:line-numbers}
6 changes: 3 additions & 3 deletions apps/docs/src/guide/contracts/multicalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ Use the `multiCall` method to call multiple functions on the same contract in a

<!-- multicall:example:end -->

<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/multicalls.node.browser.test.ts#multicall-1{ts:line-numbers}

## Different contracts multi calls

The `multiCall` method also allows you to execute multiple contract calls to distinct contracts within a single transaction:

<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/multicalls.node.browser.test.ts#multicall-2{ts:line-numbers}

You can also chain supported contract call methods, like `callParams`, for each contract call:

<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/multicalls.node.browser.test.ts#multicall-3{ts:line-numbers}

When chaining contract call methods within `multiCall`, avoid executing the contract functions themselves, such as `.call`, `.get`, and `.simulate`.

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/simulate-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Simulating a transaction is a powerful feature that allows you to validate wheth

You can use the `simulate()` method to test your transactions:

<<< @/../../docs-snippets/src/guide/contracts/simulate-transactions.test.ts#simulate-transactions-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/simulate-transactions.node.browser.test.ts#simulate-transactions-1{ts:line-numbers}

Simulating a transaction allows you to catch potential errors or issues before submitting the real transaction, making it a valuable tool for development and user interaction.

Expand All @@ -22,7 +22,7 @@ When interacting with a contract, you might want to execute a method that does n

In such cases, you can use the `simulate()` method:

<<< @/../../docs-snippets/src/guide/contracts/simulate-transactions.test.ts#simulate-transactions-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/simulate-transactions.node.browser.test.ts#simulate-transactions-2{ts:line-numbers}

Using `simulate()` for read-only calls or to test transactions provides a way to safely and efficiently access information from the blockchain or validate how a transaction would behave. It ensures that no changes will be made to the blockchain and no resources will be spent, making it a valuable tool for data retrieval and development.

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/storage-slots.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

When deploying a contract, you can specify the custom storage slots that you want to use.

<<< @/../../../packages/fuel-gauge/src/storage-test-contract.test.ts#contract-deployment-storage-slots{ts:line-numbers}
<<< @/../../../packages/fuel-gauge/src/storage-test-contract.node.browser.test.ts#contract-deployment-storage-slots{ts:line-numbers}

In the above example, we directly imported the storage slots from a JSON file generated by the Sway compiler.

Instead of importing from a file, you can also specify the custom storage slots directly in your code:

<<< @/../../../packages/fuel-gauge/src/storage-test-contract.test.ts#contract-deployment-storage-slots-inline{ts:line-numbers}
<<< @/../../../packages/fuel-gauge/src/storage-test-contract.node.browser.test.ts#contract-deployment-storage-slots-inline{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/transaction-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To set these parameters, use the optional `TxParams` object and pass it to the `

<!-- set_tx_params:example:end -->

<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.test.ts#transaction-parameters-2{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.node.browser.test.ts#transaction-parameters-2{ts:line-numbers}

<!-- This section should explain the default tx params -->
<!-- default_tx_params:example:start -->
Expand All @@ -41,4 +41,4 @@ You can also set `TxParams` when deploying contracts or transferring assets by p

<!-- est:example:end -->

<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.test.ts#transaction-parameters-3{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.node.browser.test.ts#transaction-parameters-3{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/variable-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Here's an example of a contract function that utilizes the `transfer_to_address`

With the SDK, you can call `transfer_coins_to_output` by chaining the `txParams` and adding the property `variableOutputs: amount` to your contract call. Like this:

<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.test.ts#variable-outputs-1{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/transaction-parameters.node.browser.test.ts#variable-outputs-1{ts:line-numbers}

In the TypeScript SDK, the output variables are automatically added to the transaction's list of outputs. The output's amount and owner may vary based on the transaction execution.
Loading
Loading