Skip to content

Commit

Permalink
Merge branch 'master' into ps/chore/migrate-release
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya authored Jan 29, 2025
2 parents ca4b926 + 45cc32e commit 4323a65
Show file tree
Hide file tree
Showing 39 changed files with 377 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .changeset/grumpy-lamps-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

ci(deps): bump dawidd6/action-download-artifact from 7 to 8
4 changes: 4 additions & 0 deletions .changeset/hungry-rivers-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: added validation for toolchain versions
5 changes: 5 additions & 0 deletions .changeset/loud-deers-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

feat: add `forc` tests to create fuels
7 changes: 7 additions & 0 deletions .changeset/ten-boats-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@internal/fuel-core": patch
"@fuel-ts/versions": patch
"@fuel-ts/account": patch
---

chore: upgrade `fuel-core` to `0.40.4`
5 changes: 5 additions & 0 deletions .changeset/three-taxis-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

feat: enable `fuels` callbacks to be asynchronous
21 changes: 20 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ jobs:
env:
PUBLISHED_NPM_TAG: next

forc:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Setup
uses: ./.github/actions/test-setup

- name: Setup forc and fuel-core paths
shell: bash
run: |
echo "$PWD/internal/forc/forc-binaries" >> $GITHUB_PATH
echo "$PWD/internal/fuel-core/fuel-core-binaries" >> $GITHUB_PATH
- name: Run Tests
run: pnpm test:forc

e2e:
runs-on: ubuntu-latest
timeout-minutes: 25
Expand Down Expand Up @@ -155,7 +174,7 @@ jobs:
path: coverage/report

- name: Download Master Coverage Artifact
uses: dawidd6/action-download-artifact@v7
uses: dawidd6/action-download-artifact@v8
if: ${{ steps.findPr.outputs.number }}
with:
workflow: test.yaml
Expand Down
1 change: 1 addition & 0 deletions .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-2.ts"
],
"ignore": [".github/**"],
"ignoreBinaries": ["forc"],
"ignoreDependencies": [
"fuels",
"bun",
Expand Down
2 changes: 1 addition & 1 deletion apps/create-fuels-counter-guide/fuel-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ channel = "testnet"

[components]
forc = "0.66.6"
fuel-core = "0.40.2"
fuel-core = "0.40.4"
1 change: 1 addition & 0 deletions apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"test:ui": "sh ./test/ui/test-ui.sh",
"test:forc": "forc test --path ./sway-programs",
"original:dev": "vite",
"original:build": "tsc -b && vite build",
"original:start": "vite start",
Expand Down
33 changes: 33 additions & 0 deletions apps/create-fuels-counter-guide/sway-programs/contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,36 @@ impl Counter for Contract {
}
}
// #endregion create-fuels-counter-guide-impl

#[test]
fn should_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let expected = 0;

let actual = contract_instance.get_count();

assert(actual == expected);
}

#[test]
fn should_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let expected = count_before + 1;

let count_after = contract_instance.increment_counter(1);

assert(count_after == expected);
}

// #region create-fuels-counter-guide-sway-contract-test
#[test]
fn test_decrement_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let _ = contract_instance.increment_counter(5);

let count_before = contract_instance.get_count();
let count_after = contract_instance.decrement_counter(1);
assert(count_after == count_before - 1);
}
// #endregion create-fuels-counter-guide-sway-contract-test
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@ configurable {
fn main(pin: u64) -> bool {
return PIN == pin;
}

#[test]
fn should_return_true_when_password_is_1337() {
let expected = true;

let actual = main(1337);

assert(actual == expected);
}

#[test]
fn should_return_false_when_password_is_not_1337() {
let expected = false;

let actual = main(1338);

assert(actual == expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn should_return_input() {
let expected = 1234;

let actual = main(1234);

assert(actual == expected);
}
10 changes: 5 additions & 5 deletions apps/demo-fuels/fuels.config.full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ export default createConfig({
// #endregion deployConfig-fn

// #region onBuild
onBuild: (config: FuelsConfig) => {
onBuild: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onBuild', { config });
},
// #endregion onBuild

// #region onDeploy
onDeploy: (config: FuelsConfig, data: DeployedData) => {
onDeploy: (config: FuelsConfig, data: DeployedData): void | Promise<void> => {
console.log('fuels:onDeploy', { config, data });
},
// #endregion onDeploy

// #region onDev
onDev: (config: FuelsConfig) => {
onDev: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onDev', { config });
},
// #endregion onDev

// #region onNode
onNode: (config: FuelsConfig) => {
onNode: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onNode', { config });
},
// #endregion onNode

// #region onFailure
onFailure: (config: FuelsConfig, error: Error) => {
onFailure: (config: FuelsConfig, error: Error): void | Promise<void> => {
console.log('fuels:onFailure', { config, error });
},
// #endregion onFailure
Expand Down
14 changes: 13 additions & 1 deletion apps/docs/src/guide/creating-a-fuel-dapp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,19 @@ You can find the complete source code of the dApp we built [here](https://github

Whenever you want to add a new feature to your dApp and quickly prototype things, you can follow the same steps we followed in this guide.

### 3. Extending the Test Suite (Optional)
### 3. Extending the contract testing suite (Optional)

Testing our smart contract is a good practice to ensure that our implementation is working as expected. It also give assurances down the line if we decide to change the implementation of our contract.

We write our test in the `#[test]` macro within our Sway contract, these can be inline within our Sway contract or in a separate file.

For the guide, we'll add a test for our new `decrement_counter` function in the `./sway-programs/contract/src/main.sw` file:

<<< @/../../create-fuels-counter-guide/sway-programs/contract/src/main.sw#create-fuels-counter-guide-sway-contract-test{rust:line-numbers}

After writing our test, we can run either using `forc test` or via PNPM using `pnpm test:forc`.

### 4. Extending the integration test suite (Optional)

Testing the integration with your smart contract isn't essential, but it's good practice to ensure that your application is working as expected. It also gives you the ability to test your application in a controlled environment against a local node.

Expand Down
2 changes: 1 addition & 1 deletion internal/fuel-core/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.40.2
0.40.4
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test:browser:filter": "vitest --run --coverage false --config vitest.browser.config.mts",
"test:e2e": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --e2e)",
"test:integration": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --integration)",
"test:forc": "turbo run test:forc",
"test:network": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --network)",
"lint": "run-s type:check-tests lint:check prettier:check type:check",
"lint:check": "eslint . --ext .ts --max-warnings 0",
Expand Down
33 changes: 32 additions & 1 deletion packages/account/src/providers/fuel-core-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ enum ContractParametersVersion {
V1
}

type DaCompressedBlock {
bytes: HexString!
}

union DependentCost = LightOperation | HeavyOperation

type DryRunFailureStatus {
Expand Down Expand Up @@ -809,8 +813,11 @@ type NodeInfo {
utxoValidation: Boolean!
vmBacktrace: Boolean!
maxTx: U64!
maxGas: U64!
maxSize: U64!
maxDepth: U64!
nodeVersion: String!
txPoolStats: TxPoolStats!
peers: [PeerInfo!]!
}

Expand Down Expand Up @@ -1039,7 +1046,8 @@ type Query {
"""
The list of requested assets` coins with asset ids, `target` amount the user
wants to reach, and the `max` number of coins in the selection. Several
entries with the same asset id are not allowed.
entries with the same asset id are not allowed. The result can't contain
more coins than `max_inputs`.
"""
queryPerAsset: [SpendQueryElementInput!]!

Expand All @@ -1048,6 +1056,12 @@ type Query {
"""
excludedIds: ExcludeInput
): [[CoinType!]!]!
daCompressedBlock(
"""
Height of the block
"""
height: U32!
): DaCompressedBlock
contract(
"""
ID of the Contract
Expand Down Expand Up @@ -1383,6 +1397,23 @@ enum TxParametersVersion {

scalar TxPointer

type TxPoolStats {
"""
The number of transactions in the pool
"""
txCount: U64!

"""
The total size of the transactions in the pool
"""
totalSize: U64!

"""
The total gas of the transactions in the pool
"""
totalGas: U64!
}

scalar U16

scalar U32
Expand Down
6 changes: 6 additions & 0 deletions packages/account/src/providers/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,12 @@ query getMessages(
}
}

query daCompressedBlock($height: U32!) {
daCompressedBlock(height: $height) {
bytes
}
}

query getMessageProof(
$transactionId: TransactionId!
$nonce: Nonce!
Expand Down
27 changes: 26 additions & 1 deletion packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expectToThrowFuelError, safeExec } from '@fuel-ts/errors/test-utils';
import { BN, bn } from '@fuel-ts/math';
import type { Receipt } from '@fuel-ts/transactions';
import { InputType, OutputType, ReceiptType } from '@fuel-ts/transactions';
import { DateTime, arrayify, sleep } from '@fuel-ts/utils';
import { DateTime, arrayify, hexlify, sleep } from '@fuel-ts/utils';
import { ASSET_A, ASSET_B } from '@fuel-ts/utils/test-utils';
import { versions } from '@fuel-ts/versions';

Expand Down Expand Up @@ -2462,4 +2462,29 @@ describe('Provider', () => {
code: ErrorCode.SCRIPT_REVERTED,
});
});

it('can get compressed block bytes', async () => {
const bytes = hexlify(randomBytes(32));

using launched = await setupTestProviderAndWallets();
const { provider } = launched;

// Should return null when block is not found
let compressed = await provider.daCompressedBlock('1');

expect(compressed).toBeNull();

vi.spyOn(provider, 'daCompressedBlock').mockImplementationOnce(async () =>
Promise.resolve({
bytes,
})
);

const block = await provider.getBlock('latest');
compressed = await provider.daCompressedBlock(String(block?.height));

expect(compressed).toStrictEqual({ bytes });

vi.restoreAllMocks();
});
});
18 changes: 18 additions & 0 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,24 @@ export default class Provider {
return { transactions, pageInfo };
}

/**
* Fetches a compressed block at the specified height.
*
* @param height - The height of the block to fetch.
* @returns The compressed block if available, otherwise `null`.
*/
async daCompressedBlock(height: string) {
const { daCompressedBlock } = await this.operations.daCompressedBlock({
height,
});

if (!daCompressedBlock) {
return null;
}

return daCompressedBlock;
}

/**
* Get deployed contract with the given ID.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/create-fuels/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('CLI', { timeout: 15_000 }, () => {
expect(toolchain).toEqual({ channel: 'testnet' });
expect(components).toEqual({
forc: '0.66.6',
'fuel-core': '0.40.2',
'fuel-core': '0.40.4',
});
});

Expand Down
Loading

0 comments on commit 4323a65

Please sign in to comment.