From 682d62eb7c45cfb04816378b17453a7e5e25fd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Mon, 26 Aug 2024 08:10:24 -0300 Subject: [PATCH] chore: remove TS errors from some tests (#3026) --- .changeset/fast-walls-report.md | 4 + .../interacting-with-predicates.test.ts | 4 +- .../src/guide/types/conversion.test.ts | 2 +- .../guide/wallets/checking-balances.test.ts | 4 +- .../src/utils/getFunctionInputs.test.ts | 4 +- packages/abi-coder/src/utils/json-abi.test.ts | 9 +- packages/abi-coder/test/Interface.test.ts | 9 +- .../src/utils/makeFunction.test.ts | 1 + .../src/utils/parseFunctions.test.ts | 2 + packages/fuel-gauge/src/contract.test.ts | 164 +----------------- .../fuel-gauge/src/coverage-contract.test.ts | 22 +-- .../src/dry-run-multiple-txs.test.ts | 3 +- packages/fuel-gauge/src/fee.test.ts | 5 +- .../src/generic-types-contract.test.ts | 7 +- .../src/predicate-conditional-inputs.test.ts | 4 +- packages/fuel-gauge/src/raw-slice.test.ts | 2 +- .../src/script-with-configurable.test.ts | 6 +- .../src/script-with-vectors.test.ts | 24 +-- .../src/token-test-contract.test.ts | 5 +- .../src/transaction-response.test.ts | 15 +- .../src/transaction-summary.test.ts | 13 ++ packages/fuel-gauge/src/vector-types.test.ts | 20 ++- packages/fuel-gauge/src/vectors.test.ts | 23 ++- packages/fuel-gauge/src/void.test.ts | 2 +- 24 files changed, 114 insertions(+), 240 deletions(-) create mode 100644 .changeset/fast-walls-report.md diff --git a/.changeset/fast-walls-report.md b/.changeset/fast-walls-report.md new file mode 100644 index 00000000000..4ee62c4fbca --- /dev/null +++ b/.changeset/fast-walls-report.md @@ -0,0 +1,4 @@ +--- +--- + +chore: remove TS errors from some tests diff --git a/apps/docs-snippets/src/guide/predicates/interacting-with-predicates.test.ts b/apps/docs-snippets/src/guide/predicates/interacting-with-predicates.test.ts index a42aef80f87..a67d92b7a2a 100644 --- a/apps/docs-snippets/src/guide/predicates/interacting-with-predicates.test.ts +++ b/apps/docs-snippets/src/guide/predicates/interacting-with-predicates.test.ts @@ -1,4 +1,4 @@ -import type { JsonAbi, Provider, WalletUnlocked } from 'fuels'; +import type { BytesLike, JsonAbi, Provider, WalletUnlocked } from 'fuels'; import { ScriptTransactionRequest, bn, Predicate, BN, Wallet } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; @@ -16,7 +16,7 @@ describe('Interacting with Predicates', () => { fundedWallet: WalletUnlocked, inputData: [string], abi: JsonAbi, - bytecode: string, + bytecode: BytesLike, configurableConstants?: Record ): Promise> { const predicate = new Predicate({ diff --git a/apps/docs-snippets/src/guide/types/conversion.test.ts b/apps/docs-snippets/src/guide/types/conversion.test.ts index bc2a04c59e4..963bd9bb636 100644 --- a/apps/docs-snippets/src/guide/types/conversion.test.ts +++ b/apps/docs-snippets/src/guide/types/conversion.test.ts @@ -119,6 +119,6 @@ describe('Conversion Types', () => { const assetId: AssetId = address.toAssetId(); // #endregion conversion-4 - expect(assetId.value); + expect(assetId.bits).toEqual(b256); }); }); 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 d433bb47937..b9cf92ea312 100644 --- a/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts +++ b/apps/docs-snippets/src/guide/wallets/checking-balances.test.ts @@ -1,4 +1,4 @@ -import type { CoinQuantity, BN } from 'fuels'; +import type { BN } from 'fuels'; import { Wallet } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; @@ -37,7 +37,7 @@ describe('Checking balances', () => { // #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/packages/abi-coder/src/utils/getFunctionInputs.test.ts b/packages/abi-coder/src/utils/getFunctionInputs.test.ts index 7bab5a7e85c..baaedc0eae3 100644 --- a/packages/abi-coder/src/utils/getFunctionInputs.test.ts +++ b/packages/abi-coder/src/utils/getFunctionInputs.test.ts @@ -1,4 +1,4 @@ -import type { JsonAbi, JsonAbiArgument, JsonAbiType } from '../types/JsonAbi'; +import type { JsonAbiArgument, JsonAbiOld, JsonAbiType } from '../types/JsonAbi'; import { getFunctionInputs } from './getFunctionInputs'; @@ -36,7 +36,7 @@ const EMPTY_ABI_TYPES: [string, JsonAbiType][] = [ ['option (debug)', debugOptionAbiType], ]; -const jsonAbi: JsonAbi = { +const jsonAbi: JsonAbiOld = { encoding: '1', types: [nonEmptyType, voidAbiType, optionAbiType, debugOptionAbiType], functions: [], diff --git a/packages/abi-coder/src/utils/json-abi.test.ts b/packages/abi-coder/src/utils/json-abi.test.ts index d81d28576a4..4c98cd203e9 100644 --- a/packages/abi-coder/src/utils/json-abi.test.ts +++ b/packages/abi-coder/src/utils/json-abi.test.ts @@ -1,5 +1,5 @@ import type { ResolvedAbiType } from '../ResolvedAbiType'; -import type { JsonAbiOld, JsonAbiArgument } from '../types/JsonAbi'; +import type { JsonAbiArgument } from '../types/JsonAbi'; import { ENCODING_V1 } from './constants'; import { @@ -9,8 +9,10 @@ import { findVectorBufferArgument, getEncodingVersion, } from './json-abi'; +import { transpileAbi } from './transpile-abi'; -const MOCK_ABI: JsonAbiOld = { +const MOCK_ABI = transpileAbi({ + encoding: 'V1', types: [ { typeId: 1, type: '()', components: [], typeParameters: [] }, { typeId: 2, type: 'u256', components: [], typeParameters: [] }, @@ -20,7 +22,8 @@ const MOCK_ABI: JsonAbiOld = { ], loggedTypes: [], configurables: [], -}; + messagesTypes: [], +}); const DEFAULT_ENCODING_VERSION = ENCODING_V1; diff --git a/packages/abi-coder/test/Interface.test.ts b/packages/abi-coder/test/Interface.test.ts index 4e28fa37628..0980014ee0f 100644 --- a/packages/abi-coder/test/Interface.test.ts +++ b/packages/abi-coder/test/Interface.test.ts @@ -3,8 +3,7 @@ import type { BN } from '@fuel-ts/math'; import { concat } from '@fuel-ts/utils'; import { Interface } from '../src/Interface'; -import type { JsonAbiConfigurable } from '../src/types/JsonAbi'; -import type { AbiFunction } from '../src/types/JsonAbiNew'; +import type { AbiFunction, Configurable } from '../src/types/JsonAbiNew'; import { AbiCoderProjectsEnum, getCoderForcProject } from './fixtures/forc-projects'; import { @@ -112,7 +111,7 @@ describe('Abi interface', () => { describe('configurables', () => { it('sets configurables as dictionary', () => { const dict = exhaustiveExamplesAbi.configurables.reduce((obj, val) => { - const o: Record = obj; + const o: Record = obj; o[val.name] = val; return o; }, {}); @@ -609,7 +608,7 @@ describe('Abi interface', () => { let decoded = fn.decodeOutput(expectedEncoded)[0]; if (decodedTransformer) { - decoded = decodedTransformer(decoded); + decoded = decodedTransformer(decoded as any[]); } const expectedDecoded = Array.isArray(value) && value.length === 1 ? value[0] : value; // the conditional is when the input is a SINGLE array/tuple - then de-nest it @@ -623,7 +622,7 @@ describe('Abi interface', () => { )[0]; if (decodedTransformer) { - decodedType = decodedTransformer(decodedType); + decodedType = decodedTransformer(decodedType as any[]); } expect(decodedType).toEqual(expectedDecoded); diff --git a/packages/abi-typegen/src/utils/makeFunction.test.ts b/packages/abi-typegen/src/utils/makeFunction.test.ts index aca082c573e..a1495cdcecd 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: [], }; 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..1671fdb4c1b 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: [], }; const rawF2: JsonAbiFunction = { name: 'f2', inputs: [{ name: 'u16', type: 2, typeArguments: null }], output: { name: 'u16', type: 2, typeArguments: null }, + attributes: [], }; const rawAbiFunctions = [rawF1, rawF2]; diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index f0889d0a43e..8a08569d97e 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -12,10 +12,9 @@ import { ContractFactory, Predicate, PolicyType, - ZeroBytes32, buildFunctionResult, } from 'fuels'; -import type { JsonAbi, ScriptTransactionRequest, TransferParams } from 'fuels'; +import type { ScriptTransactionRequest, TransferParams } from 'fuels'; import { expectToThrowFuelError, ASSET_A, ASSET_B, launchTestNode } from 'fuels/test-utils'; import type { DeployContractConfig } from 'fuels/test-utils'; @@ -38,122 +37,6 @@ const contractsConfigs: DeployContractConfig[] = [ }, ]; -const jsonFragment: JsonAbi = { - configurables: [], - loggedTypes: [], - types: [ - { - typeId: 0, - type: '()', - components: null, - typeParameters: null, - }, - { - typeId: 1, - type: 'u64', - components: null, - typeParameters: null, - }, - { - typeId: 2, - type: 'struct MyStruct', - components: [ - { - type: 0, - name: 'arg_one', - typeArguments: null, - }, - { - type: 1, - name: 'arg_two', - typeArguments: null, - }, - ], - typeParameters: null, - }, - ], - functions: [ - { - name: 'entry_one', - inputs: [ - { - name: 'arg', - type: 1, - typeArguments: null, - }, - ], - output: { - name: '', - type: 0, - typeArguments: null, - }, - attributes: [], - }, - ], - messagesTypes: [], -}; - -const complexFragment: JsonAbi = { - configurables: [], - loggedTypes: [], - types: [ - { - typeId: 0, - type: '()', - components: null, - typeParameters: null, - }, - { - typeId: 1, - type: 'str[20]', - components: null, - typeParameters: null, - }, - { - typeId: 2, - type: 'b256', - components: null, - typeParameters: null, - }, - { - typeId: 3, - type: '(_, _)', - components: [ - { - name: '__tuple_element', - type: 1, - typeArguments: null, - }, - { - name: '__tuple_element', - type: 2, - typeArguments: null, - }, - ], - typeParameters: null, - }, - ], - functions: [ - { - name: 'tuple_function', - inputs: [ - { - name: 'person', - type: 2, - typeArguments: null, - }, - ], - output: { - name: '', - type: 0, - typeArguments: null, - }, - attributes: [], - }, - ], - messagesTypes: [], -}; - const txPointer = '0x00000000000000000000000000000000'; const AltToken = '0x0101010101010101010101010101010101010101010101010101010101010101'; @@ -169,54 +52,11 @@ function setupTestContract() { * @group browser */ describe('Contract', () => { - it('generates function methods on a simple contract', async () => { - using launched = await launchTestNode(); - const { - wallets: [wallet], - } = launched; - - const contract = new Contract(ZeroBytes32, jsonFragment, wallet); - - const fragment = contract.interface.getFunction('entry_one'); - const interfaceSpy = vi.spyOn(fragment, 'encodeArguments'); - - try { - await contract.functions.entry_one(42); - } catch { - // The call will fail, but it doesn't matter - } - - expect(interfaceSpy).toHaveBeenCalled(); - }); - - it('generates function methods on a complex contract', async () => { - using launched = await launchTestNode(); - const { - wallets: [wallet], - } = launched; - - const contract = new Contract(ZeroBytes32, complexFragment, wallet); - - const fragment = contract.interface.getFunction('tuple_function'); - const interfaceSpy = vi.spyOn(fragment, 'encodeArguments'); - - try { - await contract.functions.tuple_function({ - address: '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b', - name: 'foo', - }); - } catch { - // The call will fail, but it doesn't matter - } - - expect(interfaceSpy).toHaveBeenCalled(); - }); - it('assigns a provider if passed', async () => { using launched = await launchTestNode(); const { provider } = launched; - const contract = new Contract(getRandomB256(), jsonFragment, provider); + const contract = new Contract(getRandomB256(), CallTestContract.abi, provider); expect(contract.provider).toEqual(provider); }); diff --git a/packages/fuel-gauge/src/coverage-contract.test.ts b/packages/fuel-gauge/src/coverage-contract.test.ts index 310e3c7ac08..4d74f8c1eb6 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 { CoverageContractFactory } from '../test/typegen/contracts'; +import type { MixedNativeEnumInput } from '../test/typegen/contracts/CoverageContract'; import { SmallEnumInput } from '../test/typegen/contracts/Vectors'; +import type { Vec } from '../test/typegen/contracts/common'; import { launchTestContract } from './utils'; @@ -240,7 +242,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { 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)); @@ -249,7 +251,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { 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)); @@ -515,12 +517,12 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { .echo_struct_vector_last([ { foo: 1, - bar: 11337n, + bar: bn(11337).toHex(), baz: '123456789', }, { foo: 2, - bar: 21337n, + bar: bn(21337).toHex(), baz: 'alphabet!', }, last, @@ -620,7 +622,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { const { value: { Ok }, } = await waitForResult(); - expect(Ok.toNumber()).toBe(20); + expect(Ok?.toNumber()).toBe(20); const call2 = await contractInstance.functions.types_result({ Ok: 0 }).call(); @@ -687,7 +689,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { it('should test mixed native enum [Native->NotNative]', async () => { using contractInstance = await setupContract(); - const input = MixedNativeEnum.Native; + const input: MixedNativeEnumInput = { Native: undefined }; const expected = { NotNative: MixedNativeEnum.NotNative }; const { waitForResult } = await contractInstance.functions.mixed_native_enum(input).call(); @@ -715,7 +717,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { const { value } = await waitForResult(); - expect(value.map((v: BN) => v.toHex())).toStrictEqual([ + expect(value.map((v: BN | undefined) => v?.toHex())).toStrictEqual([ bn(4).toHex(), bn(100).toHex(), bn(450).toHex(), @@ -732,7 +734,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { const { value } = await waitForResult(); - expect(value.map((v: BN) => v.toHex())).toStrictEqual([ + expect(value.map((v: BN | undefined) => v?.toHex())).toStrictEqual([ bn(3).toHex(), bn(450).toHex(), bn(202).toHex(), @@ -761,7 +763,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { it('should support array in vec', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: [Vec, Vec] = [ [0, 1, 2], [0, 1, 2], ]; diff --git a/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts b/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts index 663dfee54a6..729f6dbd1a1 100644 --- a/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts +++ b/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts @@ -14,6 +14,7 @@ import { MultiTokenContractFactory, RevertErrorFactory, } from '../test/typegen/contracts'; +import type { AddressInput } from '../test/typegen/contracts/MultiTokenContract'; /** * @group node @@ -146,7 +147,7 @@ describe('dry-run-multiple-txs', () => { const resources = await wallet.getResourcesToSpend([[500_000, provider.getBaseAssetId()]]); // creating receives to be used by the request 2 and 3 - const addresses = [ + const addresses: [AddressInput, AddressInput, AddressInput] = [ { bits: Wallet.generate({ provider }).address.toB256() }, { bits: Wallet.generate({ provider }).address.toB256() }, { bits: Wallet.generate({ provider }).address.toB256() }, diff --git a/packages/fuel-gauge/src/fee.test.ts b/packages/fuel-gauge/src/fee.test.ts index df63d5bbe7f..fb57c3475d0 100644 --- a/packages/fuel-gauge/src/fee.test.ts +++ b/packages/fuel-gauge/src/fee.test.ts @@ -7,6 +7,7 @@ import { MultiTokenContract, MultiTokenContractFactory, } from '../test/typegen/contracts'; +import type { AddressInput } from '../test/typegen/contracts/MultiTokenContract'; import { PredicateU32 } from '../test/typegen/predicates/PredicateU32'; /** @@ -276,8 +277,10 @@ describe('Fee', () => { const genAddresses = () => Array.from({ length: 3 }, () => ({ bits: getRandomB256() })); + const addresses = genAddresses() as [AddressInput, AddressInput, AddressInput]; + const calls = Array.from({ length: 15 }).map(() => - contract.functions.mint_to_addresses(genAddresses(), subId, 100) + contract.functions.mint_to_addresses(addresses, subId, 100) ); const balanceBefore = await wallet.getBalance(); diff --git a/packages/fuel-gauge/src/generic-types-contract.test.ts b/packages/fuel-gauge/src/generic-types-contract.test.ts index b963730d629..a10d27b2bbe 100644 --- a/packages/fuel-gauge/src/generic-types-contract.test.ts +++ b/packages/fuel-gauge/src/generic-types-contract.test.ts @@ -1,5 +1,6 @@ import { toHex } from 'fuels'; +import type { GenericTypesContract } from '../test/typegen/contracts'; import { GenericTypesContractFactory } from '../test/typegen/contracts'; import { launchTestContract } from './utils'; @@ -74,6 +75,8 @@ describe('GenericTypesContract', () => { const { value } = await call1.waitForResult(); + type ComplexFnType = GenericTypesContract['functions']['generic_complex_type_function']; + const arg1 = { bim: toHex(1), bam: true, @@ -83,7 +86,7 @@ describe('GenericTypesContract', () => { b: toHex(32), }, foo_list: new Array(10).fill(b256), - }; + } as Parameters[0]; const arg2 = { bim: toHex(1), bam: 2, @@ -99,7 +102,7 @@ describe('GenericTypesContract', () => { x: toHex(31), b: toHex(32), }), - }; + } as Parameters[1]; const call2 = await contract.functions.generic_complex_type_function(arg1, arg2).call(); const { value: value2 } = await call2.waitForResult(); diff --git a/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts b/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts index 795bc417174..c4a8b535128 100644 --- a/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts +++ b/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts @@ -50,9 +50,7 @@ describe('PredicateConditionalInputs', () => { .addResources(predicateResoruces) .addCoinOutput(aliceWallet.address, amountToTransfer, ASSET_A); - const txCost = await aliceWallet.getTransactionCost(request, { - resourcesOwner: aliceWallet, - }); + const txCost = await aliceWallet.getTransactionCost(request); request.gasLimit = txCost.gasUsed; request.maxFee = txCost.maxFee; diff --git a/packages/fuel-gauge/src/raw-slice.test.ts b/packages/fuel-gauge/src/raw-slice.test.ts index 0eede1c9a6d..dc589c921db 100644 --- a/packages/fuel-gauge/src/raw-slice.test.ts +++ b/packages/fuel-gauge/src/raw-slice.test.ts @@ -138,7 +138,7 @@ describe('Raw Slice Tests', () => { const scriptInstance = new ScriptRawSlice(wallet); const bytes = [40, 41, 42]; - const INPUT: Wrapper = { + const INPUT = { inner: [bytes, bytes], inner_enum: { Second: bytes }, }; diff --git a/packages/fuel-gauge/src/script-with-configurable.test.ts b/packages/fuel-gauge/src/script-with-configurable.test.ts index f294cfe02b7..3fdb883659c 100644 --- a/packages/fuel-gauge/src/script-with-configurable.test.ts +++ b/packages/fuel-gauge/src/script-with-configurable.test.ts @@ -3,7 +3,7 @@ import { launchTestNode } from 'fuels/test-utils'; import { ScriptWithConfigurable } from '../test/typegen'; import type { ScriptWithConfigurableConfigurables } from '../test/typegen/scripts/ScriptWithConfigurable'; -const defaultValues: ScriptWithConfigurableConfigurables = { +const defaultValues: Required = { FEE: 5, }; @@ -36,7 +36,7 @@ describe('Script With Configurable', () => { wallets: [wallet], } = launched; - const configurableConstants: ScriptWithConfigurableConfigurables = { FEE: 71 }; + const configurableConstants: Required = { FEE: 71 }; expect(configurableConstants.FEE).not.toEqual(defaultValues.FEE); @@ -57,7 +57,7 @@ describe('Script With Configurable', () => { wallets: [wallet], } = launched; - const configurableConstants: ScriptWithConfigurableConfigurables = { FEE: 35 }; + const configurableConstants: Required = { FEE: 35 }; const script = new ScriptWithConfigurable(wallet); diff --git a/packages/fuel-gauge/src/script-with-vectors.test.ts b/packages/fuel-gauge/src/script-with-vectors.test.ts index 6322f6caa9f..77c4daa804c 100644 --- a/packages/fuel-gauge/src/script-with-vectors.test.ts +++ b/packages/fuel-gauge/src/script-with-vectors.test.ts @@ -1,3 +1,4 @@ +import type { BigNumberish } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; import { @@ -6,6 +7,7 @@ import { ScriptWithVectorAdvanced, ScriptWithVectorMixed, } from '../test/typegen'; +import { StateErrorInput, UserErrorInput } from '../test/typegen/scripts/ScriptWithVectorAdvanced'; /** * @group node @@ -19,7 +21,7 @@ describe('Script With Vectors', () => { wallets: [wallet], } = launched; - const someArray = [1, 100]; + const someArray: [BigNumberish, BigNumberish] = [1, 100]; const scriptInstance = new ScriptWithArray(wallet); const { waitForResult } = await scriptInstance.functions.main(someArray).call(); @@ -109,7 +111,7 @@ describe('Script With Vectors', () => { wallets: [wallet], } = launched; - const scores = [24, 56, 43]; + const scores: number[] = [24, 56, 43]; const importantDates = [ { @@ -142,15 +144,15 @@ describe('Script With Vectors', () => { ]; const errors = [ - { StateError: 'Void' }, - { StateError: 'Pending' }, - { StateError: 'Completed' }, - { UserError: 'InsufficientPermissions' }, - { UserError: 'Unauthorized' }, - { UserError: 'Unauthorized' }, - { UserError: 'Unauthorized' }, - { UserError: 'Unauthorized' }, - { UserError: 'Unauthorized' }, + { StateError: StateErrorInput.Void }, + { StateError: StateErrorInput.Pending }, + { StateError: StateErrorInput.Completed }, + { UserError: UserErrorInput.InsufficientPermissions }, + { UserError: UserErrorInput.Unauthorized }, + { UserError: UserErrorInput.Unauthorized }, + { UserError: UserErrorInput.Unauthorized }, + { UserError: UserErrorInput.Unauthorized }, + { UserError: UserErrorInput.Unauthorized }, ]; const vectorOfStructs = [ diff --git a/packages/fuel-gauge/src/token-test-contract.test.ts b/packages/fuel-gauge/src/token-test-contract.test.ts index 96796bc9614..5a930e59060 100644 --- a/packages/fuel-gauge/src/token-test-contract.test.ts +++ b/packages/fuel-gauge/src/token-test-contract.test.ts @@ -4,6 +4,7 @@ import { toHex, Wallet, bn } from 'fuels'; import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { TokenContractFactory } from '../test/typegen'; +import type { AddressInput } from '../test/typegen/contracts/TokenContract'; /** * @group node @@ -80,7 +81,7 @@ describe('TokenTestContract', () => { const addresses = [wallet1, wallet2, wallet3].map((wallet) => ({ bits: wallet.address.toB256(), - })); + })) as [AddressInput, AddressInput, AddressInput]; const functionCallOne = token.functions.mint_to_addresses(addresses, 10); await functionCallOne.dryRun(); @@ -195,6 +196,8 @@ describe('TokenTestContract', () => { const assetId: AssetId = { bits: provider.getBaseAssetId() }; await expectToThrowFuelError( + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore () => token.functions.transfer_to_address(addressParameter, assetId, 50).call(), new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid b256.') ); diff --git a/packages/fuel-gauge/src/transaction-response.test.ts b/packages/fuel-gauge/src/transaction-response.test.ts index 4b41d42283b..6cbe72e68db 100644 --- a/packages/fuel-gauge/src/transaction-response.test.ts +++ b/packages/fuel-gauge/src/transaction-response.test.ts @@ -97,9 +97,9 @@ describe('TransactionResponse', () => { const response = await TransactionResponse.create(transactionId, provider); - expect(response.gqlTransaction).toBeDefined(); - expect(response.gqlTransaction?.status).toBeDefined(); - expect(response.gqlTransaction?.id).toBe(transactionId); + const { id } = await response.assembleResult(); + + expect(id).toEqual(transactionId); }); it('should ensure getTransactionSummary fetches a transaction and assembles transaction summary', async () => { @@ -147,10 +147,6 @@ describe('TransactionResponse', () => { expect(transactionSummary.isStatusSuccess).toBeDefined(); expect(transactionSummary.isStatusPending).toBeDefined(); expect(transactionSummary.transaction).toBeDefined(); - - expect(response.gqlTransaction).toBeDefined(); - expect(response.gqlTransaction?.status).toBeDefined(); - expect(response.gqlTransaction?.id).toBe(transactionId); }); it.skip( @@ -186,8 +182,6 @@ describe('TransactionResponse', () => { ); const response = await TransactionResponse.create(transactionId, provider); - expect(response.gqlTransaction?.status?.type).toBe('SubmittedStatus'); - const subscriptionStreamHolder = { stream: new ReadableStream(), }; @@ -196,9 +190,6 @@ describe('TransactionResponse', () => { await response.waitForResult(); - expect(response.gqlTransaction?.status?.type).toEqual('SuccessStatus'); - expect(response.gqlTransaction?.id).toBe(transactionId); - await verifyKeepAliveMessageWasSent(subscriptionStreamHolder.stream); } ); diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index 94320a18a44..856ac089b1c 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -21,6 +21,7 @@ import { import { ASSET_A, ASSET_B, launchTestNode, TestMessage } from 'fuels/test-utils'; import { MultiTokenContractFactory, TokenContractFactory } from '../test/typegen'; +import type { ContractIdInput, TransferParamsInput } from '../test/typegen/contracts/TokenContract'; function convertBnsToHex(value: unknown): unknown { if (value instanceof BN) { @@ -468,6 +469,12 @@ describe('TransactionSummary', () => { asset_id: { bits: assetId }, amount, })), + ] as [ + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, ]) .call(); @@ -593,6 +600,12 @@ describe('TransactionSummary', () => { asset_id: { bits: assetId }, amount, })), + ] as [ + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, + TransferParamsInput, ]) .call(); diff --git a/packages/fuel-gauge/src/vector-types.test.ts b/packages/fuel-gauge/src/vector-types.test.ts index 286a951eac2..0c349870559 100644 --- a/packages/fuel-gauge/src/vector-types.test.ts +++ b/packages/fuel-gauge/src/vector-types.test.ts @@ -1,3 +1,4 @@ +import type { BigNumberish } from 'fuels'; import { bn, Predicate, Wallet, Address } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; @@ -7,6 +8,9 @@ import { VectorTypesScript } from '../test/typegen/scripts'; import { launchTestContract } from './utils'; +type ArrayOfTuplesType = [BigNumberish, BigNumberish][]; +type TupleOfArraysType = [BigNumberish[], BigNumberish[]]; + const U32_VEC = [0, 1, 2]; const VEC_IN_VEC = [ [0, 1, 2], @@ -14,21 +18,21 @@ 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: ArrayOfTuplesType = [ [0, 1], [0, 1], ]; -const VEC_IN_ARRAY = [ +const VEC_IN_ARRAY: TupleOfArraysType = [ [0, 1, 2], [0, 1, 2], ]; const VEC_IN_ENUM = { a: [0, 1, 2] }; const ENUM_IN_VEC = [{ a: 0 }, { a: 1 }]; -const TUPLE_IN_VEC = [ +const TUPLE_IN_VEC: ArrayOfTuplesType = [ [0, 0], [1, 1], ]; -const VEC_IN_TUPLE = [ +const VEC_IN_TUPLE: TupleOfArraysType = [ [0, 1, 2], [0, 1, 2], ]; @@ -67,12 +71,12 @@ type MainArgs = [ TwoDimensionArray, // VEC_IN_VEC SomeStruct[], // STRUCT_IN_VEC SomeStructWithVec, // VEC_IN_STRUCT - TwoDimensionArray, // ARRAY_IN_VEC - TwoDimensionArray, // VEC_IN_ARRAY + ArrayOfTuplesType, // ARRAY_IN_VEC + TupleOfArraysType, // VEC_IN_ARRAY SomeStructWithVec, // VEC_IN_ENUM SomeStruct[], // ENUM_IN_VEC - TwoDimensionArray, // TUPLE_IN_VEC - TwoDimensionArray, // VEC_IN_TUPLE + ArrayOfTuplesType, // TUPLE_IN_VEC + TupleOfArraysType, // VEC_IN_TUPLE VecInAStructInAVec, // VEC_IN_A_VEC_IN_A_STRUCT_IN_A_VEC ]; diff --git a/packages/fuel-gauge/src/vectors.test.ts b/packages/fuel-gauge/src/vectors.test.ts index b2481f18814..b05a665e8ae 100644 --- a/packages/fuel-gauge/src/vectors.test.ts +++ b/packages/fuel-gauge/src/vectors.test.ts @@ -1,5 +1,5 @@ import { bn, randomBytes, hexlify } from 'fuels'; -import type { BN } from 'fuels'; +import type { BigNumberish, BN } from 'fuels'; import { VectorsFactory } from '../test/typegen/contracts'; import { SmallEnumInput } from '../test/typegen/contracts/CoverageContract'; @@ -119,7 +119,7 @@ describe('Vector Tests', () => { it('should test (u8, u8) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Array<[BigNumberish, BigNumberish]> = [ [1, 2], [3, 4], [5, 6], @@ -136,7 +136,7 @@ describe('Vector Tests', () => { it('should test (u64, u64) vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: [BigNumberish, BigNumberish][] = [ [111, 2222], [333, 4445], [5555, 6], @@ -151,7 +151,7 @@ describe('Vector Tests', () => { it('should test [u8; 2] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Array<[BigNumberish, BigNumberish]> = [ [1, 2], [5, 6], ]; @@ -167,7 +167,7 @@ describe('Vector Tests', () => { it('should test [u64; 5] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Array<[BigNumberish, BigNumberish, BigNumberish, BigNumberish, BigNumberish]> = [ [1, 2, 3, 4, 5], [500, 600, 700, 9000, 9999], [11500, 22600, 33700, 55000, 669999], @@ -182,7 +182,7 @@ describe('Vector Tests', () => { it('should test [bool; 2] vector input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: Array<[boolean, boolean]> = [ [true, true], [true, false], [false, true], @@ -403,7 +403,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: [Array, string] = [[1, 8, 3, 2, 55, 215], hexlify(randomBytes(32))]; const { waitForResult } = await contractInstance.functions .echo_vector_and_b256_tuple(...INPUT) @@ -416,7 +416,7 @@ describe('Vector Tests', () => { it('should test two vectors tuple input/output', async () => { using contractInstance = await setupContract(); - const INPUT = [ + const INPUT: [Array, Array] = [ [219, 229], [1, 254, 55], ]; @@ -432,7 +432,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: [number, boolean[], number[], number[]] = [ + 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/src/void.test.ts b/packages/fuel-gauge/src/void.test.ts index d2012529c8d..bdd24c8003a 100644 --- a/packages/fuel-gauge/src/void.test.ts +++ b/packages/fuel-gauge/src/void.test.ts @@ -1,7 +1,7 @@ import { launchTestNode } from 'fuels/test-utils'; import { VoidFactory } from '../test/typegen'; -import type { NativeEnumInput } from '../test/typegen/contracts/VoidAbi'; +import type { NativeEnumInput } from '../test/typegen/contracts/Void'; import type { Option } from '../test/typegen/contracts/common'; /**