Skip to content

Commit

Permalink
chore: revert(add browser testing infrastructure) (#2618)
Browse files Browse the repository at this point in the history
* Revert "chore: add browser testing infrastructure (#2378)"

This reverts commit 04b58e2.

* chore: changeset

* chore: empty changeset

---------

Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
petertonysmith94 and arboleya committed Jun 25, 2024
1 parent 41647a8 commit 6184bc9
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 376 deletions.
5 changes: 0 additions & 5 deletions .changeset/serious-dogs-wash.md

This file was deleted.

2 changes: 2 additions & 0 deletions .changeset/two-nails-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 1 addition & 2 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { randomBytes } from '@fuel-ts/crypto';
import type { SnapshotConfigs } from '@fuel-ts/utils';
import { defaultConsensusKey, hexlify, defaultSnapshotConfigs } from '@fuel-ts/utils';
import type { ChildProcessWithoutNullStreams } from 'child_process';
import { spawn } from 'child_process';
import { randomUUID } from 'crypto';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'fs';
import os from 'os';
Expand Down Expand Up @@ -216,8 +217,6 @@ export const launchNode = async ({
snapshotDirToUse = tempDir;
}

const { spawn } = await import('child_process');

const child = spawn(
command,
[
Expand Down
24 changes: 2 additions & 22 deletions packages/account/src/test-utils/setup-test-provider-and-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface LaunchCustomProviderAndGetWalletsOptions {
snapshotConfig: PartialDeep<SnapshotConfigs>;
}
>;
launchNodeServerPort?: string;
}

const defaultWalletConfigOptions: WalletsConfigOptions = {
Expand Down Expand Up @@ -53,7 +52,6 @@ export async function setupTestProviderAndWallets({
walletsConfig: walletsConfigOptions = {},
providerOptions,
nodeOptions = {},
launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || undefined,
}: Partial<LaunchCustomProviderAndGetWalletsOptions> = {}): Promise<SetupTestProviderAndWalletsReturn> {
// @ts-expect-error this is a polyfill (see https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management)
Symbol.dispose ??= Symbol('Symbol.dispose');
Expand All @@ -66,33 +64,15 @@ export async function setupTestProviderAndWallets({
}
);

const launchNodeOptions: LaunchNodeOptions = {
const { cleanup, url } = await launchNode({
loggingEnabled: false,
...nodeOptions,
snapshotConfig: mergeDeepRight(
defaultSnapshotConfigs,
walletsConfig.apply(nodeOptions?.snapshotConfig)
),
port: '0',
};

let cleanup: () => void;
let url: string;
if (launchNodeServerPort) {
const serverUrl = `http://localhost:${launchNodeServerPort}`;
url = await (
await fetch(serverUrl, { method: 'POST', body: JSON.stringify(launchNodeOptions) })
).text();

cleanup = () => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fetch(`${serverUrl}/cleanup/${url}`);
};
} else {
const settings = await launchNode(launchNodeOptions);
url = settings.url;
cleanup = settings.cleanup;
}
});

let provider: Provider;

Expand Down
47 changes: 22 additions & 25 deletions packages/fuel-gauge/src/call-test-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import { ASSET_A } from '@fuel-ts/utils/test-utils';
import type { Contract } from 'fuels';
import { BN, bn, toHex } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import type { CallTestContractAbi } from '../test/typegen/contracts';
import { CallTestContractAbi__factory } from '../test/typegen/contracts';
import bytecode from '../test/typegen/contracts/CallTestContractAbi.hex';

const setupContract = async () => {
const {
contracts: [contract],
cleanup,
} = await launchTestNode({
contractsConfigs: [{ deployer: CallTestContractAbi__factory, bytecode }],
});
return Object.assign(contract, { [Symbol.dispose]: cleanup });
};
import binHexlified from '../test/typegen/contracts/CallTestContractAbi.hex';

import { createSetupConfig } from './utils';

const setupContract = createSetupConfig<CallTestContractAbi>({
contractBytecode: binHexlified,
abi: CallTestContractAbi__factory.abi,
cache: true,
});

const U64_MAX = bn(2).pow(64).sub(1);

/**
* @group node
* @group browser
*/
describe('CallTestContract', () => {
it.each([0, 1337, U64_MAX.sub(1)])('can call a contract with u64 (%p)', async (num) => {
using contract = await setupContract();
const contract = await setupContract();
const { value } = await contract.functions.foo(num).call();
expect(value.toHex()).toEqual(bn(num).add(1).toHex());
});
Expand All @@ -37,14 +34,14 @@ describe('CallTestContract', () => {
[{ a: false, b: U64_MAX.sub(1) }],
[{ a: true, b: U64_MAX.sub(1) }],
])('can call a contract with structs (%p)', async (struct) => {
using contract = await setupContract();
const contract = await setupContract();
const { value } = await contract.functions.boo(struct).call();
expect(value.a).toEqual(!struct.a);
expect(value.b.toHex()).toEqual(bn(struct.b).add(1).toHex());
});

it('can call a function with empty arguments', async () => {
using contract = await setupContract();
const contract = await setupContract();

const { value: empty } = await contract.functions.empty().call();
expect(empty.toHex()).toEqual(toHex(63));
Expand All @@ -62,7 +59,7 @@ describe('CallTestContract', () => {
});

it('function with empty return should resolve undefined', async () => {
using contract = await setupContract();
const contract = await setupContract();

// Call method with no params but with no result and no value on config
const { value } = await contract.functions.return_void().call();
Expand Down Expand Up @@ -139,9 +136,9 @@ describe('CallTestContract', () => {
async (method, { values, expected }) => {
// Type cast to Contract because of the dynamic nature of the test
// But the function names are type-constrained to correct Contract's type
using contract = await setupContract();
const contract = (await setupContract()) as Contract;

const { value } = await (contract as Contract).functions[method](...values).call();
const { value } = await contract.functions[method](...values).call();

if (BN.isBN(value)) {
expect(toHex(value)).toBe(toHex(expected));
Expand All @@ -152,7 +149,7 @@ describe('CallTestContract', () => {
);

it('Forward amount value on contract call', async () => {
using contract = await setupContract();
const contract = await setupContract();
const baseAssetId = contract.provider.getBaseAssetId();
const { value } = await contract.functions
.return_context_amount()
Expand All @@ -164,7 +161,7 @@ describe('CallTestContract', () => {
});

it('Forward asset_id on contract call', async () => {
using contract = await setupContract();
const contract = await setupContract();

const assetId = ASSET_A;
const { value } = await contract.functions
Expand All @@ -177,7 +174,7 @@ describe('CallTestContract', () => {
});

it('Forward asset_id on contract simulate call', async () => {
using contract = await setupContract();
const contract = await setupContract();

const assetId = ASSET_A;
const { value } = await contract.functions
Expand All @@ -190,7 +187,7 @@ describe('CallTestContract', () => {
});

it('can make multiple calls', async () => {
using contract = await setupContract();
const contract = await setupContract();

const num = 1337;
const numC = 10;
Expand Down Expand Up @@ -225,14 +222,14 @@ describe('CallTestContract', () => {
});

it('Calling a simple contract function does only one dry run', async () => {
using contract = await setupContract();
const contract = await setupContract();
const dryRunSpy = vi.spyOn(contract.provider.operations, 'dryRun');
await contract.functions.no_params().call();
expect(dryRunSpy).toHaveBeenCalledOnce();
});

it('Simulating a simple contract function does two dry runs', async () => {
using contract = await setupContract();
const contract = await setupContract();
const dryRunSpy = vi.spyOn(contract.provider.operations, 'dryRun');

await contract.functions.no_params().simulate();
Expand Down
131 changes: 0 additions & 131 deletions packages/fuels/src/setup-launch-node-server.test.ts

This file was deleted.

Loading

0 comments on commit 6184bc9

Please sign in to comment.