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

docs: Update the hyperlinks to reference the new documentation hub #1520

Merged
Prev Previous commit
Merge branch 'rc/salamander' of github.com:FuelLabs/fuels-ts into ps/…
…docs/fix-internal-docs-links
  • Loading branch information
petertonysmith94 committed Dec 16, 2023
commit 949081baf593260e91e41df74e96b6d8f955e327
2 changes: 2 additions & 0 deletions .changeset/flat-dodos-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/funny-dolls-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/great-walls-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/hip-humans-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/late-mugs-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/odd-kids-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 7 additions & 0 deletions .changeset/six-shoes-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/math": minor
"@fuel-ts/providers": minor
"@fuel-ts/wallet": minor
---

ensure estimated fee values returned by getTransactionCost are never 0
2 changes: 2 additions & 0 deletions .changeset/stale-lizards-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 0 additions & 1 deletion .changeset/violet-mice-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@fuel-ts/program": minor
"@fuel-ts/providers": minor
"@fuel-ts/script": minor
"@fuel-ts/testcases": minor
"@fuel-ts/transactions": minor
"@fuel-ts/utils": minor
"@fuel-ts/versions": minor
Expand Down
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ dist/
out/

apps/demo-fuels/src/sway-programs-api
apps/demo-typegen/src/generated-types
apps/demo-typegen/src/contract-types
apps/demo-typegen/src/script-types
apps/demo-typegen/src/predicate-types
apps/demo-nextjs
apps/demo-react-cra
apps/demo-react-vite
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/rc-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release to @rc-<name> tag on npm

on:
push:
branches:
- "rc/*"

jobs:
release-pr:
name: "Release RC to npm"
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: CI Setup
uses: ./.github/actions/ci-setup

- name: Ensure NPM access
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Build
run: pnpm build

- name: Get RC name
uses: frabert/replace-string-action@v2
id: rc_name
with:
string: ${{ github.ref }}
pattern: "refs/heads/rc/"
replace-with: "rc-"

- name: Release to @${{ steps.rc_name.outputs.replaced }} tag on npm
id: release
run: |
echo "${{ steps.rc_name.outputs.replaced }}"
pnpm changeset:next
git add .changeset/fuel-labs-ci.md
pnpm changeset version --snapshot ${{ steps.rc_name.outputs.replaced }}
changetsets=$(pnpm changeset publish --tag ${{ steps.rc_name.outputs.replaced }})
published_version=$(echo "$changetsets" | grep -oP '@\K([0-9]+\.){2}[0-9]+-${{ steps.rc_name.outputs.replaced }}-\d+' | head -1)
echo "published_version=$published_version" >> $GITHUB_OUTPUT
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: mshick/add-pr-comment@v2
with:
message: |
This RC is published in NPM with version **${{ steps.rc_name.outputs.replaced }}**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ apps/demo-fuels/src/sway-programs-api
apps/demo-nextjs
apps/demo-react-cra
apps/demo-react-vite
apps/demo-typegen/src/generated-types
apps/demo-typegen/src/contract-types
apps/demo-typegen/src/script-types
apps/demo-typegen/src/predicate-types
apps/docs/.vitepress/cache/

packages/fuels/test/fixtures/project
Expand Down
4 changes: 3 additions & 1 deletion apps/demo-typegen/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
src/generated-types
src/contract-types
src/predicate-types
src/script-types

# Forc
**/out/debug/**
10 changes: 8 additions & 2 deletions apps/demo-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"scripts": {
"pretest": "run-s build:forc build:types",
"build:forc": "pnpm fuels-forc build -p contract",
"build:types": "pnpm fuels typegen -i contract/out/debug/demo-contract-abi.json -o src/generated-types"
"build:forc": "run-p forc:*",
"forc:contract": "pnpm fuels-forc build -p contract",
"forc:script": "pnpm fuels-forc build -p script",
"forc:predicate": "pnpm fuels-forc build -p predicate",
"build:types": "run-p types:*",
"types:contract": "pnpm fuels typegen -i contract/out/debug/demo-contract-abi.json -o src/contract-types",
"types:script": "pnpm fuels typegen -i script/out/debug/script-abi.json -o src/script-types --script",
"types:predicate": "pnpm fuels typegen -i predicate/out/debug/predicate-abi.json -o src/predicate-types --predicate"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions apps/demo-typegen/predicate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
7 changes: 7 additions & 0 deletions apps/demo-typegen/predicate/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "predicate"

[dependencies]
5 changes: 5 additions & 0 deletions apps/demo-typegen/predicate/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
predicate;

fn main() -> bool {
true
}
2 changes: 2 additions & 0 deletions apps/demo-typegen/script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
7 changes: 7 additions & 0 deletions apps/demo-typegen/script/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "script"

[dependencies]
5 changes: 5 additions & 0 deletions apps/demo-typegen/script/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
script;

fn main() -> u8 {
10
}
102 changes: 97 additions & 5 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,52 @@
import { safeExec } from '@fuel-ts/errors/test-utils';
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import type { BN } from 'fuels';
import { ContractFactory, Provider, toHex, BaseAssetId, Wallet, FUEL_NETWORK_URL } from 'fuels';

import { DemoContractAbi__factory } from './generated-types';
import bytecode from './generated-types/DemoContractAbi.hex';
import {
ContractFactory,
Provider,
toHex,
BaseAssetId,
Wallet,
FUEL_NETWORK_URL,
Address,
} from 'fuels';

import storageSlots from '../contract/out/debug/demo-contract-storage_slots.json';

import { DemoContractAbi__factory } from './contract-types';
import bytecode from './contract-types/DemoContractAbi.hex';
import { PredicateAbi__factory } from './predicate-types';
import { ScriptAbi__factory } from './script-types';

let gasPrice: BN;
describe('ExampleContract', () => {
beforeAll(async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
({ minGasPrice: gasPrice } = provider.getGasConfig());
});
it('with imported storage slots', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);

// #region typegen-demo-contract-storage-slots
// #context import storageSlots from './contract/out/debug/demo-contract-storage_slots.json';

const contract = await DemoContractAbi__factory.deployContract(bytecode, wallet, {
storageSlots,
gasPrice,
});
// #endregion typegen-demo-contract-storage-slots

expect(contract.id).toBeTruthy();
});
it('should return the input', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);

// Deploy
const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, wallet);
const contract = await factory.deployContract({ gasPrice });
const contractId = contract.id;

// Call
const { value } = await contract.functions
Expand All @@ -31,20 +59,29 @@ describe('ExampleContract', () => {
expect(value.toHex()).toEqual(toHex(1337));

// You can also make a call using the factory
const contractInstance = DemoContractAbi__factory.connect(contract.id, wallet);
// #region typegen-demo-contract-factory-connect
// #context import { DemoContractAbi__factory } from './types';

const contractInstance = DemoContractAbi__factory.connect(contractId, wallet);
const { value: v2 } = await contractInstance.functions
.return_input(1337)
.txParams({ gasPrice, gasLimit: 10_000 })
.call();
// #endregion typegen-demo-contract-factory-connect
expect(v2.toHex()).toBe(toHex(1337));
});

it('deployContract method', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);

// #region typegen-demo-contract-factory-deploy
// #context import { DemoContractAbi__factory } from './types';
// #context import bytecode from './types/DemoContractAbi.hex';

// Deploy
const contract = await DemoContractAbi__factory.deployContract(bytecode, wallet, { gasPrice });
// #endregion typegen-demo-contract-factory-deploy

// Call
const { value } = await contract.functions
Expand Down Expand Up @@ -89,3 +126,58 @@ it('should throw when dry running via contract factory with wallet with no resou

expect((<Error>error).message).toMatch('not enough coins to fit the target');
});

test('Example script', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);

// TODO: investigate why do we need to specify the gasLimit here. If we don't specify it, the call fails saying `FuelError: Gas limit '0' is lower than the required: '19'.`

// #region typegen-demo-script
// #context import { ScriptAbi__factory } from './types';

const script = ScriptAbi__factory.createInstance(wallet);
const { value } = await script.functions
.main()
.txParams({
gasPrice: provider.getGasConfig().minGasPrice,
gasLimit: 10_000,
})
.call();
// #endregion typegen-demo-script
// @ts-expect-error TODO: investitage - typegen is expecting value to be a number but the value being returned is the string '0xa'
expect(value.toNumber()).toBe(10);
});

test('Example predicate', async () => {
// #region typegen-demo-predicate
// #context import { PredicateAbi__factory } from './types';

// In this exchange, we are first transferring some coins to the predicate
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);
const receiver = Wallet.fromAddress(Address.fromRandom(), provider);

const predicate = PredicateAbi__factory.createInstance(provider);

const tx = await wallet.transfer(predicate.address, 100_000, BaseAssetId, {
gasPrice: provider.getGasConfig().minGasPrice,
gasLimit: 50,
});
await tx.wait();

const initialPredicateBalance = await predicate.getBalance();

// Then we are transferring some coins from the predicate to a random address (receiver)
const tx2 = await predicate.transfer(receiver.address, 50_000, BaseAssetId, {
gasPrice: provider.getGasConfig().minGasPrice,
gasLimit: 50,
});
await tx2.wait();

expect((await receiver.getBalance()).toNumber()).toEqual(50_000);
expect((await predicate.getBalance()).toNumber()).toBeLessThan(
initialPredicateBalance.toNumber()
);
// #endregion typegen-demo-predicate
});
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.