Skip to content

Commit

Permalink
chore: remove TS errors from some tests (#3026)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf committed Aug 26, 2024
1 parent e14f7d4 commit 682d62e
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 240 deletions.
4 changes: 4 additions & 0 deletions .changeset/fast-walls-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: remove TS errors from some tests
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +16,7 @@ describe('Interacting with Predicates', () => {
fundedWallet: WalletUnlocked,
inputData: [string],
abi: JsonAbi,
bytecode: string,
bytecode: BytesLike,
configurableConstants?: Record<string, unknown>
): Promise<Predicate<string[]>> {
const predicate = new Predicate({
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-snippets/src/guide/types/conversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ describe('Conversion Types', () => {
const assetId: AssetId = address.toAssetId();
// #endregion conversion-4

expect(assetId.value);
expect(assetId.bits).toEqual(b256);
});
});
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-coder/src/utils/getFunctionInputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonAbi, JsonAbiArgument, JsonAbiType } from '../types/JsonAbi';
import type { JsonAbiArgument, JsonAbiOld, JsonAbiType } from '../types/JsonAbi';

import { getFunctionInputs } from './getFunctionInputs';

Expand Down Expand Up @@ -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: [],
Expand Down
9 changes: 6 additions & 3 deletions packages/abi-coder/src/utils/json-abi.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: [] },
Expand All @@ -20,7 +22,8 @@ const MOCK_ABI: JsonAbiOld = {
],
loggedTypes: [],
configurables: [],
};
messagesTypes: [],
});

const DEFAULT_ENCODING_VERSION = ENCODING_V1;

Expand Down
9 changes: 4 additions & 5 deletions packages/abi-coder/test/Interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -112,7 +111,7 @@ describe('Abi interface', () => {
describe('configurables', () => {
it('sets configurables as dictionary', () => {
const dict = exhaustiveExamplesAbi.configurables.reduce((obj, val) => {
const o: Record<string, JsonAbiConfigurable> = obj;
const o: Record<string, Configurable> = obj;
o[val.name] = val;
return o;
}, {});
Expand Down Expand Up @@ -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
Expand All @@ -623,7 +622,7 @@ describe('Abi interface', () => {
)[0];

if (decodedTransformer) {
decodedType = decodedTransformer(decodedType);
decodedType = decodedTransformer(decodedType as any[]);
}

expect(decodedType).toEqual(expectedDecoded);
Expand Down
1 change: 1 addition & 0 deletions packages/abi-typegen/src/utils/makeFunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/abi-typegen/src/utils/parseFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
164 changes: 2 additions & 162 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
Expand All @@ -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);
});
Expand Down
Loading

0 comments on commit 682d62e

Please sign in to comment.