Skip to content

Commit

Permalink
fix: remove node specific testing utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jul 12, 2024
1 parent 5cb3ce1 commit 9d306ed
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 70 deletions.
17 changes: 6 additions & 11 deletions packages/fuel-gauge/src/bytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { bn, Predicate, Wallet, Address } from 'fuels';
import type { BN } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { FuelGaugeProjectsEnum, getFuelGaugeForcProject } from '../test/fixtures';
import { PredicateBytesAbi__factory, ScriptBytesAbi__factory } from '../test/typegen';
import { BytesAbi__factory } from '../test/typegen/contracts';
import BytesAbiHex from '../test/typegen/contracts/BytesAbi.hex';

import { getScript, launchTestContract } from './utils';
import { launchTestContract } from './utils';

type SomeEnum = {
First?: boolean;
Expand Down Expand Up @@ -106,19 +106,15 @@ describe('Bytes Tests', () => {
const amountToReceiver = 50;
type MainArgs = [Wrapper];

const { binHexlified, abiContents } = getFuelGaugeForcProject(
FuelGaugeProjectsEnum.PREDICATE_BYTES
);

const bytes = [40, 41, 42];
const INPUT: Wrapper = {
inner: [bytes, bytes],
inner_enum: { Second: bytes },
};

const predicate = new Predicate<MainArgs>({
bytecode: binHexlified,
abi: abiContents,
bytecode: PredicateBytesAbi__factory.bin,
abi: PredicateBytesAbi__factory.abi,
provider: wallet.provider,
inputData: [INPUT],
});
Expand Down Expand Up @@ -167,15 +163,14 @@ describe('Bytes Tests', () => {
wallets: [wallet],
} = launched;

type MainArgs = [number, Wrapper];
const scriptInstance = getScript<MainArgs, void>('script-bytes', wallet);

const bytes = [40, 41, 42];
const INPUT: Wrapper = {
inner: [bytes, bytes],
inner_enum: { Second: bytes },
};

const scriptInstance = ScriptBytesAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions.main(1, INPUT).call<BN>();
const { value } = await waitForResult();

Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/e2e-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
assets,
} from 'fuels';

import { getScript } from './utils';
import { ScriptMainArgBoolAbi__factory } from '../test/typegen';

enum Networks {
DEVNET = 'devnet',
Expand Down Expand Up @@ -81,7 +81,7 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => {
return;
}

const scriptInstance = getScript<[boolean], boolean>('script-main-arg-bool', wallet);
const scriptInstance = ScriptMainArgBoolAbi__factory.createInstance(wallet);

let output: boolean = false;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-gauge/src/funding-transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AssetId, launchTestNode } from 'fuels/test-utils';
* @group node
* @group browser
*/
describe(__filename, () => {
describe('Funding Transactions', () => {
const assetA = '0x0101010101010101010101010101010101010101010101010101010101010101';
const assetB = '0x0202020202020202020202020202020202020202020202020202020202020202';

Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-gauge/src/min-gas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CoverageContractAbiHex from '../test/typegen/contracts/CoverageContractAb
* @group node
* @group browser
*/
describe(__filename, () => {
describe('Minimum gas tests', () => {
it('sets gas requirements (contract)', async () => {
using launched = await launchTestNode({
walletsConfig: {
Expand Down
6 changes: 3 additions & 3 deletions packages/fuel-gauge/src/raw-slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { bn, Predicate, Wallet, Address } from 'fuels';
import type { BN } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { ScriptRawSliceAbi__factory } from '../test/typegen';
import { RawSliceAbi__factory } from '../test/typegen/contracts';
import RawSliceAbiHex from '../test/typegen/contracts/RawSliceAbi.hex';
import { PredicateRawSliceAbi__factory } from '../test/typegen/predicates';

import { getScript, launchTestContract } from './utils';
import { launchTestContract } from './utils';

type SomeEnum = {
First?: boolean;
Expand Down Expand Up @@ -136,8 +137,7 @@ describe('Raw Slice Tests', () => {
wallets: [wallet],
} = launched;

type MainArgs = [number, Wrapper];
const scriptInstance = getScript<MainArgs, void>('script-raw-slice', wallet);
const scriptInstance = ScriptRawSliceAbi__factory.createInstance(wallet);

const bytes = [40, 41, 42];
const INPUT: Wrapper = {
Expand Down
12 changes: 7 additions & 5 deletions packages/fuel-gauge/src/script-main-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { BigNumberish } from 'fuels';
import { bn, Script } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { ScriptMainArgsAbi__factory } from '../test/typegen';

import { getScript } from './utils';
import {
ScriptMainArgsAbi__factory,
ScriptMainReturnStructAbi__factory,
ScriptMainTwoArgsAbi__factory,
} from '../test/typegen';

type Baz = {
x: number;
Expand Down Expand Up @@ -44,7 +46,7 @@ describe('Script Coverage', () => {
wallets: [wallet],
} = launched;

const scriptInstance = getScript<[BigNumberish, Baz], Baz>('script-main-two-args', wallet);
const scriptInstance = ScriptMainTwoArgsAbi__factory.createInstance(wallet);
const foo = 33;
const bar: Baz = {
x: 12,
Expand All @@ -63,7 +65,7 @@ describe('Script Coverage', () => {
wallets: [wallet],
} = launched;

const scriptInstance = getScript<[BigNumberish, Baz], Baz>('script-main-return-struct', wallet);
const scriptInstance = ScriptMainReturnStructAbi__factory.createInstance(wallet);
const foo = 1;
const bar: Baz = {
x: 2,
Expand Down
18 changes: 10 additions & 8 deletions packages/fuel-gauge/src/script-with-vectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { BigNumberish } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { getScript } from './utils';
import {
ScriptWithArrayAbi__factory,
ScriptWithVectorAbi__factory,
ScriptWithVectorAdvancedAbi__factory,
ScriptWithVectorMixedAbi__factory,
} from '../test/typegen';

/**
* @group node
Expand All @@ -20,7 +24,7 @@ describe('Script With Vectors', () => {
} = launched;

const someArray = [1, 100];
const scriptInstance = getScript<[BigNumberish[]], void>('script-with-array', wallet);
const scriptInstance = ScriptWithArrayAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions.main(someArray).call();
const { logs } = await waitForResult();
Expand All @@ -40,7 +44,7 @@ describe('Script With Vectors', () => {
} = launched;

const someVec = [7, 2, 1, 5];
const scriptInstance = getScript<[BigNumberish[]], void>('script-with-vector', wallet);
const scriptInstance = ScriptWithVectorAbi__factory.createInstance(wallet);

const scriptInvocationScope = scriptInstance.functions.main(someVec);

Expand Down Expand Up @@ -103,8 +107,7 @@ describe('Script With Vectors', () => {
},
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const scriptInstance = getScript<[any], void>('script-with-vector-mixed', wallet);
const scriptInstance = ScriptWithVectorMixedAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions.main(importantDates).call();
const { value } = await waitForResult();
Expand Down Expand Up @@ -179,8 +182,7 @@ describe('Script With Vectors', () => {
},
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const scriptInstance = getScript<[any[]], void>('script-with-vector-advanced', wallet);
const scriptInstance = ScriptWithVectorAdvancedAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions.main(vectorOfStructs).call();
const { value } = await waitForResult();
Expand Down
11 changes: 7 additions & 4 deletions packages/fuel-gauge/src/std-lib-string.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { bn, Predicate, Wallet, Address } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { PredicateStdLibStringAbi__factory, StdLibStringAbi__factory } from '../test/typegen';
import {
PredicateStdLibStringAbi__factory,
ScriptStdLibStringAbi__factory,
StdLibStringAbi__factory,
} from '../test/typegen';
import StdLibStringAbiHex from '../test/typegen/contracts/StdLibStringAbi.hex';

import { getScript, launchTestContract } from './utils';
import { launchTestContract } from './utils';

/**
* @group node
Expand Down Expand Up @@ -105,9 +109,8 @@ describe('std-lib-string Tests', () => {
wallets: [wallet],
} = launched;

type MainArgs = [string];
const scriptInstance = getScript<MainArgs, void>('script-std-lib-string', wallet);
const INPUT = 'Hello World';
const scriptInstance = ScriptStdLibStringAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions.main(INPUT).call();
const { value } = await waitForResult();
Expand Down
32 changes: 0 additions & 32 deletions packages/fuel-gauge/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
import { readFileSync } from 'fs';
import { Script } from 'fuels';
import type { Interface, WalletUnlocked, JsonAbi, BytesLike } from 'fuels';
import type { DeployContractConfig } from 'fuels/test-utils';
import { launchTestNode } from 'fuels/test-utils';
import { join } from 'path';

export type SetupConfig = {
contractBytecode: BytesLike;
abi: JsonAbi | Interface;
cache?: boolean;
};

const getFullPath = <T>(contractName: string, next: (fullPath: string) => T) =>
next(
join(__dirname, `../test/fixtures/forc-projects/${contractName}/out/release/${contractName}`)
);

export const getScript = <TInput extends unknown[], TOutput>(
scriptName: string,
wallet: WalletUnlocked
): Script<TInput, TOutput> =>
getFullPath(
scriptName,
(fullPath: string) =>
new Script(
readFileSync(`${fullPath}.bin`),
JSON.parse(readFileSync(`${fullPath}-abi.json`, 'utf8')),
wallet
)
);

export const getProgramDir = (name: string) =>
join(__dirname, `../test/fixtures/forc-projects/${name}`);

export async function launchTestContract<T extends DeployContractConfig>(config: T) {
const {
Expand Down
7 changes: 4 additions & 3 deletions packages/fuel-gauge/src/vector-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 { PredicateVectorTypesAbi__factory } from '../test/typegen/predicates';

import { getScript, launchTestContract } from './utils';
import { launchTestContract } from './utils';

const U32_VEC = [0, 1, 2];
const VEC_IN_VEC = [
Expand Down Expand Up @@ -114,7 +114,8 @@ describe('Vector Types Validation', () => {
const {
wallets: [wallet],
} = launched;
const scriptInstance = getScript<MainArgs, BigNumberish>('vector-types-script', wallet);

const scriptInstance = VectorTypesScriptAbi__factory.createInstance(wallet);

const { waitForResult } = await scriptInstance.functions
.main(
Expand Down

0 comments on commit 9d306ed

Please sign in to comment.