Skip to content

Commit

Permalink
Merge branch 'master' into ci/upgrade-dependabot-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed May 1, 2024
2 parents d75fe2f + 86543ed commit 1b20fc8
Show file tree
Hide file tree
Showing 26 changed files with 1,368 additions and 1,127 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-trainers-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": patch
"fuels": patch
---

build: update deps
6 changes: 6 additions & 0 deletions .changeset/neat-ladybugs-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": patch
"@fuel-ts/program": patch
---

fix: handling optional policies
4 changes: 4 additions & 0 deletions .changeset/rude-ants-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

docs: add notice about `forc deploy` in `fuels deploy` docs
8 changes: 8 additions & 0 deletions .fuel-core/configs/stateConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@
"amount": 12704439083013451934,
"data": "",
"da_height": 0
},
{
"sender": "0x22cae5308938e8b4caf217b6464884f6331eff05e81468df8ccd08126effc8d0",
"recipient": "0x8d2af98a4198732a46bf65d87a73427dd7608acaad2414585d8ccdd6f59c437b",
"nonce": "0x381de90750098776c71544527fd253412908dec3d07ce9a7367bd1ba975908a0",
"amount": 18446744073709551615,
"data": "",
"da_height": 0
}
],
"contracts": [],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
- name: Run dependabot changeset script
run: pnpm changeset:dependabot
env:
PR_TITLE: $(jq -r .pull_request.title "$GITHUB_EVENT_PATH")
PR_TITLE: ${{ github.event.pull_request.title }}

- name: Commit Changeset
run: |
Expand Down
2 changes: 1 addition & 1 deletion apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"fuels": "workspace:*",
"@tanstack/react-query": "^5.29.2",
"dotenv": "^16.4.5",
"next": "14.0.1",
"next": "14.2.2",
"react": "^18.2",
"react-dom": "^18.2",
"react-hot-toast": "^2.4.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/react-dom": "18.2.4",
"@types/react": "18.2.9",
"fuels": "workspace:*",
"next": "13.4.4",
"next": "14.2.2",
"react-dom": "18.2.0",
"react": "18.2.0",
"typescript": "~5.2.2"
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react": "^4.0.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"typescript": "~5.2.2",
"vite": "^4.3.9"
"vite": "^5.2.9"
}
}
2 changes: 1 addition & 1 deletion apps/demo-wallet-sdk-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@fuels/react": "^0.18.1",
"@tanstack/react-query": "^5.29.2",
"fuels": "workspace:*",
"next": "14.1.0",
"next": "14.2.2",
"react": "^18",
"react-dom": "^18"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('Transaction Request', () => {
// #endregion transaction-request-7

expect(transactionId).toBe(
'0x09274de739e2a53a815799b4c7fa93359eaf4befee0b26be04a7a6283bbeb127'
'0xac53fe9d09624f6295e0d9205eecc373ff568db2dbb89656190b1cb1a9b5bb00'
);
});
});
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"nodemon": "^3.0.3",
"replace": "^1.2.2",
"typedoc": "^0.25.1",
"typedoc-plugin-merge-modules": "^5.0.1",
"typedoc-plugin-merge-modules": "^5.1.0",
"vitepress": "1.0.0-rc.40",
"vitepress-plugin-search": "1.0.4-alpha.19",
"vue": "^3.4.15"
Expand Down
10 changes: 8 additions & 2 deletions apps/docs/src/guide/fuels-cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ Using the `--deploy` flag will additionally:
npx fuels@{{fuels}} deploy
```

1. Deploy all Sway contracts under `workspace`
> [!NOTE] Note
> We recommend using the `fuels deploy` command only when you are deploying contracts to a local node.
> If you are deploying contracts to a live network like the Testnet, we recommend using the [`forc deploy`](https://docs.fuel.network/docs/intro/quickstart-contract/#deploy-to-testnet) command instead.
The `fuels deploy` command does two things:

1. Deploy all Sway contracts under `workspace`.
1. Saves their deployed IDs to:
- _`./src/sway-programs-api/contract-ids.json`_

Expand All @@ -117,7 +123,7 @@ For a complete example, see:
npx fuels@{{fuels}} dev
```

The `fuels dev` command do three things:
The `fuels dev` command does three things:

1. Auto-start a short-lived `fuel-core` node ([docs](./config-file.md#autostartfuelcore))
1. Runs `build` and `deploy` once at the start
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"eslint-plugin-tsdoc": "^0.2.17",
"glob": "^10.2.6",
"knip": "^5.9.3",
"memfs": "^4.6.0",
"memfs": "^4.8.2",
"nodemon": "^3.0.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
Expand All @@ -106,11 +106,11 @@
"tsx": "^4.7.0",
"turbo": "^1.8.8",
"typescript": "~5.2.2",
"vite": "^5.0.11",
"vite-plugin-node-polyfills": "^0.17.0",
"vite": "^5.2.10",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-plain-text": "^1.4.2",
"vitest": "^1.1.3",
"webdriverio": "^8.32.0"
"webdriverio": "^8.36.1"
},
"pnpm": {
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@noble/curves": "^1.4.0",
"ethers": "^6.7.1",
"events": "^3.3.0",
"graphql": "^16.6.0",
"graphql": "^16.8.1",
"graphql-request": "5.0.0",
"graphql-tag": "^2.12.6",
"portfinder": "^1.0.32",
Expand Down
13 changes: 9 additions & 4 deletions packages/account/src/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ describe('Account', () => {
const senderBalances = await sender.getBalances();
const receiverBalances = await receiver.getBalances();

expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(499112) }]);
const expectedRemaining = 499118;
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(expectedRemaining) }]);
expect(receiverBalances).toEqual([{ assetId: baseAssetId, amount: bn(1) }]);
});

Expand All @@ -402,7 +403,8 @@ describe('Account', () => {
const senderBalances = await sender.getBalances();
const receiverBalances = await receiver.getBalances();

expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(499112) }]);
const expectedRemaining = 499118;
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(expectedRemaining) }]);
expect(receiverBalances).toEqual([{ assetId: baseAssetId, amount: bn(1) }]);
});

Expand Down Expand Up @@ -507,7 +509,8 @@ describe('Account', () => {
expect(amount.toString()).toEqual(messageOutReceipt.amount.toString());

const senderBalances = await sender.getBalances();
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(498427) }]);
const expectedRemaining = 498433;
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(expectedRemaining) }]);
});

it('can retrieve a valid MessageProof', async () => {
Expand Down Expand Up @@ -582,7 +585,9 @@ describe('Account', () => {
expect(amount.toString()).toEqual(messageOutReceipt.amount.toString());

const senderBalances = await sender.getBalances();
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(1498327) }]);

const expectedRemaining = 1498333;
expect(senderBalances).toEqual([{ assetId: baseAssetId, amount: bn(expectedRemaining) }]);
});

it('should ensure gas price and gas limit are validated when transfering amounts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('transactionRequestify', () => {
}

expect(txRequest.type).toEqual(txRequestLike.type);
expect(toNumber(txRequest.tip)).toEqual(txRequestLike.tip);
expect(txRequest.tip?.toNumber()).toEqual(txRequestLike.tip);
expect(toNumber((<ScriptTransactionRequest>txRequest).gasLimit)).toEqual(
txRequestLike.gasLimit
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
OutputType,
TransactionType,
} from '@fuel-ts/transactions';
import { concat, hexlify } from '@fuel-ts/utils';
import { concat, hexlify, isDefined } from '@fuel-ts/utils';

import type { Account } from '../../account';
import type { GqlGasCosts } from '../__generated__/operations';
Expand Down Expand Up @@ -92,11 +92,11 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi
/** Type of the transaction */
abstract type: TransactionType;
/** Gas price for transaction */
tip: BN;
tip?: BN;
/** Block until which tx cannot be included */
maturity: number;
maturity?: number;
/** The maximum fee payable by this transaction using BASE_ASSET. */
maxFee?: BN;
maxFee: BN;
/** The maximum amount of witness data allowed for the transaction */
witnessLimit?: BN | undefined;
/** List of inputs */
Expand All @@ -120,10 +120,10 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi
outputs,
witnesses,
}: BaseTransactionRequestLike = {}) {
this.tip = bn(tip);
this.maturity = maturity ?? 0;
this.witnessLimit = witnessLimit ? bn(witnessLimit) : undefined;
this.maxFee = maxFee ? bn(maxFee) : undefined;
this.tip = tip ? bn(tip) : undefined;
this.maturity = maturity && maturity > 0 ? maturity : undefined;
this.witnessLimit = isDefined(witnessLimit) ? bn(witnessLimit) : undefined;
this.maxFee = bn(maxFee);
this.inputs = inputs ?? [];
this.outputs = outputs ?? [];
this.witnesses = witnesses ?? [];
Expand All @@ -133,23 +133,24 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi
let policyTypes = 0;
const policies: Policy[] = [];

if (req.tip) {
const { tip, witnessLimit, maturity } = req;

if (bn(tip).gt(0)) {
policyTypes += PolicyType.Tip;
policies.push({ data: req.tip, type: PolicyType.Tip });
policies.push({ data: bn(tip), type: PolicyType.Tip });
}
if (req.witnessLimit) {
if (isDefined(witnessLimit) && bn(witnessLimit).gte(0)) {
policyTypes += PolicyType.WitnessLimit;
policies.push({ data: req.witnessLimit, type: PolicyType.WitnessLimit });
policies.push({ data: bn(witnessLimit), type: PolicyType.WitnessLimit });
}
if (req.maturity > 0) {
if (maturity && maturity > 0) {
policyTypes += PolicyType.Maturity;
policies.push({ data: req.maturity, type: PolicyType.Maturity });
}
if (req.maxFee) {
policyTypes += PolicyType.MaxFee;
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
policies.push({ data: maturity, type: PolicyType.Maturity });
}

policyTypes += PolicyType.MaxFee;
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });

return {
policyTypes,
policies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('autoRetryFetch', () => {

expect(fn).toHaveBeenCalledTimes(1);
expect(result).toBeFalsy();
expect(error).toMatch(/anything/);
expect(error?.message).toMatch(/anything/);
});

it('should retry until maxRetries and fail', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/providers/utils/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ export function calculateMetadataGasForTxScript({
}

export interface CalculateGasFeeParams {
tip: BN;
tip?: BN;
gas: BN;
gasPrice: BN;
priceFactor: BN;
}

export const calculateGasFee = (params: CalculateGasFeeParams) => {
const { gas, gasPrice, priceFactor, tip } = params;
return gas.mul(gasPrice).div(priceFactor).add(tip);
return gas.mul(gasPrice).div(priceFactor).add(bn(tip));
};
67 changes: 65 additions & 2 deletions packages/fuel-gauge/src/policies.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { generateTestWallet } from '@fuel-ts/account/test-utils';
import type { BigNumberish, Transaction, WalletUnlocked } from 'fuels';
import type { BaseTransactionRequest, BigNumberish, Transaction, WalletUnlocked } from 'fuels';
import {
ContractFactory,
CreateTransactionRequest,
FUEL_NETWORK_URL,
PolicyType,
Provider,
Expand Down Expand Up @@ -58,6 +59,68 @@ describe('Policies', () => {
expect(bn(transaction.policies?.[3]?.data).lte(bn(params.maxFee))).toBeTruthy();
};

it('should ensure optional TX policies are not set when not informed', () => {
let txRequest: BaseTransactionRequest = new ScriptTransactionRequest();

txRequest = new ScriptTransactionRequest();

expect(txRequest.tip).toBeUndefined();
expect(txRequest.maturity).toBeUndefined();
expect(txRequest?.witnessLimit).toBeUndefined();

expect(txRequest.maxFee).toBeDefined();

let tx = txRequest.toTransaction();

// should only includes MaxFee which is a required policy
expect(tx.policies.length).toBe(1);
expect(tx.policyTypes).toBe(PolicyType.MaxFee);

txRequest = new CreateTransactionRequest({ bytecodeWitnessIndex: 0 });

expect(txRequest.tip).toBeUndefined();
expect(txRequest.maturity).toBeUndefined();
expect(txRequest?.witnessLimit).toBeUndefined();

expect(txRequest.maxFee).toBeDefined();

tx = txRequest.toTransaction();

// should only includes MaxFee which is a required policy
expect(tx.policies.length).toBe(1);
expect(tx.policyTypes).toBe(PolicyType.MaxFee);
});

it('should ensure optional TX policies are not set with undesired values', () => {
let txRequest: BaseTransactionRequest = new ScriptTransactionRequest({ tip: 0, maturity: 0 });

txRequest = new ScriptTransactionRequest();

expect(txRequest.tip).toBeUndefined();
expect(txRequest.maturity).toBeUndefined();

expect(txRequest.maxFee).toBeDefined();

let tx = txRequest.toTransaction();

// should only includes maxFee which is a required policy
expect(tx.policies.length).toBe(1);
expect(tx.policyTypes).toBe(PolicyType.MaxFee);

txRequest = new CreateTransactionRequest({ tip: 0, maturity: 0, bytecodeWitnessIndex: 0 });

expect(txRequest.tip).toBeUndefined();
expect(txRequest.maturity).toBeUndefined();

expect(txRequest.maxFee).toBeDefined();

tx = txRequest.toTransaction();

// should only includes maxFee which is a required policy
expect(tx.policies.length).toBe(1);
expect(tx.policyTypes).toBe(PolicyType.MaxFee);
});

it('should ensure TX policies are properly set (ScriptTransactionRequest)', async () => {
const receiver = Wallet.generate({ provider });

Expand Down Expand Up @@ -237,7 +300,7 @@ describe('Policies', () => {

const txParams: CustomTxParams = {
maturity: randomNumber(1, 2),
witnessLimit: 5,
witnessLimit: 0,
};

await expect(async () => {
Expand Down
Loading

0 comments on commit 1b20fc8

Please sign in to comment.