Skip to content

Commit

Permalink
test: using getForcProject instead of manually reading files (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Nov 18, 2023
1 parent d608f3e commit e3a798f
Show file tree
Hide file tree
Showing 88 changed files with 670 additions and 418 deletions.
2 changes: 2 additions & 0 deletions .changeset/healthy-rings-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
9 changes: 6 additions & 3 deletions apps/docs-snippets/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getForcProject } from '@fuel-ts/utils/test-utils';
import type { JsonAbi } from 'fuels';
import { join } from 'path';

export enum SnippetProjectEnum {
export enum DocSnippetProjectsEnum {
COUNTER = 'counter',
ECHO_ENUM = 'echo-enum',
LOG_VALUES = 'log-values',
Expand All @@ -26,5 +26,8 @@ export enum SnippetProjectEnum {
SCRIPT_TRANSFER_TO_CONTRACT = 'script-transfer-to-contract',
}

export const getSnippetProjectArtifacts = (project: SnippetProjectEnum) =>
getForcProject<JsonAbi>(join(__dirname, project));
export const getDocsSnippetsForcProject = (project: DocSnippetProjectsEnum) =>
getForcProject<JsonAbi>({
projectDir: join(__dirname, project),
projectName: project,
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Contract, Provider } from 'fuels';
import { BN, BaseAssetId } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;
let provider: Provider;
beforeAll(async () => {
contract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.RETURN_CONTEXT);
provider = contract.provider;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { Contract } from 'fuels';
import { FUEL_NETWORK_URL, Provider, WalletUnlocked } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let deployedContract: Contract;

beforeAll(async () => {
deployedContract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
deployedContract = await createAndDeployContractFromProject(
DocSnippetProjectsEnum.RETURN_CONTEXT
);
});

it('should successfully update contract instance wallet', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Provider, WalletUnlocked } from 'fuels';
import { ContractFactory } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
let wallet: WalletUnlocked;

const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_CONFIGURABLES
const { abiContents: abi, binHexlified: bin } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.ECHO_CONFIGURABLES
);

const defaultValues = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Contract } from 'fuels';
import { Wallet, BN, BaseAssetId, Provider, FUEL_NETWORK_URL } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
Expand All @@ -10,7 +10,7 @@ describe(__filename, () => {

beforeAll(async () => {
provider = await Provider.create(FUEL_NETWORK_URL);
contract = await createAndDeployContractFromProject(SnippetProjectEnum.TRANSFER_TO_ADDRESS);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.TRANSFER_TO_ADDRESS);
});

it('should successfully get a contract balance', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { Contract, Provider } from 'fuels';
import { BaseAssetId } from 'fuels';
import { BaseAssetId, type Contract, type Provider } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;
let provider: Provider;

beforeAll(async () => {
contract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.RETURN_CONTEXT);
provider = contract.provider;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from 'fs';
import { Provider, FUEL_NETWORK_URL, Wallet, ContractFactory } from 'fuels';
import { join } from 'path';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
Expand All @@ -14,7 +14,8 @@ describe(__filename, () => {
const wallet = await getTestWallet();
PRIVATE_KEY = wallet.privateKey;
projectsPath = join(__dirname, '../../../projects');
contractName = SnippetProjectEnum.ECHO_VALUES;

contractName = DocSnippetProjectsEnum.ECHO_VALUES;
});

it('should successfully deploy and execute contract function', async () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/docs-snippets/src/guide/contracts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Contract } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.ECHO_VALUES);
});

it('should successfully call contract and echo values', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Contract, Provider, WalletUnlocked } from 'fuels';
import { BN, ContractFactory } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
Expand All @@ -15,8 +15,8 @@ describe(__filename, () => {
provider = wallet.provider;
const { minGasPrice } = provider.getGasConfig();

const tokenArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.SIMPLE_TOKEN);
const depositorArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.TOKEN_DEPOSITOR);
const tokenArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.SIMPLE_TOKEN);
const depositorArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.TOKEN_DEPOSITOR);

simpleToken = await new ContractFactory(
tokenArtifacts.binHexlified,
Expand Down
4 changes: 2 additions & 2 deletions apps/docs-snippets/src/guide/contracts/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Contract, Provider } from 'fuels';
import { BN } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;
let provider: Provider;

beforeAll(async () => {
contract = await createAndDeployContractFromProject(SnippetProjectEnum.LOG_VALUES);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.LOG_VALUES);
provider = contract.provider;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { AbstractAddress, WalletUnlocked } from 'fuels';
import { ContractFactory, Contract } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
let contract: Contract;
let contractId: AbstractAddress;
let wallet: WalletUnlocked;
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
const { abiContents: abi, binHexlified: bin } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.ECHO_VALUES
);

beforeAll(async () => {
Expand Down
8 changes: 4 additions & 4 deletions apps/docs-snippets/src/guide/contracts/multicalls.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Contract, Provider } from 'fuels';
import { BaseAssetId, BN, ContractFactory } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
Expand All @@ -15,9 +15,9 @@ describe(__filename, () => {
provider = wallet.provider;
const { minGasPrice: gasPrice } = provider.getGasConfig();

const counterArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.COUNTER);
const echoArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.ECHO_VALUES);
const contextArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.RETURN_CONTEXT);
const counterArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.COUNTER);
const echoArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.ECHO_VALUES);
const contextArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.RETURN_CONTEXT);

const factory1 = new ContractFactory(
echoArtifacts.binHexlified,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { safeExec } from '@fuel-ts/errors/test-utils';
import { BaseAssetId, Wallet, BN, Contract } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
it('should successfully simulate contract call with forwarded amount', async () => {
const contract = await createAndDeployContractFromProject(
SnippetProjectEnum.TRANSFER_TO_ADDRESS
DocSnippetProjectsEnum.TRANSFER_TO_ADDRESS
);

const amountToForward = 40;
Expand All @@ -33,7 +33,7 @@ describe(__filename, () => {
});

it('should successfully execute a simulate call', async () => {
const contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
const contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.ECHO_VALUES);

// #region simulate-transactions-2
const { value } = await contract.functions.echo_u8(15).simulate();
Expand All @@ -42,9 +42,9 @@ describe(__filename, () => {
});

it('should throw when simulating with an unfunded wallet', async () => {
const contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
const contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.ECHO_VALUES);
const unfundedWallet = Wallet.generate({ provider: contract.provider });
const { abiContents: abi } = getSnippetProjectArtifacts(SnippetProjectEnum.ECHO_VALUES);
const { abiContents: abi } = getDocsSnippetsForcProject(DocSnippetProjectsEnum.ECHO_VALUES);
const deployedContract = new Contract(contract.id, abi, unfundedWallet);

const { error } = await safeExec(() => deployedContract.functions.echo_u8(15).simulate());
Expand All @@ -53,9 +53,9 @@ describe(__filename, () => {
});

it('should throw when dry running with an unfunded wallet', async () => {
const contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
const contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.ECHO_VALUES);
const unfundedWallet = Wallet.generate({ provider: contract.provider });
const { abiContents: abi } = getSnippetProjectArtifacts(SnippetProjectEnum.ECHO_VALUES);
const { abiContents: abi } = getDocsSnippetsForcProject(DocSnippetProjectsEnum.ECHO_VALUES);
const deployedContract = new Contract(contract.id, abi, unfundedWallet);

const { error } = await safeExec(() => deployedContract.functions.echo_u8(15).dryRun());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Contract, Provider } from 'fuels';
import { BN } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { DocSnippetProjectsEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;
let provider: Provider;
beforeAll(async () => {
contract = await createAndDeployContractFromProject(SnippetProjectEnum.COUNTER);
contract = await createAndDeployContractFromProject(DocSnippetProjectsEnum.COUNTER);
provider = contract.provider;
});

Expand Down
6 changes: 3 additions & 3 deletions apps/docs-snippets/src/guide/predicates/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FUEL_NETWORK_URL, Provider, Predicate } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';

describe(__filename, () => {
const { abiContents: jsonAbi, binHexlified: binary } = getSnippetProjectArtifacts(
SnippetProjectEnum.RETURN_TRUE_PREDICATE
const { abiContents: jsonAbi, binHexlified: binary } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.RETURN_TRUE_PREDICATE
);

it('should successfully instantiate a predicate', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { WalletUnlocked, Predicate, BaseAssetId, BN, getRandomB256 } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
let wallet: WalletUnlocked;
let gasPrice: BN;

const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.WHITELISTED_ADDRESS_PREDICATE
const { abiContents: abi, binHexlified: bin } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.WHITELISTED_ADDRESS_PREDICATE
);

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
BaseAssetId,
} from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
let walletWithFunds: WalletUnlocked;
let gasPrice: BN;
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.SIMPLE_PREDICATE
const { abiContents: abi, binHexlified: bin } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.SIMPLE_PREDICATE
);

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BN, ContractFactory, BaseAssetId, ScriptTransactionRequest } from 'fuels';
import type { CoinQuantityLike, Contract, WalletUnlocked } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { defaultTxParams, getTestWallet } from '../../utils';

describe(__filename, () => {
Expand All @@ -11,12 +11,12 @@ describe(__filename, () => {
const assetIdB = '0x0101010101010101010101010101010101010101010101010101010101010101';
const assetIdA = '0x0202020202020202020202020202020202020202020202020202020202020202';

const { binHexlified: scriptBin, abiContents } = getSnippetProjectArtifacts(
SnippetProjectEnum.SCRIPT_TRANSFER_TO_CONTRACT
const { binHexlified: scriptBin, abiContents } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.SCRIPT_TRANSFER_TO_CONTRACT
);

const { abiContents: contractAbi, binHexlified: contractBin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
const { abiContents: contractAbi, binHexlified: contractBin } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.ECHO_VALUES
);

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { WalletUnlocked } from 'fuels';
import { Script, BN } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../projects';
import { getTestWallet } from '../../utils';

describe(__filename, () => {
let wallet: WalletUnlocked;
let gasPrice: BN;
const { abiContents, binHexlified } = getSnippetProjectArtifacts(SnippetProjectEnum.SUM_SCRIPT);
const { abiContents, binHexlified } = getDocsSnippetsForcProject(
DocSnippetProjectsEnum.SUM_SCRIPT
);

beforeAll(async () => {
wallet = await getTestWallet();
Expand Down
Loading

0 comments on commit e3a798f

Please sign in to comment.