From b41e9590f7cda4a84fd83919911c73df0fbe332c Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 3 Sep 2024 16:18:52 +0100 Subject: [PATCH 1/4] chore: adding type checking (#3046) * chore: added ts check for docs-snippets * chore: added typechecking for the packages * fix: integration test * Added pid * fuel-gauge: wip * chore: appease the lint gods * chore: added missing type checking * chore: changeset * chore: changeset * chore: fixed import * Removed unnecessary arguments * chore: fix error with coder * chore: lint * chore: moved type checking to lint hook --- .changeset/odd-seahorses-learn.md | 4 ++ apps/docs-snippets/package.json | 5 ++- .../src/guide/types/arrays.test.ts | 1 + .../src/guide/types/contract-types.test.ts | 16 +++++--- .../src/guide/types/enums.test.ts | 3 ++ .../src/guide/types/vector.test.ts | 2 +- .../src/guide/wallets/connectors.test.ts | 7 +++- apps/docs-snippets/src/jsonc.d.ts | 5 +++ package.json | 3 +- .../src/encoding/coders/NumberCoder.test.ts | 1 + .../strategies/getCoderForEncoding.test.ts | 5 ++- .../src/utils/parseTypeArguments.test.ts | 2 +- packages/abi-typegen/tsconfig.json | 3 +- packages/contract/tsconfig.json | 2 +- packages/create-fuels/package.json | 4 +- packages/fuel-gauge/package.json | 5 ++- .../fuel-gauge/src/bytecode-sway-lib.test.ts | 13 ++----- packages/fuel-gauge/src/vectors.test.ts | 17 +++++---- .../fuel-gauge/test/fixtures/abi/predicate.ts | 38 ------------------- .../test/fixtures/bytecode/predicate.ts | 2 - .../bytecode-sway-lib/src/main.sw | 2 +- packages/fuel-gauge/tsconfig.json | 2 +- packages/fuels/package.json | 4 +- packages/logger/test/index.test.ts | 5 ++- packages/logger/test/utils.test.ts | 4 +- packages/logger/tsconfig.json | 2 +- packages/utils/tsconfig.json | 2 +- packages/versions/src/cli.test.ts | 14 +++++++ tsconfig.test.json | 8 ++++ 29 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 .changeset/odd-seahorses-learn.md create mode 100644 apps/docs-snippets/src/jsonc.d.ts delete mode 100644 packages/fuel-gauge/test/fixtures/abi/predicate.ts delete mode 100644 packages/fuel-gauge/test/fixtures/bytecode/predicate.ts create mode 100644 tsconfig.test.json diff --git a/.changeset/odd-seahorses-learn.md b/.changeset/odd-seahorses-learn.md new file mode 100644 index 00000000000..1e170e28704 --- /dev/null +++ b/.changeset/odd-seahorses-learn.md @@ -0,0 +1,4 @@ +--- +--- + +chore: adding type checking diff --git a/apps/docs-snippets/package.json b/apps/docs-snippets/package.json index 3929d9d870d..f1d1b3eaf97 100644 --- a/apps/docs-snippets/package.json +++ b/apps/docs-snippets/package.json @@ -4,8 +4,9 @@ "description": "", "private": true, "scripts": { - "pretest": "pnpm build:forc", - "build:forc": "pnpm fuels build" + "pretest": "run-s build:forc type:check", + "build:forc": "pnpm fuels build", + "type:check": "tsc --noEmit" }, "devDependencies": { "@fuel-ts/account": "workspace:*", diff --git a/apps/docs-snippets/src/guide/types/arrays.test.ts b/apps/docs-snippets/src/guide/types/arrays.test.ts index 1872e93a786..99fbc78f175 100644 --- a/apps/docs-snippets/src/guide/types/arrays.test.ts +++ b/apps/docs-snippets/src/guide/types/arrays.test.ts @@ -58,6 +58,7 @@ describe('Arrays Types', () => { contracts: [contract], } = launched; try { + // @ts-expect-error Will throw error because the array length is not 2 // #region arrays-3 // will throw error because the array length is not 2 await contract.functions.echo_u64_array([10000000]).simulate(); diff --git a/apps/docs-snippets/src/guide/types/contract-types.test.ts b/apps/docs-snippets/src/guide/types/contract-types.test.ts index 1c3bae0d668..0d17a7f0d9e 100644 --- a/apps/docs-snippets/src/guide/types/contract-types.test.ts +++ b/apps/docs-snippets/src/guide/types/contract-types.test.ts @@ -2,6 +2,11 @@ import { Address } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; import { InputOutputTypesFactory } from '../../../test/typegen'; +import type { + IdentityOutput, + AddressOutput, + ContractIdOutput, +} from '../../../test/typegen/contracts/InputOutputTypes'; /** * @group node @@ -87,9 +92,9 @@ describe('Contract Types', () => { // #region identity-address-output // #import { Address }; - const identityFromOutput1 = callResponse1.value; - const addressStringFromOutput = identityFromOutput1.Address.bits; - const addressFromOutput: Address = Address.fromB256(addressStringFromOutput); + const identityFromOutput1: IdentityOutput = callResponse1.value; + const addressStringFromOutput: AddressOutput = identityFromOutput1.Address as AddressOutput; + const addressFromOutput: Address = Address.fromB256(addressStringFromOutput.bits); // #endregion identity-address-output // #region identity-contract-input @@ -100,8 +105,9 @@ describe('Contract Types', () => { const callResponse2 = await contract.functions.identity(contractIdentityInput).simulate(); // #region identity-contract-output - const identityFromOutput2 = callResponse2.value; - const contractIdFromOutput: string = identityFromOutput2.ContractId.bits; + const identityFromOutput2: IdentityOutput = callResponse2.value; + const contractIdOutput: ContractIdOutput = identityFromOutput2.ContractId as ContractIdOutput; + const contractIdFromOutput: string = contractIdOutput.bits; // #endregion identity-contract-output expect(addressFromOutput).toEqual(address); diff --git a/apps/docs-snippets/src/guide/types/enums.test.ts b/apps/docs-snippets/src/guide/types/enums.test.ts index b06280917fd..2d56bf0cfb4 100644 --- a/apps/docs-snippets/src/guide/types/enums.test.ts +++ b/apps/docs-snippets/src/guide/types/enums.test.ts @@ -98,6 +98,7 @@ describe('Enums Types', () => { const emumValue: number = 1; await expectToThrowFuelError( + // @ts-expect-error number is not a valid type () => contract.functions.echo_state_error_enum(emumValue).simulate(), new FuelError(FuelError.CODES.INVALID_DECODE_VALUE, 'A field for the case must be provided.') ); @@ -122,6 +123,7 @@ describe('Enums Types', () => { const emumValue = 'NotStateEnumValue'; await expectToThrowFuelError( + // @ts-expect-error NotStateEnumValue is not a valid value () => contract.functions.echo_state_error_enum(emumValue).simulate(), new FuelError(FuelError.CODES.INVALID_DECODE_VALUE, 'Only one field must be provided.') ); @@ -146,6 +148,7 @@ describe('Enums Types', () => { const enumParam = { UnknownKey: 'Completed' }; await expectToThrowFuelError( + // @ts-expect-error UnknownKey is not a valid key () => contract.functions.echo_error_enum(enumParam).simulate(), new FuelError( FuelError.CODES.INVALID_DECODE_VALUE, diff --git a/apps/docs-snippets/src/guide/types/vector.test.ts b/apps/docs-snippets/src/guide/types/vector.test.ts index a3766e34706..c8e3b2b5f4f 100644 --- a/apps/docs-snippets/src/guide/types/vector.test.ts +++ b/apps/docs-snippets/src/guide/types/vector.test.ts @@ -78,7 +78,7 @@ describe('Vector Types', () => { // #import { arrayify }; // #context import { BytecodeInputFactory } from '../path/to/typegen'; - const bytecodeAsVecU8 = arrayify(BytecodeInputFactory.bytecode); + const bytecodeAsVecU8 = Array.from(arrayify(BytecodeInputFactory.bytecode)); const { waitForResult } = await bytecodeContract.functions .compute_bytecode_root(bytecodeAsVecU8) diff --git a/apps/docs-snippets/src/guide/wallets/connectors.test.ts b/apps/docs-snippets/src/guide/wallets/connectors.test.ts index e06ca8ba839..ff7dce6832e 100644 --- a/apps/docs-snippets/src/guide/wallets/connectors.test.ts +++ b/apps/docs-snippets/src/guide/wallets/connectors.test.ts @@ -121,8 +121,11 @@ class WalletConnector extends FuelConnector { // #region fuel-connector-events-abis const abis: Array = [ { - encoding: '1', - types: [], + encodingVersion: '1', + specVersion: '1', + programType: 'contract', + concreteTypes: [], + metadataTypes: [], loggedTypes: [], functions: [], messagesTypes: [], diff --git a/apps/docs-snippets/src/jsonc.d.ts b/apps/docs-snippets/src/jsonc.d.ts new file mode 100644 index 00000000000..08d542a11e4 --- /dev/null +++ b/apps/docs-snippets/src/jsonc.d.ts @@ -0,0 +1,5 @@ +// informs TS about `.jsonc` file extension +declare module '*.jsonc' { + const value: string; + export default value; +} diff --git a/package.json b/package.json index b938881d570..3da7ab5dc35 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,12 @@ "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)", - "lint": "run-s lint:check prettier:check", + "lint": "run-s type:check-tests lint:check prettier:check", "lint:check": "eslint . --ext .ts --max-warnings 0", "lint:fix": "pnpm lint:check --fix", "lint:md-links": "tsx ./scripts/lint-md-links", "lint:package-jsons": "tsx ./scripts/lint-package-jsons", + "type:check-tests": "tsc -p tsconfig.test.json", "prettier:check": "prettier --check packages --check apps/docs-snippets", "prettier:format": "prettier --write packages --check apps/docs-snippets", "verify:package-exports": "tsx ./scripts/verify-package-exports", diff --git a/packages/abi-coder/src/encoding/coders/NumberCoder.test.ts b/packages/abi-coder/src/encoding/coders/NumberCoder.test.ts index 836297e38be..e8fc4f9dec1 100644 --- a/packages/abi-coder/src/encoding/coders/NumberCoder.test.ts +++ b/packages/abi-coder/src/encoding/coders/NumberCoder.test.ts @@ -162,6 +162,7 @@ describe('NumberCoder', () => { const invalidNumber = 'u64'; await expectToThrowFuelError( + // @ts-expect-error Expected to throw error () => new NumberCoder(invalidNumber), new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${invalidNumber}`) ); diff --git a/packages/abi-coder/src/encoding/strategies/getCoderForEncoding.test.ts b/packages/abi-coder/src/encoding/strategies/getCoderForEncoding.test.ts index 15020c8859a..6f8a883271a 100644 --- a/packages/abi-coder/src/encoding/strategies/getCoderForEncoding.test.ts +++ b/packages/abi-coder/src/encoding/strategies/getCoderForEncoding.test.ts @@ -1,3 +1,4 @@ +import type { EncodingVersion } from '../../utils/constants'; import { ENCODING_V1 } from '../../utils/constants'; import { getCoderForEncoding } from './getCoderForEncoding'; @@ -17,6 +18,8 @@ describe('getEncodingStrategy', () => { }); it('throws for an unsupported encoding version', () => { - expect(() => getCoderForEncoding('2')).toThrowError('Encoding version 2 is unsupported.'); + expect(() => getCoderForEncoding('2' as EncodingVersion)).toThrowError( + 'Encoding version 2 is unsupported.' + ); }); }); diff --git a/packages/abi-typegen/src/utils/parseTypeArguments.test.ts b/packages/abi-typegen/src/utils/parseTypeArguments.test.ts index 8595704badb..a95ab37fc12 100644 --- a/packages/abi-typegen/src/utils/parseTypeArguments.test.ts +++ b/packages/abi-typegen/src/utils/parseTypeArguments.test.ts @@ -70,7 +70,7 @@ describe('parseTypeArguments.ts', () => { /* Test helpers */ - function bundleTypes(rawTypes = defautRawTypes) { + function bundleTypes(rawTypes: readonly JsonAbiType[] = defautRawTypes) { const types = rawTypes.map((rawAbiType) => makeType({ rawAbiType })); return types; } diff --git a/packages/abi-typegen/tsconfig.json b/packages/abi-typegen/tsconfig.json index b22c89a4b35..3bb5815acdc 100644 --- a/packages/abi-typegen/tsconfig.json +++ b/packages/abi-typegen/tsconfig.json @@ -3,5 +3,6 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["src", "test"] + "include": ["src", "test"], + "exclude": ["**/__temp__/**"] } diff --git a/packages/contract/tsconfig.json b/packages/contract/tsconfig.json index 7b3d19b35da..63307672aee 100644 --- a/packages/contract/tsconfig.json +++ b/packages/contract/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["src", "src/**/*.json"] + "include": ["src", "src/**/*.json", "test"] } diff --git a/packages/create-fuels/package.json b/packages/create-fuels/package.json index 38934a040d5..7fd1f8c1938 100644 --- a/packages/create-fuels/package.json +++ b/packages/create-fuels/package.json @@ -15,7 +15,9 @@ }, "license": "Apache-2.0", "scripts": { - "build": "tsup && tsc --noEmit", + "build": "run-s build:source type:check", + "build:source": "tsup", + "type:check": "tsc --noEmit", "prepublishOnly": "tsx ./scripts/prepublish.ts" }, "dependencies": { diff --git a/packages/fuel-gauge/package.json b/packages/fuel-gauge/package.json index 409d2a215d2..b4d765f06f9 100644 --- a/packages/fuel-gauge/package.json +++ b/packages/fuel-gauge/package.json @@ -5,9 +5,10 @@ "description": "", "author": "Fuel Labs (https://fuel.network/)", "scripts": { - "pretest": "run-s build:forc build:process-predicates", + "pretest": "run-s build:forc build:process-predicates type:check", "build:forc": "pnpm fuels build", - "build:process-predicates": "tsx ./scripts/process-predicates.ts" + "build:process-predicates": "tsx ./scripts/process-predicates.ts", + "type:check": "tsc --noEmit" }, "license": "Apache-2.0", "dependencies": { diff --git a/packages/fuel-gauge/src/bytecode-sway-lib.test.ts b/packages/fuel-gauge/src/bytecode-sway-lib.test.ts index 705bf2c0491..2469ca46337 100644 --- a/packages/fuel-gauge/src/bytecode-sway-lib.test.ts +++ b/packages/fuel-gauge/src/bytecode-sway-lib.test.ts @@ -1,8 +1,7 @@ -import { Predicate, arrayify } from 'fuels'; +import { arrayify } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; -import { defaultPredicateAbi } from '../test/fixtures/abi/predicate'; -import { defaultPredicateBytecode } from '../test/fixtures/bytecode/predicate'; +import { PredicateTrue } from '../test/typegen'; import { BytecodeSwayLibFactory } from '../test/typegen/contracts'; import { launchTestContract } from './utils'; @@ -58,16 +57,12 @@ describe('bytecode computations', () => { provider, } = launched; - const predicate = new Predicate({ - bytecode: defaultPredicateBytecode, - abi: defaultPredicateAbi, - provider, - }); + const predicate = new PredicateTrue({ provider }); const address = predicate.address; const { waitForResult } = await contract.functions - .compute_predicate_address(Array.from(arrayify(defaultPredicateBytecode))) + .compute_predicate_address(Array.from(arrayify(PredicateTrue.bytecode))) .call(); const { value } = await waitForResult(); diff --git a/packages/fuel-gauge/src/vectors.test.ts b/packages/fuel-gauge/src/vectors.test.ts index b05a665e8ae..9c94d76f40d 100644 --- a/packages/fuel-gauge/src/vectors.test.ts +++ b/packages/fuel-gauge/src/vectors.test.ts @@ -3,6 +3,7 @@ import type { BigNumberish, BN } from 'fuels'; import { VectorsFactory } from '../test/typegen/contracts'; import { SmallEnumInput } from '../test/typegen/contracts/CoverageContract'; +import type { Vec } from '../test/typegen/contracts/common'; import { launchTestContract } from './utils'; @@ -119,7 +120,7 @@ describe('Vector Tests', () => { it('should test (u8, u8) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT: Array<[BigNumberish, BigNumberish]> = [ + const INPUT: Vec<[BigNumberish, BigNumberish]> = [ [1, 2], [3, 4], [5, 6], @@ -136,7 +137,7 @@ describe('Vector Tests', () => { it('should test (u64, u64) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT: [BigNumberish, BigNumberish][] = [ + const INPUT: Vec<[BigNumberish, BigNumberish]> = [ [111, 2222], [333, 4445], [5555, 6], @@ -167,7 +168,7 @@ describe('Vector Tests', () => { it('should test [u64; 5] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT: Array<[BigNumberish, BigNumberish, BigNumberish, BigNumberish, BigNumberish]> = [ + const INPUT: Vec<[BigNumberish, BigNumberish, BigNumberish, BigNumberish, BigNumberish]> = [ [1, 2, 3, 4, 5], [500, 600, 700, 9000, 9999], [11500, 22600, 33700, 55000, 669999], @@ -182,7 +183,7 @@ describe('Vector Tests', () => { it('should test [bool; 2] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT: Array<[boolean, boolean]> = [ + const INPUT: Vec<[boolean, boolean]> = [ [true, true], [true, false], [false, true], @@ -282,7 +283,7 @@ describe('Vector Tests', () => { it('should test SmallEnum vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec = [ SmallEnumInput.Empty, SmallEnumInput.Empty, SmallEnumInput.Empty, @@ -403,7 +404,7 @@ describe('Vector Tests', () => { it('should test Vec and b256 tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT: [Array, string] = [[1, 8, 3, 2, 55, 215], hexlify(randomBytes(32))]; + const INPUT: [Vec, string] = [[1, 8, 3, 2, 55, 215], hexlify(randomBytes(32))]; const { waitForResult } = await contractInstance.functions .echo_vector_and_b256_tuple(...INPUT) @@ -416,7 +417,7 @@ describe('Vector Tests', () => { it('should test two vectors tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT: [Array, Array] = [ + const INPUT: [Vec, Vec] = [ [219, 229], [1, 254, 55], ]; @@ -432,7 +433,7 @@ describe('Vector Tests', () => { it('should test u32 and three different vectors tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT: [number, boolean[], number[], number[]] = [ + const INPUT: [BigNumberish, Vec, Vec, Vec] = [ 91000, [true, true, false], [95000, 153333], diff --git a/packages/fuel-gauge/test/fixtures/abi/predicate.ts b/packages/fuel-gauge/test/fixtures/abi/predicate.ts deleted file mode 100644 index e3413f6623a..00000000000 --- a/packages/fuel-gauge/test/fixtures/abi/predicate.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { JsonAbi } from 'fuels'; - -export const defaultPredicateAbi: JsonAbi = { - types: [ - { - typeId: 0, - type: 'bool', - components: null, - typeParameters: null, - }, - { - typeId: 1, - type: 'b256', - components: null, - typeParameters: null, - }, - ], - functions: [ - { - inputs: [ - { - name: 'data', - type: 1, - typeArguments: null, - }, - ], - name: 'main', - output: { - name: '', - type: 0, - typeArguments: null, - }, - attributes: null, - }, - ], - loggedTypes: [], - configurables: [], -}; diff --git a/packages/fuel-gauge/test/fixtures/bytecode/predicate.ts b/packages/fuel-gauge/test/fixtures/bytecode/predicate.ts deleted file mode 100644 index a6afa8bdd8d..00000000000 --- a/packages/fuel-gauge/test/fixtures/bytecode/predicate.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const defaultPredicateBytecode = - '0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'; diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/bytecode-sway-lib/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/bytecode-sway-lib/src/main.sw index 09d33c9eaf0..5aac2d0d056 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/bytecode-sway-lib/src/main.sw +++ b/packages/fuel-gauge/test/fixtures/forc-projects/bytecode-sway-lib/src/main.sw @@ -19,6 +19,6 @@ impl MyContract for Contract { } fn compute_predicate_address(bytecode: Vec) -> Address { - return Address::from(0x6b6ef590390f0a7de75f8275ab5d7877c17236caba2514039c6565ec15f79111); + return Address::from(0x68fec7a57e48f4ec6467d7e09c27272bd8ca72b312ea553a470b98731475ccf3); } } diff --git a/packages/fuel-gauge/tsconfig.json b/packages/fuel-gauge/tsconfig.json index b0fced27d72..b22c89a4b35 100644 --- a/packages/fuel-gauge/tsconfig.json +++ b/packages/fuel-gauge/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["src"] + "include": ["src", "test"] } diff --git a/packages/fuels/package.json b/packages/fuels/package.json index eebac33373d..0d4695d3f4d 100644 --- a/packages/fuels/package.json +++ b/packages/fuels/package.json @@ -55,7 +55,9 @@ "build:package": "tsup", "build:browser": "pnpm vite build", "build:minified": "pnpm uglifyjs --compress --mangle --output dist/browser.min.mjs -- dist/browser.mjs", - "postbuild": "tsc --emitDeclarationOnly -p tsconfig.dts.json", + "postbuild": "run-s type:declarations type:check", + "type:declarations": "tsc --emitDeclarationOnly -p tsconfig.dts.json", + "type:check": "tsc --noEmit", "prepublishOnly": "cp ../../README.md ./README.md" }, "license": "Apache-2.0", diff --git a/packages/logger/test/index.test.ts b/packages/logger/test/index.test.ts index d458df5e663..e23dfd920c8 100644 --- a/packages/logger/test/index.test.ts +++ b/packages/logger/test/index.test.ts @@ -1,14 +1,17 @@ import type { AbstractAddress } from '@fuel-ts/interfaces'; import { BN } from '@fuel-ts/math'; import debug from 'debug'; +import type { MockInstance } from 'vitest'; import { logger, prefixLogger, defaultLogger } from '../src/index'; +type Debug = typeof debug; + /** * @group node */ describe('Logger Tests', () => { - let debugSpy; + let debugSpy: MockInstance, ReturnType>; beforeEach(() => { debug.enable('test'); diff --git a/packages/logger/test/utils.test.ts b/packages/logger/test/utils.test.ts index aa90837ad35..f692cc8930a 100644 --- a/packages/logger/test/utils.test.ts +++ b/packages/logger/test/utils.test.ts @@ -10,7 +10,7 @@ describe('truncateWalletAddress Tests', () => { it('should correctly truncate a wallet address', () => { const mockAddress: Address = { toString: () => '0x1234567890abcdef1234567890abcdef', - }; + } as Address; const options = { prefixLength: 6, suffixLength: 4 }; const result = truncateWalletAddress(mockAddress, options); expect(result).toBe('0x1234…cdef'); @@ -19,7 +19,7 @@ describe('truncateWalletAddress Tests', () => { it('should handle default options if none provided', () => { const mockAddress: Address = { toString: () => '0x1234567890abcdef1234567890abcdef', - }; + } as Address; const result = truncateWalletAddress(mockAddress); expect(result).toBe('0x…cdef'); }); diff --git a/packages/logger/tsconfig.json b/packages/logger/tsconfig.json index b0fced27d72..b22c89a4b35 100644 --- a/packages/logger/tsconfig.json +++ b/packages/logger/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["src"] + "include": ["src", "test"] } diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json index b0fced27d72..b22c89a4b35 100644 --- a/packages/utils/tsconfig.json +++ b/packages/utils/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["src"] + "include": ["src", "test"] } diff --git a/packages/versions/src/cli.test.ts b/packages/versions/src/cli.test.ts index 64a905f40a1..a077b875380 100644 --- a/packages/versions/src/cli.test.ts +++ b/packages/versions/src/cli.test.ts @@ -23,8 +23,10 @@ describe('cli.js', () => { function mockAllDeps(params: { systemForcIsGt: boolean; systemForcIsEq: boolean; + systemForcIsLt: boolean; systemFuelCoreIsGt: boolean; systemFuelCoreIsEq: boolean; + systemFuelCoreIsLt: boolean; systemForcVersion: string; systemFuelCoreVersion: string; systemVersionsError: Error | null; @@ -34,8 +36,10 @@ describe('cli.js', () => { systemFuelCoreVersion, systemFuelCoreIsGt, systemFuelCoreIsEq, + systemFuelCoreIsLt, systemForcIsGt, systemForcIsEq, + systemForcIsLt, systemVersionsError, } = params; @@ -52,6 +56,8 @@ describe('cli.js', () => { systemFuelCoreIsGt, systemForcIsEq, systemFuelCoreIsEq, + systemForcIsLt, + systemFuelCoreIsLt, })); vi.spyOn(getSystemVersionsMod, 'getSystemVersions').mockImplementation(() => ({ @@ -85,8 +91,10 @@ describe('cli.js', () => { systemFuelCoreVersion: '1.1.1', systemFuelCoreIsGt: true, systemFuelCoreIsEq: false, + systemFuelCoreIsLt: false, systemForcIsGt: true, systemForcIsEq: false, + systemForcIsLt: false, systemVersionsError: null, }); @@ -106,8 +114,10 @@ describe('cli.js', () => { systemFuelCoreVersion: '1.0.0', systemFuelCoreIsGt: false, systemFuelCoreIsEq: true, + systemFuelCoreIsLt: false, systemForcIsGt: false, systemForcIsEq: true, + systemForcIsLt: false, systemVersionsError: null, }); @@ -127,8 +137,10 @@ describe('cli.js', () => { systemFuelCoreVersion: '0.0.1', systemFuelCoreIsGt: false, systemFuelCoreIsEq: false, + systemFuelCoreIsLt: true, systemForcIsGt: false, systemForcIsEq: false, + systemForcIsLt: true, systemVersionsError: null, }); @@ -150,8 +162,10 @@ describe('cli.js', () => { systemFuelCoreVersion: '0.0.1', systemFuelCoreIsGt: false, systemFuelCoreIsEq: false, + systemFuelCoreIsLt: false, systemForcIsGt: false, systemForcIsEq: false, + systemForcIsLt: false, systemVersionsError, }); diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 00000000000..0330aadf23a --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "noEmit": true + }, + "include": ["**/*.test.ts"], + "exclude": ["node_modules"] +} From b6b83f4366a96e33825ef782dd071084ef8fe6c2 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Tue, 3 Sep 2024 11:29:17 -0500 Subject: [PATCH 2/4] chore: add e2e tests for transaction summary operations (#2931) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> --- .changeset/lazy-lemons-suffer.md | 4 + .../src/transaction-summary.test.ts | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .changeset/lazy-lemons-suffer.md diff --git a/.changeset/lazy-lemons-suffer.md b/.changeset/lazy-lemons-suffer.md new file mode 100644 index 00000000000..ed2ccc43153 --- /dev/null +++ b/.changeset/lazy-lemons-suffer.md @@ -0,0 +1,4 @@ +--- +--- + +chore: add e2e tests for transaction summary operations \ No newline at end of file diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index 856ac089b1c..4943039e24f 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -16,6 +16,9 @@ import { Wallet, AddressType, OperationName, + Address, + ChainName, + bn, OutputType, } from 'fuels'; import { ASSET_A, ASSET_B, launchTestNode, TestMessage } from 'fuels/test-utils'; @@ -728,5 +731,79 @@ describe('TransactionSummary', () => { ], }); }); + + it('should ensure contract call operations are correctly assembled [WITHDRAW TO BASE LAYER]', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [sender], + } = launched; + + const recipient = Address.fromB256( + '0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263' + ); + + const amountToWithdraw = 10; + + const tx = await sender.withdrawToBaseLayer(recipient, amountToWithdraw); + const result = await tx.waitForResult(); + + const { operations } = result; + + expect(operations[0].name).toEqual(OperationName.withdrawFromFuel); + expect(operations[0].from?.type).toEqual(AddressType.account); + expect(operations[0].from?.address).toEqual(sender.address.toB256()); + expect(operations[0].to?.type).toEqual(AddressType.account); + expect(operations[0].to?.address).toEqual(recipient.toB256()); + expect(operations[0].to?.chain).toEqual(ChainName.ethereum); + expect(operations[0].assetsSent).toHaveLength(1); + expect(operations[0].assetsSent?.[0].amount).toEqual(bn(amountToWithdraw)); + expect(operations[0].assetsSent?.[0].assetId).toEqual(provider.getBaseAssetId()); + }); + + it('Should return contract created operations', async () => { + using launched = await launchTestNode(); + + const { + wallets: [wallet], + } = launched; + + const tx = await MultiTokenContractFactory.deploy(wallet); + const result = await tx.waitForResult(); + + expect(result.transactionResult.operations).toHaveLength(1); + expect(result.transactionResult.operations[0].name).toEqual(OperationName.contractCreated); + expect(result.transactionResult.operations[0].from?.type).toEqual(AddressType.account); + expect(result.transactionResult.operations[0].from?.address).toEqual(wallet.address.toB256()); + expect(result.transactionResult.operations[0].to?.type).toEqual(AddressType.contract); + expect(result.transactionResult.isTypeCreate).toEqual(true); + }); + + it('should have no assets returned for contract call operations', async () => { + using launched = await launchTestNode({ + contractsConfigs: [ + { + factory: TokenContractFactory, + }, + ], + }); + + const { + wallets: [wallet], + contracts: [contract], + } = launched; + + const tx = await contract.functions.mint_coins(100).call(); + const result = await tx.waitForResult(); + + expect(result.transactionResult.operations).toHaveLength(1); + expect(result.transactionResult.operations[0].name).toEqual(OperationName.contractCall); + expect(result.transactionResult.operations[0].from?.type).toEqual(AddressType.account); + expect(result.transactionResult.operations[0].from?.address).toEqual(wallet.address.toB256()); + expect(result.transactionResult.operations[0].to?.address).toEqual(contract.id.toB256()); + expect(result.transactionResult.operations[0].to?.type).toEqual(AddressType.contract); + expect(result.transactionResult.operations[0].assetsSent).toBeUndefined(); + }); }); }); From 96140a2a0612fb6551deb0d1c3c32040ac7b9425 Mon Sep 17 00:00:00 2001 From: Dhaiwat Date: Tue, 3 Sep 2024 22:44:13 +0530 Subject: [PATCH 3/4] fix: faucet link in `create-fuels` navbar (#3091) --- .changeset/clever-papayas-hang.md | 5 +++++ templates/nextjs/src/components/Navbar.tsx | 20 ++------------------ templates/vite/src/components/Navbar.tsx | 20 ++------------------ 3 files changed, 9 insertions(+), 36 deletions(-) create mode 100644 .changeset/clever-papayas-hang.md diff --git a/.changeset/clever-papayas-hang.md b/.changeset/clever-papayas-hang.md new file mode 100644 index 00000000000..97516e1622a --- /dev/null +++ b/.changeset/clever-papayas-hang.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +fix: faucet link in `create-fuels` navbar diff --git a/templates/nextjs/src/components/Navbar.tsx b/templates/nextjs/src/components/Navbar.tsx index e4c6f2a3f49..1e12d6d8424 100644 --- a/templates/nextjs/src/components/Navbar.tsx +++ b/templates/nextjs/src/components/Navbar.tsx @@ -79,14 +79,7 @@ export const Navbar: FC = () => {