From 516b120f2eed438e4cdf90c31b4270782a34a59c Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Fri, 26 Jul 2024 17:43:06 +0100 Subject: [PATCH 01/14] chore: added ts check for docs-snippets --- apps/docs-snippets/package.json | 5 +++-- .../src/guide/transactions/transaction-policies.test.ts | 4 ++-- apps/docs-snippets/src/guide/types/conversion.test.ts | 2 +- .../src/guide/wallets/checking-balances.test.ts | 2 +- apps/docs-snippets/src/jsonc.d.ts | 5 +++++ 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 apps/docs-snippets/src/jsonc.d.ts diff --git a/apps/docs-snippets/package.json b/apps/docs-snippets/package.json index b7580f5c74a..3c7b3316b52 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": "pnpm 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/transactions/transaction-policies.test.ts b/apps/docs-snippets/src/guide/transactions/transaction-policies.test.ts index ae0b3fa1903..15e3c56ef73 100644 --- a/apps/docs-snippets/src/guide/transactions/transaction-policies.test.ts +++ b/apps/docs-snippets/src/guide/transactions/transaction-policies.test.ts @@ -39,7 +39,7 @@ describe('Transaction Policies', () => { expect(policyTypes).toBe(15); expect(policies?.[0].type).toBe(PolicyType.Tip); - expect(bn(policies?.[0].data).eq(transactionRequest.tip)).toBeTruthy(); + expect(bn(policies?.[0].data).eq(bn(transactionRequest.tip))).toBeTruthy(); expect(policies?.[1].type).toBe(PolicyType.WitnessLimit); expect(bn(policies?.[1].data).eq(bn(transactionRequest.witnessLimit))).toBeTruthy(); expect(policies?.[2].type).toBe(PolicyType.Maturity); @@ -84,7 +84,7 @@ describe('Transaction Policies', () => { } expect(policies?.[0].type).toBe(PolicyType.Tip); - expect(bn(policies?.[0].data).eq(transactionRequest.tip)).toBeTruthy(); + expect(bn(policies?.[0].data).eq(bn(transactionRequest.tip))).toBeTruthy(); expect(policies?.[1].type).toBe(PolicyType.WitnessLimit); expect(bn(policies?.[1].data).eq(bn(transactionRequest.witnessLimit))).toBeTruthy(); expect(policies?.[2].type).toBe(PolicyType.Maturity); diff --git a/apps/docs-snippets/src/guide/types/conversion.test.ts b/apps/docs-snippets/src/guide/types/conversion.test.ts index 8651ab2885a..b49e9e2022b 100644 --- a/apps/docs-snippets/src/guide/types/conversion.test.ts +++ b/apps/docs-snippets/src/guide/types/conversion.test.ts @@ -128,6 +128,6 @@ describe(__filename, () => { const assetId: AssetId = address.toAssetId(); // #endregion conversion-4 - expect(assetId.value); + expect(assetId.bits).toBeTruthy(); }); }); diff --git a/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts b/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts index d6d1890f19c..3f4a6286eab 100644 --- a/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts +++ b/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts @@ -37,7 +37,7 @@ describe(__filename, () => { // #region checking-balances-2 const myWallet = Wallet.fromPrivateKey(privateKey, provider); - const balances: CoinQuantity[] = await myWallet.getBalances(); + const { balances } = await myWallet.getBalances(); // #endregion checking-balances-2 expect(balances).toBeDefined(); 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; +} From b6828601ecd176ae5b2aa32783531e940868ae3b Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Fri, 26 Jul 2024 18:06:34 +0100 Subject: [PATCH 02/14] chore: added typechecking for the packages --- .../strategies/getCoderForEncoding.test.ts | 5 ++++- packages/abi-coder/src/utils/json-abi.test.ts | 1 + .../src/templates/predicate/factory.test.ts | 1 + .../src/templates/script/factory.test.ts | 1 + .../abi-typegen/src/utils/makeFunction.test.ts | 1 + .../abi-typegen/src/utils/parseFunctions.test.ts | 2 ++ .../src/utils/parseTypeArguments.test.ts | 2 +- packages/abi-typegen/tsconfig.json | 3 ++- packages/create-fuels/package.json | 1 + packages/fuel-gauge/package.json | 5 +++-- packages/fuel-gauge/tsconfig.json | 2 +- packages/fuels/package.json | 4 +++- packages/versions/src/cli.test.ts | 14 ++++++++++++++ scripts/postbuild.ts | 10 ++++++++++ 14 files changed, 45 insertions(+), 7 deletions(-) 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-coder/src/utils/json-abi.test.ts b/packages/abi-coder/src/utils/json-abi.test.ts index 853530c87bb..27cbc033026 100644 --- a/packages/abi-coder/src/utils/json-abi.test.ts +++ b/packages/abi-coder/src/utils/json-abi.test.ts @@ -20,6 +20,7 @@ const MOCK_ABI: JsonAbi = { ], loggedTypes: [], configurables: [], + messagesTypes: [], }; const DEFAULT_ENCODING_VERSION = ENCODING_V1; diff --git a/packages/abi-typegen/src/templates/predicate/factory.test.ts b/packages/abi-typegen/src/templates/predicate/factory.test.ts index 7d5e0e91d01..2563371abc7 100644 --- a/packages/abi-typegen/src/templates/predicate/factory.test.ts +++ b/packages/abi-typegen/src/templates/predicate/factory.test.ts @@ -67,6 +67,7 @@ describe('factory.ts', () => { const rawContents = project.abiContents; // friction here (deletes 'main' function by emptying the functions array) + // @ts-expect-error we are able to update the ABI rawContents.functions = []; const abi = new Abi({ diff --git a/packages/abi-typegen/src/templates/script/factory.test.ts b/packages/abi-typegen/src/templates/script/factory.test.ts index 0267d01492a..6c11c8594f6 100644 --- a/packages/abi-typegen/src/templates/script/factory.test.ts +++ b/packages/abi-typegen/src/templates/script/factory.test.ts @@ -65,6 +65,7 @@ describe('factory.ts', () => { const rawContents = project.abiContents; // friction here (deletes 'main' function by emptying the functions array) + // @ts-expect-error we are able to update the ABI rawContents.functions = []; const abi = new Abi({ diff --git a/packages/abi-typegen/src/utils/makeFunction.test.ts b/packages/abi-typegen/src/utils/makeFunction.test.ts index aca082c573e..0ce042ea1f3 100644 --- a/packages/abi-typegen/src/utils/makeFunction.test.ts +++ b/packages/abi-typegen/src/utils/makeFunction.test.ts @@ -32,6 +32,7 @@ describe('functions.ts', () => { name: 'f1', inputs: [{ name: 'u8', type: 1, typeArguments: null }], output: { name: 'u8', type: 1, typeArguments: null }, + attributes: null, }; expect(makeFunction({ rawAbiFunction, types })).toBeTruthy(); diff --git a/packages/abi-typegen/src/utils/parseFunctions.test.ts b/packages/abi-typegen/src/utils/parseFunctions.test.ts index 54f0e8697ea..054aa98e78c 100644 --- a/packages/abi-typegen/src/utils/parseFunctions.test.ts +++ b/packages/abi-typegen/src/utils/parseFunctions.test.ts @@ -32,12 +32,14 @@ describe('functions.ts', () => { name: 'f1', inputs: [{ name: 'u8', type: 1, typeArguments: null }], output: { name: 'u8', type: 1, typeArguments: null }, + attributes: null, }; const rawF2: JsonAbiFunction = { name: 'f2', inputs: [{ name: 'u16', type: 2, typeArguments: null }], output: { name: 'u16', type: 2, typeArguments: null }, + attributes: null, }; const rawAbiFunctions = [rawF1, rawF2]; diff --git a/packages/abi-typegen/src/utils/parseTypeArguments.test.ts b/packages/abi-typegen/src/utils/parseTypeArguments.test.ts index dbb7b115f82..1515c33dd2f 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/create-fuels/package.json b/packages/create-fuels/package.json index ac6b0411e0c..fc330b5c9d6 100644 --- a/packages/create-fuels/package.json +++ b/packages/create-fuels/package.json @@ -16,6 +16,7 @@ "license": "Apache-2.0", "scripts": { "build": "tsup", + "postbuild": "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/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 0845203f7e6..7cf2dec7ede 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/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/scripts/postbuild.ts b/scripts/postbuild.ts index ff4556d2779..1321277a419 100644 --- a/scripts/postbuild.ts +++ b/scripts/postbuild.ts @@ -38,3 +38,13 @@ Object.keys(pkgJson.exports) }); writeFileSync(dtsPath, dtsContents); + +/** + * 3). Run typecheck + */ +try { + execSync('tsc --noEmit', { stdio: 'inherit' }); +} catch (err) { + error(err.toString()); + process.exit(1); +} From d92585ea9df31b5667102175a0eee6a52557abd0 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Fri, 26 Jul 2024 10:35:31 +0100 Subject: [PATCH 03/14] fix: integration test --- packages/create-fuels/test/integration.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/create-fuels/test/integration.test.ts b/packages/create-fuels/test/integration.test.ts index 00c527bbf8e..817a27e2ef9 100644 --- a/packages/create-fuels/test/integration.test.ts +++ b/packages/create-fuels/test/integration.test.ts @@ -41,7 +41,7 @@ describe('`create fuels` package integrity', () => { }); afterEach(() => { - resetFilesystem(paths.root); + resetFilesystem(paths.projectRoot); }); it.each(packageManagerCreateCommands)( @@ -54,8 +54,8 @@ describe('`create fuels` package integrity', () => { `"fuels": "[0-9]+.[0-9]+.[0-9]+-${PUBLISHED_NPM_TAG}-[0-9]+"` ); - const args = generateArgs(paths.root, packageManager).join(' '); - const expectedTemplateFiles = await getAllFiles(paths.sourceTemplate).then((files) => + const args = generateArgs(paths.projectRoot, packageManager).join(' '); + const expectedTemplateFiles = await getAllFiles(paths.templateSource).then((files) => filterOriginalTemplateFiles(files).filter(filterForcBuildFiles) ); @@ -66,9 +66,9 @@ describe('`create fuels` package integrity', () => { ); expect(createFuelsError).toBeUndefined(); - const actualTemplateFiles = await getAllFiles(paths.root); + const actualTemplateFiles = await getAllFiles(paths.projectRoot); expect(actualTemplateFiles.sort()).toEqual(expectedTemplateFiles.sort()); - const packageJson = readFileSync(paths.packageJson, 'utf-8'); + const packageJson = readFileSync(paths.projectPackageJson, 'utf-8'); expect(packageJson).toEqual(expect.stringMatching(expectedPackageJsonInstall)); }, { timeout: 30000 } From db9702277708d4303f746da1776741aa37bf5093 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 30 Jul 2024 12:14:19 +0100 Subject: [PATCH 04/14] Added pid --- packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index 53f87ded6b2..d950c510c91 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -34,6 +34,7 @@ describe('autoStartFuelCore', () => { port: '4000', url: 'http://127.0.0.1:4000/v1/graphql', snapshotDir: '/some/path', + pid: 1234, }) ); return { launchNode }; From c656950d8432b43f386e9837ba2aafe9240f94bb Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 30 Jul 2024 12:14:32 +0100 Subject: [PATCH 05/14] fuel-gauge: wip --- .../fuel-gauge/src/coverage-contract.test.ts | 22 +++++++++------- packages/fuel-gauge/src/vector-types.test.ts | 4 ++- packages/fuel-gauge/src/vectors.test.ts | 25 ++++++++++++------- .../fuel-gauge/test/fixtures/abi/predicate.ts | 1 + 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/packages/fuel-gauge/src/coverage-contract.test.ts b/packages/fuel-gauge/src/coverage-contract.test.ts index ad5d7ca9705..cd8c43b64a4 100644 --- a/packages/fuel-gauge/src/coverage-contract.test.ts +++ b/packages/fuel-gauge/src/coverage-contract.test.ts @@ -1,8 +1,10 @@ -import type { BN, Message } from 'fuels'; +import type { BigNumberish, BN, Message } from 'fuels'; import { arrayify, bn, toHex, Wallet, ScriptTransactionRequest, randomBytes, hexlify } from 'fuels'; import { CoverageContractAbi__factory } from '../test/typegen/contracts'; +import { SmallEnumInput } from '../test/typegen/contracts/CoverageContractAbi'; import CoverageContractAbiHex from '../test/typegen/contracts/CoverageContractAbi.hex'; +import type { Option } from '../test/typegen/contracts/common'; import { launchTestContract } from './utils'; @@ -245,7 +247,7 @@ describe('Coverage Contract', () => { it('should test tuple > 8 bytes variable type', async () => { using contractInstance = await setupContract(); - const INPUT = [bn(RUST_U32_MAX).add(1), bn(RUST_U32_MAX).add(2)]; + const INPUT: [BigNumberish, BigNumberish] = [bn(RUST_U32_MAX).add(1), bn(RUST_U32_MAX).add(2)]; const { waitForResult } = await contractInstance.functions.echo_tuple_u64(INPUT).call(); const { value } = await waitForResult(); expect(JSON.stringify(value)).toStrictEqual(JSON.stringify(INPUT)); @@ -254,7 +256,7 @@ describe('Coverage Contract', () => { it('should test tuple mixed variable type', async () => { using contractInstance = await setupContract(); - const INPUT = [true, bn(RUST_U32_MAX).add(1)]; + const INPUT: [boolean, BigNumberish] = [true, bn(RUST_U32_MAX).add(1)]; const { waitForResult } = await contractInstance.functions.echo_tuple_mixed(INPUT).call(); const { value } = await waitForResult(); expect(JSON.stringify(value)).toStrictEqual(JSON.stringify(INPUT)); @@ -314,7 +316,7 @@ describe('Coverage Contract', () => { it('should test enum < 8 byte variable type', async () => { using contractInstance = await setupContract(); - const INPUT = SmallEnum.Empty; + const INPUT: SmallEnumInput = SmallEnumInput.Empty; const { waitForResult } = await contractInstance.functions.echo_enum_small(INPUT).call(); const { value } = await waitForResult(); expect(value).toStrictEqual(INPUT); @@ -392,7 +394,9 @@ describe('Coverage Contract', () => { const INPUT = 1; // adds the three values together, but only first param value is supplied - const { waitForResult } = await contractInstance.functions.echo_option_three_u8(INPUT).call(); + const { waitForResult } = await contractInstance.functions + .echo_option_three_u8(INPUT, undefined, undefined) + .call(); const { value: Some } = await waitForResult(); // we receive the result of adding whatever was passed @@ -523,12 +527,12 @@ describe('Coverage Contract', () => { .echo_struct_vector_last([ { foo: 1, - bar: 11337n, + bar: bn(11337), baz: '123456789', }, { foo: 2, - bar: 21337n, + bar: bn(21337), baz: 'alphabet!', }, last, @@ -740,7 +744,7 @@ describe('Coverage Contract', () => { const { value } = await waitForResult(); - expect(value.map((v: BN) => v.toHex())).toStrictEqual([ + expect(value.map((v: BN | Option) => v?.toHex())).toStrictEqual([ bn(3).toHex(), bn(450).toHex(), bn(202).toHex(), @@ -813,7 +817,7 @@ describe('Coverage Contract', () => { contractInstance.functions.echo_b256_middle(INPUT_A, INPUT_B, INPUT_C, INPUT_D), contractInstance.functions.echo_u8(13), contractInstance.functions.echo_u8(23), - contractInstance.functions.echo_enum_small(SmallEnum.Empty), + contractInstance.functions.echo_enum_small(SmallEnumInput.Empty), contractInstance.functions.echo_b256_middle(INPUT_B, INPUT_A, INPUT_C, INPUT_D), ]) .call(); diff --git a/packages/fuel-gauge/src/vector-types.test.ts b/packages/fuel-gauge/src/vector-types.test.ts index 69aea48368b..c01f0194f34 100644 --- a/packages/fuel-gauge/src/vector-types.test.ts +++ b/packages/fuel-gauge/src/vector-types.test.ts @@ -1,9 +1,11 @@ +import type { BigNumberish } from 'fuels'; import { bn, Predicate, Wallet, Address } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; import { VectorTypesScriptAbi__factory } from '../test/typegen'; import { VectorTypesContractAbi__factory } from '../test/typegen/contracts'; import VectorTypesContractAbiHex from '../test/typegen/contracts/VectorTypesContractAbi.hex'; +import type { Vec } from '../test/typegen/contracts/common'; import { PredicateVectorTypesAbi__factory } from '../test/typegen/predicates'; import { launchTestContract } from './utils'; @@ -15,7 +17,7 @@ const VEC_IN_VEC = [ ]; const STRUCT_IN_VEC = [{ a: 0 }, { a: 1 }]; const VEC_IN_STRUCT = { a: [0, 1, 2] }; -const ARRAY_IN_VEC = [ +const ARRAY_IN_VEC: Vec<[BigNumberish, BigNumberish]> = [ [0, 1], [0, 1], ]; diff --git a/packages/fuel-gauge/src/vectors.test.ts b/packages/fuel-gauge/src/vectors.test.ts index 10bd0f46d70..c09d9397e8b 100644 --- a/packages/fuel-gauge/src/vectors.test.ts +++ b/packages/fuel-gauge/src/vectors.test.ts @@ -1,8 +1,10 @@ import { bn, randomBytes, hexlify } from 'fuels'; -import type { BN } from 'fuels'; +import type { BigNumberish, BN } from 'fuels'; import { VectorsAbi__factory } from '../test/typegen/contracts'; +import type { SmallEnumInput } from '../test/typegen/contracts/CoverageContractAbi'; import VectorsAbiHex from '../test/typegen/contracts/VectorsAbi.hex'; +import type { Vec } from '../test/typegen/contracts/common'; import { launchTestContract } from './utils'; @@ -124,7 +126,7 @@ describe('Vector Tests', () => { it('should test (u8, u8) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec<[BigNumberish, BigNumberish]> = [ [1, 2], [3, 4], [5, 6], @@ -141,7 +143,7 @@ describe('Vector Tests', () => { it('should test (u64, u64) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec<[BigNumberish, BigNumberish]> = [ [111, 2222], [333, 4445], [5555, 6], @@ -172,7 +174,7 @@ describe('Vector Tests', () => { it('should test [u64; 5] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec<[BigNumberish, BigNumberish, BigNumberish, BigNumberish, BigNumberish]> = [ [1, 2, 3, 4, 5], [500, 600, 700, 9000, 9999], [11500, 22600, 33700, 55000, 669999], @@ -187,7 +189,7 @@ describe('Vector Tests', () => { it('should test [bool; 2] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec<[boolean, boolean]> = [ [true, true], [true, false], [false, true], @@ -287,7 +289,7 @@ describe('Vector Tests', () => { it('should test SmallEnum vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Vec = [ SmallEnum.Empty, SmallEnum.Empty, SmallEnum.Empty, @@ -408,7 +410,7 @@ describe('Vector Tests', () => { it('should test Vec and b256 tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [[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) @@ -421,7 +423,7 @@ describe('Vector Tests', () => { it('should test two vectors tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: [Vec, Vec] = [ [219, 229], [1, 254, 55], ]; @@ -437,7 +439,12 @@ describe('Vector Tests', () => { it('should test u32 and three different vectors tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [91000, [true, true, false], [95000, 153333], [20000, 65500]]; + const INPUT: [BigNumberish, Vec, Vec, Vec] = [ + 91000, + [true, true, false], + [95000, 153333], + [20000, 65500], + ]; const { waitForResult } = await contractInstance.functions .echo_u32_then_three_vectors(...INPUT) diff --git a/packages/fuel-gauge/test/fixtures/abi/predicate.ts b/packages/fuel-gauge/test/fixtures/abi/predicate.ts index e3413f6623a..41eadf17339 100644 --- a/packages/fuel-gauge/test/fixtures/abi/predicate.ts +++ b/packages/fuel-gauge/test/fixtures/abi/predicate.ts @@ -35,4 +35,5 @@ export const defaultPredicateAbi: JsonAbi = { ], loggedTypes: [], configurables: [], + messagesTypes: [], }; From 77112c2fce8e4e991559df63661fbeb6d6e9db2c Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 28 Aug 2024 11:56:59 +0100 Subject: [PATCH 06/14] chore: appease the lint gods --- apps/docs-snippets/src/guide/types/vector.test.ts | 2 -- packages/fuel-gauge/src/bytecode-sway-lib.test.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/docs-snippets/src/guide/types/vector.test.ts b/apps/docs-snippets/src/guide/types/vector.test.ts index 11c26f24c91..c8e3b2b5f4f 100644 --- a/apps/docs-snippets/src/guide/types/vector.test.ts +++ b/apps/docs-snippets/src/guide/types/vector.test.ts @@ -1,7 +1,5 @@ -import type { BigNumberish } from 'fuels'; import { BN, arrayify, getRandomB256 } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; -import type { Vec } from 'test/typegen/contracts/common'; import { BytecodeInputFactory, EchoEmployeeDataVectorFactory } from '../../../test/typegen'; import type { EmployeeDataInput } from '../../../test/typegen/contracts/EchoU64Array'; diff --git a/packages/fuel-gauge/src/bytecode-sway-lib.test.ts b/packages/fuel-gauge/src/bytecode-sway-lib.test.ts index c7229e695fa..2469ca46337 100644 --- a/packages/fuel-gauge/src/bytecode-sway-lib.test.ts +++ b/packages/fuel-gauge/src/bytecode-sway-lib.test.ts @@ -1,4 +1,4 @@ -import { Predicate, arrayify } from 'fuels'; +import { arrayify } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; import { PredicateTrue } from '../test/typegen'; From fa3df98f4d7e1c016e38bc958af8662647dbde78 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 28 Aug 2024 12:25:55 +0100 Subject: [PATCH 07/14] chore: added missing type checking --- packages/contract/tsconfig.json | 2 +- packages/logger/test/index.test.ts | 5 ++++- packages/logger/test/utils.test.ts | 4 ++-- packages/logger/tsconfig.json | 2 +- packages/utils/tsconfig.json | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) 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/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"] } From 4011d9e24c5c05911d684551c644a7f0e0075dd5 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 28 Aug 2024 12:28:18 +0100 Subject: [PATCH 08/14] chore: changeset --- .changeset/odd-seahorses-learn.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changeset/odd-seahorses-learn.md diff --git a/.changeset/odd-seahorses-learn.md b/.changeset/odd-seahorses-learn.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/odd-seahorses-learn.md @@ -0,0 +1,2 @@ +--- +--- From e396aa305db90e6ca560c6b2ef33101f46d79b2e Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 28 Aug 2024 12:32:01 +0100 Subject: [PATCH 09/14] chore: changeset --- .changeset/odd-seahorses-learn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.changeset/odd-seahorses-learn.md b/.changeset/odd-seahorses-learn.md index a845151cc84..1e170e28704 100644 --- a/.changeset/odd-seahorses-learn.md +++ b/.changeset/odd-seahorses-learn.md @@ -1,2 +1,4 @@ --- --- + +chore: adding type checking From 9936e42bd535793addcd5e254c915460daeb1a8e Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 28 Aug 2024 12:32:10 +0100 Subject: [PATCH 10/14] chore: fixed import --- apps/docs-snippets/src/guide/types/contract-types.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 816d4a7a723..0d17a7f0d9e 100644 --- a/apps/docs-snippets/src/guide/types/contract-types.test.ts +++ b/apps/docs-snippets/src/guide/types/contract-types.test.ts @@ -1,12 +1,12 @@ 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'; - -import { InputOutputTypesFactory } from '../../../test/typegen'; +} from '../../../test/typegen/contracts/InputOutputTypes'; /** * @group node From a1de1e4daea504bbcd23045462d7fda9fb752f99 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 2 Sep 2024 07:17:56 +0100 Subject: [PATCH 11/14] Removed unnecessary arguments --- packages/fuel-gauge/src/coverage-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuel-gauge/src/coverage-contract.test.ts b/packages/fuel-gauge/src/coverage-contract.test.ts index db34051c4a1..b1293e8d71c 100644 --- a/packages/fuel-gauge/src/coverage-contract.test.ts +++ b/packages/fuel-gauge/src/coverage-contract.test.ts @@ -387,7 +387,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { // adds the three values together, but only first param value is supplied const { waitForResult } = await contractInstance.functions - .echo_option_three_u8(INPUT, undefined, undefined) + .echo_option_three_u8(INPUT) .call(); const { value: Some } = await waitForResult(); From 52ebb044a4b4cf28cc286aad347c6a6379bd016d Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 2 Sep 2024 07:31:37 +0100 Subject: [PATCH 12/14] chore: fix error with coder --- packages/abi-coder/src/encoding/coders/NumberCoder.test.ts | 1 + 1 file changed, 1 insertion(+) 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}`) ); From aa63f4f722421a7c772da339485833b4226bb729 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 2 Sep 2024 07:31:45 +0100 Subject: [PATCH 13/14] chore: lint --- packages/fuel-gauge/src/coverage-contract.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/fuel-gauge/src/coverage-contract.test.ts b/packages/fuel-gauge/src/coverage-contract.test.ts index b1293e8d71c..4d74f8c1eb6 100644 --- a/packages/fuel-gauge/src/coverage-contract.test.ts +++ b/packages/fuel-gauge/src/coverage-contract.test.ts @@ -386,9 +386,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { const INPUT = 1; // adds the three values together, but only first param value is supplied - const { waitForResult } = await contractInstance.functions - .echo_option_three_u8(INPUT) - .call(); + const { waitForResult } = await contractInstance.functions.echo_option_three_u8(INPUT).call(); const { value: Some } = await waitForResult(); // we receive the result of adding whatever was passed From 961e0787007f952b871caa757c9ff255e813ff4e Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 3 Sep 2024 08:17:22 +0100 Subject: [PATCH 14/14] chore: moved type checking to lint hook --- package.json | 3 ++- scripts/postbuild.ts | 10 ---------- tsconfig.test.json | 8 ++++++++ 3 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 tsconfig.test.json diff --git a/package.json b/package.json index a7ed2c488d4..d7eda0479a8 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/scripts/postbuild.ts b/scripts/postbuild.ts index 1321277a419..ff4556d2779 100644 --- a/scripts/postbuild.ts +++ b/scripts/postbuild.ts @@ -38,13 +38,3 @@ Object.keys(pkgJson.exports) }); writeFileSync(dtsPath, dtsContents); - -/** - * 3). Run typecheck - */ -try { - execSync('tsc --noEmit', { stdio: 'inherit' }); -} catch (err) { - error(err.toString()); - process.exit(1); -} 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"] +}