Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Browse files Browse the repository at this point in the history
…/chore/fix-coverage-report
  • Loading branch information
danielbate committed Jun 13, 2024
2 parents 2aac021 + 4ba32d1 commit f6f9efc
Show file tree
Hide file tree
Showing 46 changed files with 402 additions and 241 deletions.
2 changes: 2 additions & 0 deletions .changeset/cold-avocados-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/gold-rice-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 7 additions & 0 deletions .changeset/good-lobsters-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/abi-typegen": minor
"@fuel-ts/abi-coder": minor
"@fuel-ts/program": patch
---

feat!: remove redundant exports from `v1` encoding
5 changes: 5 additions & 0 deletions .changeset/heavy-cobras-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": minor
---

chore!: rename Provider `call` to `dryRun`
5 changes: 5 additions & 0 deletions .changeset/light-paws-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

chore: add test to validate mint transactions serialization
6 changes: 6 additions & 0 deletions .changeset/tasty-pens-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": minor
"fuels": minor
---

fix!: updated chain assets, removed `beta-5` network
5 changes: 5 additions & 0 deletions .changeset/weak-ravens-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-coder": patch
---

chore: validate incorrect case key for `EnumCoder`
6 changes: 3 additions & 3 deletions .github/workflows/pr-validate-changesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ jobs:

- name: Commit Changeset
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "build: update dependency changeset [skip ci]"
git commit -m "build: update dependency changeset"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}

validate-changeset:
name: Validate PR Changeset
Expand Down
3 changes: 2 additions & 1 deletion .textlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"https://testnet.fuel.network/",
"https://faucet-testnet.fuel.network/",
"https://thebitcoinmanual.com/**",
"https://forum.fuel.network/"
"https://forum.fuel.network/",
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Contract } from 'fuels';
import { bn, getMintedAssetId } from 'fuels';

import { DocSnippetProjectsEnum } from '../../../test/fixtures/forc-projects';
import { createAndDeployContractFromProject } from '../../utils';

/**
* @group node
*/
describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.TOKEN);
});

it('should successfully execute contract call with forwarded amount', async () => {
// #region minted-token-asset-id-2
// #import { bn, getMintedAssetId };

// Any valid bits256 string can be used as a sub ID
const subID = '0xc7fd1d987ada439fc085cfa3c49416cf2b504ac50151e3c2335d60595cb90745';
const mintAmount = bn(1000);

const txResult = await contract.functions.mint_coins(subID, mintAmount).call();

const mintedAssetId = getMintedAssetId(subID, contract.id.toB256());
// #endregion minted-token-asset-id-2

expect(mintedAssetId).toBeDefined();
expect(txResult.transactionResult.isStatusSuccess).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe(__filename, () => {

transactionRequest.addResources(resources);

const dryrunResult = await provider.call(transactionRequest);
const dryrunResult = await provider.dryRun(transactionRequest);

const returnReceipt = dryrunResult.receipts.find(
(receipt) => receipt.type === ReceiptType.ReturnData
Expand Down
62 changes: 49 additions & 13 deletions apps/docs-snippets/src/guide/types/enums.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Contract } from 'fuels';
import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
import { FuelError, type Contract } from 'fuels';

import { DocSnippetProjectsEnum } from '../../../test/fixtures/forc-projects';
import { createAndDeployContractFromProject } from '../../utils';
Expand All @@ -14,36 +15,71 @@ describe(__filename, () => {
});

it('should successfully echo a simple enum in a contract call', async () => {
// #region enum-3
// #region simple-enum-3
const enumVariant = 'Completed';

const { value } = await contract.functions.echo_state_error_enum(enumVariant).simulate();

expect(value).toEqual(enumVariant);
// #endregion enum-3
// #endregion simple-enum-3
});

it('should successfully echo a enum in a contract call (UserError Enum)', async () => {
// #region enum-6
const userErroVar = 'InsufficientPermissions';

const enumParam = { UserError: userErroVar };
// #region enum-of-enums-3
const enumParam = { UserError: 'InsufficientPermissions' };

const { value } = await contract.functions.echo_error_enum(enumParam).simulate();

expect(value).toEqual(enumParam);
// #endregion enum-6
// #endregion enum-of-enums-3
});

it('should successfully echo a enum in a contract call (StateError Enum)', async () => {
// #region enum-7
const stateErrorVar = 'Completed';

const enumParam = { StateError: stateErrorVar };
// #region enum-of-enums-4
const enumParam = { StateError: 'Completed' };

const { value } = await contract.functions.echo_error_enum(enumParam).simulate();

expect(value).toEqual(enumParam);
// #endregion enum-7
// #endregion enum-of-enums-4
});

it('should throw when enum value is not the correct type', async () => {
// #region enum-error-mismatch-type
// Valid types: string
const emumValue: number = 1;

await expectToThrowFuelError(
() => contract.functions.echo_state_error_enum(emumValue).simulate(),
new FuelError(FuelError.CODES.INVALID_DECODE_VALUE, 'A field for the case must be provided.')
);
// #endregion enum-error-mismatch-type
});

it('should throw when enum value is not present in Sway enum values', async () => {
// #region enum-error-value-mismatch
// Valid values: 'Void', 'Pending', 'Completed'
const emumValue = 'NotStateEnumValue';

await expectToThrowFuelError(
() => contract.functions.echo_state_error_enum(emumValue).simulate(),
new FuelError(FuelError.CODES.INVALID_DECODE_VALUE, 'Only one field must be provided.')
);
// #endregion enum-error-value-mismatch
});

it('should throw when using incorrect key for enum of enums', async () => {
// #region enum-error-case-key-mismatch
// Valid case keys: 'StateError', 'UserError'
const enumParam = { UnknownKey: 'Completed' };

await expectToThrowFuelError(
() => contract.functions.echo_error_enum(enumParam).simulate(),
new FuelError(
FuelError.CODES.INVALID_DECODE_VALUE,
`Invalid case 'UnknownKey'. Valid cases: 'StateError', 'UserError'.`
)
);
// #endregion enum-error-case-key-mismatch
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe(__filename, () => {
// #endregion encrypting-and-decrypting-json-wallets-2

expect(myBalance).toBeDefined();
});
}, 10000);

it('should validate that fs was imported on this file', () => {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
contract;

// #region enum-1
// #region enum-4
// #region simple-enum-1
// #region enum-of-enums-1
pub enum StateError {
Void: (),
Pending: (),
Completed: (),
}
// #endregion enum-1
// #endregion simple-enum-1

pub enum UserError {
Unauthorized: (),
Expand All @@ -18,7 +18,7 @@ pub enum Error {
StateError: StateError,
UserError: UserError,
}
// #endregion enum-4
// #endregion enum-of-enums-1

abi EchoEnum {
fn echo_state_error_enum(state_error: StateError) -> StateError;
Expand All @@ -29,18 +29,18 @@ abi EchoEnum {
}

impl EchoEnum for Contract {
// #region enum-2
// #region simple-enum-2
fn echo_state_error_enum(state_error: StateError) -> StateError {
state_error
}
// #endregion enum-2
// #endregion simple-enum-2
fn echo_user_error_enum(user_error: UserError) -> UserError {
user_error
}

// #region enum-5
// #region enum-of-enums-2
fn echo_error_enum(error: Error) -> Error {
error
}
// #endregion enum-5
// #endregion enum-of-enums-2
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// #region minted-token-asset-id-1
contract;

use std::asset::{burn, mint, transfer};
Expand Down Expand Up @@ -27,3 +28,4 @@ impl Token for Contract {
burn(sub_id, burn_amount);
}
}
// #endregion minted-token-asset-id-1
4 changes: 4 additions & 0 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export default defineConfig({
text: 'Configurable Constants',
link: '/guide/contracts/configurable-constants',
},
{
text: 'Minted Token Asset ID',
link: '/guide/contracts/minted-token-asset-id',
},
{
text: 'Managing Deployed Contracts',
link: '/guide/contracts/managing-deployed-contracts',
Expand Down
20 changes: 20 additions & 0 deletions apps/docs/src/guide/contracts/minted-token-asset-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minted Token Asset ID

The asset ID of a token on the Fuel network is determined by two factors:

- The ID of the contract that minted the token,
- A sub-identifier (Sub ID)

> Both of which are [bits256](../types/bits256.md) strings.
The process involves applying a SHA-256 hash algorithm to the combination of the Contract ID and the Sub ID, to derive an Asset ID - as explained [here](https://docs.fuel.network/docs/specs/identifiers/asset/#asset-id).

Consider the following simplified token contract:

<<< @/../../docs-snippets/test/fixtures/forc-projects/token/src/main.sw#minted-token-asset-id-1{rs:line-numbers}

Imagine that this contract is already deployed and we are about to mint some coins:

<<< @/../../docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts#minted-token-asset-id-2{ts:line-numbers}

Since the asset ID depends on the contract ID, which is always dynamic (unlike the sub ID, which can be set to a fixed value), the helper `getMintedAssetId` can be used to easily obtain the asset ID for a given contract ID and sub ID.
2 changes: 1 addition & 1 deletion apps/docs/src/guide/cookbook/generate-fake-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Below is an example script that returns the value `1337`. You can use fake resou

<<< @/../../docs-snippets/test/fixtures/forc-projects/return-script/src/main.sw#generate-fake-resources-1{rust:line-numbers}

To execute a dry-run, use the `Provider.call` method. Ensure you set the `utxo_validation` flag to true, as this script uses fake UTXOs:
To execute a dry-run, use the `Provider.dryRun` method. Ensure you set the `utxo_validation` flag to true, as this script uses fake UTXOs:

<<< @/../../docs-snippets/src/guide/cookbook/generate-fake-resources.test.ts#generate-fake-resources-2{ts:line-numbers}

Expand Down
8 changes: 7 additions & 1 deletion apps/docs/src/guide/errors/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ When the value is more than the max value.

Ensure that the value is less than the max value.

## `INVALID_DECODE_VALUE`

When you provide an incorrect value to contract, these are documented under [Enums](../types/enums.md#errors).

Ensure that the value (and type) matches the expected format.

## `INVALID_ENTROPY`

When the entropy is not: between 16 and 32 bytes; a multiple of 4.
Expand Down Expand Up @@ -251,4 +257,4 @@ It could be that the passphrase is incorrect and/or the wallet does _not_ exist
## `HASHER_LOCKED`

The hashing algorithm is currently locked, any subsequent attempts to register a new implementation will throw this error.
The purpose of the lock function is to provide a way to ensure that the implementation of the specific hashing algorithm cannot be changed once it is locked. This can be useful in scenarios where you want to guarantee the integrity and consistency of the hashing function throughout your application.
The purpose of the lock function is to provide a way to ensure that the implementation of the specific hashing algorithm cannot be changed once it is locked. This can be useful in scenarios where you want to guarantee the integrity and consistency of the hashing function throughout your application.
Loading

0 comments on commit f6f9efc

Please sign in to comment.