diff --git a/.changeset/mean-sheep-occur.md b/.changeset/mean-sheep-occur.md new file mode 100644 index 00000000000..014a178950c --- /dev/null +++ b/.changeset/mean-sheep-occur.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +chore: avoid re-estimate `gasPrice` at `estimateTxDependencies` diff --git a/.changeset/moody-terms-shake.md b/.changeset/moody-terms-shake.md new file mode 100644 index 00000000000..0880568bf0a --- /dev/null +++ b/.changeset/moody-terms-shake.md @@ -0,0 +1,4 @@ +--- +--- + +chore: minimizing logs in test output diff --git a/.changeset/old-maps-fold.md b/.changeset/old-maps-fold.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/old-maps-fold.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/apps/docs/README.md b/apps/docs/README.md index f7cbd7f83b6..fa97e16d3c4 100644 --- a/apps/docs/README.md +++ b/apps/docs/README.md @@ -8,6 +8,7 @@ - [Table of contents](#table-of-contents) - [Building](#building) - [Testing](#testing) + - [Referencing snippets](#referencing-snippets) ## Building @@ -42,3 +43,17 @@ If no environment is specified, it will run in the browser and node environments ```sh pnpm test ``` + +## Referencing snippets + +To reference a snippet outside of the current directory, you need to use the following syntax (`<<< @/`): + +```md +`<<< @/../../path/to/snippet.ts#snippet-name{language:line-numbers} +``` + +To reference a snippet in the current directory, you can use the following syntax (`<<< @./`): + +```md +`<<< @./snippets/transaction-request/fetch-resources.ts#transaction-request-5{ts:line-numbers} +``` diff --git a/apps/docs/src/guide/transactions/transaction-request.md b/apps/docs/src/guide/transactions/transaction-request.md index 95ceb4847bb..6d7b7337a82 100644 --- a/apps/docs/src/guide/transactions/transaction-request.md +++ b/apps/docs/src/guide/transactions/transaction-request.md @@ -60,7 +60,7 @@ If needed, you can manually include specific coins or messages in the transactio Imagine that you have a Sway script that manually calls a contract: -<<< @../../../../sway/script-call-contract/src/main.sw#transaction-request-7{rs:line-numbers} +<<< @/../../docs/sway/script-call-contract/src/main.sw#transaction-request-7{rs:line-numbers} In those cases, you will need to add both an `InputContract` and `OutputContract` to the transaction request: diff --git a/packages/abi-typegen/src/cli.test.ts b/packages/abi-typegen/src/cli.test.ts index 4c4a1d55716..c960b9a48d2 100644 --- a/packages/abi-typegen/src/cli.test.ts +++ b/packages/abi-typegen/src/cli.test.ts @@ -164,7 +164,7 @@ describe('cli.ts', () => { test('should handle errors when running cli action', () => { const runTypegenError = new Error('Pretty message'); - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); const { exit } = mockDeps({ runTypegenError }); const inputs = ['*-no-abis-here.json']; diff --git a/packages/abi-typegen/src/runTypegen.test.ts b/packages/abi-typegen/src/runTypegen.test.ts index 2ea943f2c98..3fe0e2ae1bb 100644 --- a/packages/abi-typegen/src/runTypegen.test.ts +++ b/packages/abi-typegen/src/runTypegen.test.ts @@ -153,7 +153,7 @@ describe('runTypegen.js', () => { }); test('should log messages to stdout', async () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); // setup temp sway project const project = getTypegenForcProject(AbiTypegenProjectsEnum.SCRIPT); @@ -272,7 +272,7 @@ describe('runTypegen.js', () => { cpSync(fromBin, toBin); // mocking - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); // executes program const fn = () => diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 112aaaaa318..60484577999 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -323,6 +323,7 @@ export class Account extends AbstractAccount { const { maxFee } = await this.provider.estimateTxGasAndFee({ transactionRequest: requestToReestimate, + gasPrice, }); request.maxFee = maxFee; diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 226c6642e00..7e62483ddc1 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -250,7 +250,7 @@ describe('Provider', () => { }); // Spy on console.warn - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); // Verify that only one transaction was returned (the known type) const transaction = await mockProvider.getTransaction('0x1234567890abcdef'); @@ -298,7 +298,7 @@ describe('Provider', () => { }); // Spy on console.warn - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); // Verify that only one transaction was returned (the known type) const { transactions } = await mockProvider.getTransactions(); @@ -448,7 +448,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const { cleanup, url } = await launchNode({ port: '0' }); + const { cleanup, url } = await launchNode({ port: '0', loggingEnabled: false }); const spyFetchChainAndNodeInfo = vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo'); @@ -1181,7 +1181,7 @@ describe('Provider', () => { const spy = vi.spyOn(fuelTsVersionsMod, 'checkFuelCoreVersionCompatibility'); spy.mockImplementationOnce(() => mock); - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); using launched = await setupTestProviderAndWallets(); const { provider } = launched; @@ -1216,7 +1216,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const spy = vi.spyOn(fuelTsVersionsMod, 'checkFuelCoreVersionCompatibility'); spy.mockImplementationOnce(() => mock); - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); using launched = await setupTestProviderAndWallets(); const { provider } = launched; diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index b07bcfd1d67..5f9ffe88f42 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1011,6 +1011,7 @@ Supported fuel-core version: ${supportedVersion}.` } = await this.operations.dryRun({ encodedTransactions: [hexlify(transactionRequest.toTransactionBytes())], utxoValidation: false, + gasPrice: '0', }); receipts = rawReceipts.map(processGqlReceipt); @@ -1032,6 +1033,7 @@ Supported fuel-core version: ${supportedVersion}.` const { maxFee } = await this.estimateTxGasAndFee({ transactionRequest, + gasPrice: bn(0), }); // eslint-disable-next-line no-param-reassign @@ -1204,7 +1206,7 @@ Supported fuel-core version: ${supportedVersion}.` const { gasPriceFactor, maxGasPerTx } = this.getGasConfig(); const minGas = transactionRequest.calculateMinGas(chainInfo); - if (!gasPrice) { + if (!isDefined(gasPrice)) { gasPrice = await this.estimateGasPrice(10); } diff --git a/packages/account/src/test-utils/launchNode.test.ts b/packages/account/src/test-utils/launchNode.test.ts index 410ca85ac32..ab52fd47603 100644 --- a/packages/account/src/test-utils/launchNode.test.ts +++ b/packages/account/src/test-utils/launchNode.test.ts @@ -117,7 +117,7 @@ describe('launchNode', () => { }); test('should throw on error and log error message', { timeout: 15000 }, async () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); const invalidCoin = { asset_id: 'whatever', @@ -132,7 +132,7 @@ describe('launchNode', () => { const error = await expectToThrowFuelError( async () => launchNode({ - loggingEnabled: false, + loggingEnabled: true, snapshotConfig: { ...defaultSnapshotConfigs, stateConfig: { @@ -238,7 +238,7 @@ describe('launchNode', () => { test('calling cleanup on externally killed node does not throw', async () => { const mkdirSyncSpy = vi.spyOn(fsMod, 'mkdirSync'); - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); const { pid, cleanup } = await launchNode({ loggingEnabled: false }); expect(mkdirSyncSpy).toHaveBeenCalledTimes(1); diff --git a/packages/account/src/test-utils/launchNode.ts b/packages/account/src/test-utils/launchNode.ts index a4371ab023c..cfcd46f890e 100644 --- a/packages/account/src/test-utils/launchNode.ts +++ b/packages/account/src/test-utils/launchNode.ts @@ -278,6 +278,9 @@ export const launchNode = async ({ } }); + // Increase the max listeners to avoid a warning + process.setMaxListeners(100); + // Process exit. process.on('exit', cleanup); diff --git a/packages/create-fuels/src/utils/logger.test.ts b/packages/create-fuels/src/utils/logger.test.ts index 3a3344abbd1..fc13e87d273 100644 --- a/packages/create-fuels/src/utils/logger.test.ts +++ b/packages/create-fuels/src/utils/logger.test.ts @@ -28,7 +28,7 @@ describe('logger', () => { }); test('should log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: false }); log('message'); expect(logSpy).toHaveBeenCalledTimes(1); @@ -36,7 +36,7 @@ describe('logger', () => { }); test('should not log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: false, isDebugEnabled: false }); log('any message'); @@ -44,7 +44,7 @@ describe('logger', () => { }); test('should debug', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: true }); debug('message'); @@ -53,7 +53,7 @@ describe('logger', () => { }); test('should not log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: false, isDebugEnabled: false }); loggerMod.debug('any debug message'); @@ -61,14 +61,14 @@ describe('logger', () => { }); test('should warn', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); warn('message1', 'message2'); expect(logSpy).toHaveBeenCalledTimes(1); expect(logSpy).toHaveBeenCalledWith(chalk.yellow('message1 message2')); }); test('should error', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); error('message1', 'message2'); expect(logSpy).toHaveBeenCalledTimes(1); expect(logSpy).toHaveBeenCalledWith(chalk.red('message1 message2')); diff --git a/packages/fuel-gauge/src/fee.test.ts b/packages/fuel-gauge/src/fee.test.ts index 17b87f5d055..f5c5a53440e 100644 --- a/packages/fuel-gauge/src/fee.test.ts +++ b/packages/fuel-gauge/src/fee.test.ts @@ -3,6 +3,7 @@ import { InputMessageCoder, ScriptTransactionRequest, Wallet, + getMintedAssetId, getRandomB256, hexlify, isCoin, @@ -40,6 +41,8 @@ describe('Fee', () => { } }; + const SUB_ID = '0x4a778acfad1abc155a009dc976d2cf0db6197d3d360194d74b1fb92b96986b00'; + it('should ensure fee is properly calculated when minting and burning coins', async () => { using launched = await launchTestNode({ contractsConfigs: [ @@ -431,5 +434,81 @@ describe('Fee', () => { expect(cost.dryRunStatus?.type).toBe('DryRunSuccessStatus'); }); + + it('should not run estimateGasPrice in between estimateTxDependencies dry run attempts', async () => { + using launched = await launchTestNode({ + contractsConfigs: [ + { + factory: MultiTokenContractFactory, + }, + ], + }); + + const { + contracts: [contract], + wallets: [wallet], + provider, + } = launched; + + const assetId = getMintedAssetId(contract.id.toB256(), SUB_ID); + + // Minting coins first + const mintCall = await contract.functions.mint_coins(SUB_ID, 10_000).call(); + await mintCall.waitForResult(); + + const estimateGasPrice = vi.spyOn(provider, 'estimateGasPrice'); + const dryRun = vi.spyOn(provider.operations, 'dryRun'); + + /** + * Sway transfer without adding `OutputVariable` which will result in + * 2 dry runs at the `Provider.estimateTxDependencies` method: + * - 1st dry run will fail due to missing `OutputVariable` + * - 2nd dry run will succeed + */ + const transferCall = await contract.functions + .transfer_to_address({ bits: wallet.address.toB256() }, { bits: assetId }, 10_000) + .call(); + + await transferCall.waitForResult(); + + expect(estimateGasPrice).toHaveBeenCalledOnce(); + expect(dryRun).toHaveBeenCalledTimes(2); + }); + + it('should ensure estimateGasPrice runs only once when funding a transaction.', async () => { + const amountPerCoin = 100; + + using launched = await launchTestNode({ + walletsConfig: { + amountPerCoin, // Funding with multiple UTXOs so the fee will change after funding the TX. + coinsPerAsset: 250, + }, + contractsConfigs: [ + { + factory: MultiTokenContractFactory, + }, + ], + }); + + const { + wallets: [wallet], + provider, + } = launched; + + const fund = vi.spyOn(wallet, 'fund'); + const estimateGasPrice = vi.spyOn(provider, 'estimateGasPrice'); + + const tx = await wallet.transfer( + wallet.address, + amountPerCoin * 20, + provider.getBaseAssetId() + ); + const { isStatusSuccess } = await tx.waitForResult(); + + expect(fund).toHaveBeenCalledOnce(); + expect(estimateGasPrice).toHaveBeenCalledOnce(); + + expect(isStatusSuccess).toBeTruthy(); + }); }); }); diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts index f10c9968f35..d91ef982b67 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts @@ -56,7 +56,7 @@ describe('buildSwayPrograms', () => { test('logs to console when logging is enabled', async () => { const { spawn } = mockAll(); - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: false }); @@ -70,7 +70,7 @@ describe('buildSwayPrograms', () => { test('logs debug to console when debug is enabled', async () => { const { spawn } = mockAll(); - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: true }); await buildSwayProgram(fuelsConfig, '/any/workspace/path'); diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index d950c510c91..f5290233ed9 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -26,7 +26,7 @@ describe('autoStartFuelCore', () => { }); }); - function mockLaunchNode() { + function mockAll() { const launchNode = vi.spyOn(testUtilsMod, 'launchNode').mockReturnValue( Promise.resolve({ cleanup: () => {}, @@ -37,11 +37,12 @@ describe('autoStartFuelCore', () => { pid: 1234, }) ); - return { launchNode }; + const log = vi.spyOn(console, 'log').mockImplementation(() => {}); + return { launchNode, log }; } test('should auto start `fuel-core`', async () => { - const { launchNode } = mockLaunchNode(); + const { launchNode, log } = mockAll(); const config = structuredClone(fuelsConfig); config.autoStartFuelCore = true; @@ -49,10 +50,11 @@ describe('autoStartFuelCore', () => { await autoStartFuelCore(config); expect(launchNode).toHaveBeenCalledTimes(1); + expect(log).toHaveBeenCalledTimes(1); }); test('should not start `fuel-core`', async () => { - const { launchNode } = mockLaunchNode(); + const { launchNode, log } = mockAll(); const config = structuredClone(fuelsConfig); config.autoStartFuelCore = false; @@ -60,10 +62,11 @@ describe('autoStartFuelCore', () => { await autoStartFuelCore(config); expect(launchNode).toHaveBeenCalledTimes(0); + expect(log).toHaveBeenCalledTimes(0); }); test('should start `fuel-core` node using custom binary', async () => { - const { launchNode } = mockLaunchNode(); + const { launchNode, log } = mockAll(); const copyConfig: FuelsConfig = structuredClone(fuelsConfig); copyConfig.fuelCorePath = 'fuels-core'; @@ -86,12 +89,13 @@ describe('autoStartFuelCore', () => { fuelCorePath: 'fuels-core', }) ); + expect(log).toHaveBeenCalledTimes(1); core.killChildProcess(); }); test('should start `fuel-core` node using system binary', async () => { - const { launchNode } = mockLaunchNode(); + const { launchNode, log } = mockAll(); const config = structuredClone(fuelsConfig); const core = (await autoStartFuelCore(config)) as FuelCoreNode; @@ -103,6 +107,7 @@ describe('autoStartFuelCore', () => { expect(core.port).toBeGreaterThanOrEqual(4000); expect(core.providerUrl).toMatch(/http:\/\/127\.0\.0\.1:([0-9]+)\/v1\/graphql/); expect(core.killChildProcess).toBeTruthy(); + expect(log).toHaveBeenCalledTimes(1); core.killChildProcess(); }); diff --git a/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts b/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts index 113f70f096d..d58f57fb47d 100644 --- a/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts +++ b/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts @@ -26,8 +26,8 @@ describe('checkForAndDisplayUpdates', () => { FUEL_CORE: '1.0.0', }); - const log = vi.spyOn(loggerMod, 'log'); - const warn = vi.spyOn(loggerMod, 'warn'); + const log = vi.spyOn(loggerMod, 'log').mockImplementation(() => {}); + const warn = vi.spyOn(loggerMod, 'warn').mockImplementation(() => {}); return { log, warn }; }; @@ -67,7 +67,7 @@ describe('checkForAndDisplayUpdates', () => { new Error('Failed to fetch') ); - const log = vi.spyOn(loggerMod, 'log'); + const log = vi.spyOn(loggerMod, 'log').mockImplementation(() => {}); await checkForAndDisplayUpdatesMod.checkForAndDisplayUpdates(); diff --git a/packages/fuels/src/cli/utils/logger.test.ts b/packages/fuels/src/cli/utils/logger.test.ts index 7c8cd22069c..82f8d48fd97 100644 --- a/packages/fuels/src/cli/utils/logger.test.ts +++ b/packages/fuels/src/cli/utils/logger.test.ts @@ -26,7 +26,7 @@ describe('logger', () => { }); test('should log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: false }); log('message'); expect(logSpy).toHaveBeenCalledTimes(1); @@ -34,7 +34,7 @@ describe('logger', () => { }); test('should not log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: false, isDebugEnabled: false }); log('any message'); @@ -42,7 +42,7 @@ describe('logger', () => { }); test('should debug', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: true }); debug('message'); @@ -51,7 +51,7 @@ describe('logger', () => { }); test('should not log', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: false, isDebugEnabled: false }); loggerMod.debug('any debug message'); @@ -59,14 +59,14 @@ describe('logger', () => { }); test('should warn', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); warn('message1', 'message2'); expect(logSpy).toHaveBeenCalledTimes(1); expect(logSpy).toHaveBeenCalledWith(chalk.yellow('message1 message2')); }); test('should error', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); error('message1', 'message2'); expect(logSpy).toHaveBeenCalledTimes(1); expect(logSpy).toHaveBeenCalledWith(chalk.red('message1 message2')); diff --git a/packages/fuels/test/features/build.test.ts b/packages/fuels/test/features/build.test.ts index 4c2956c1c9f..f03a6388419 100644 --- a/packages/fuels/test/features/build.test.ts +++ b/packages/fuels/test/features/build.test.ts @@ -1,4 +1,4 @@ -import { existsSync, readFileSync, writeFileSync } from 'fs'; +import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; import { join } from 'path'; import * as deployMod from '../../src/cli/commands/deploy/index'; @@ -24,6 +24,7 @@ describe('build', { timeout: 180000 }, () => { afterEach(() => { resetConfigAndMocks(paths.fuelsConfigPath); + rmSync(paths.outputDir, { recursive: true, force: true }); }); afterAll(() => { @@ -76,12 +77,12 @@ describe('build', { timeout: 180000 }, () => { expect(killChildProcess).toHaveBeenCalledTimes(0); }); - it('should run `build` command with contracts-only', async () => { + it('should run `build` command with contracts-only [single contract]', async () => { const { autoStartFuelCore, killChildProcess, deploy } = mockAll(); await runInit({ root: paths.root, - contracts: paths.contractsDir, + contracts: paths.contractsFooDir, output: paths.outputDir, forcPath: paths.forcPath, fuelCorePath: paths.fuelCorePath, @@ -96,7 +97,42 @@ describe('build', { timeout: 180000 }, () => { 'index.ts', ].map((f) => join(paths.outputDir, f)); - files.forEach((file) => expect(existsSync(file)).toBeTruthy()); + files.forEach((file) => expect(existsSync(file), `${file} does not exist`).toBeTruthy()); + expect(readdirSync(paths.outputContractsDir)).toHaveLength(3); + + expect(autoStartFuelCore).toHaveBeenCalledTimes(0); + expect(deploy).toHaveBeenCalledTimes(0); + expect(killChildProcess).toHaveBeenCalledTimes(0); + }); + + it('should run `build` command with contracts-only [with glob]', async () => { + const { autoStartFuelCore, killChildProcess, deploy } = mockAll(); + + await runInit({ + root: paths.root, + contracts: `${paths.contractsDir}/*`, + output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, + }); + + await runBuild({ root: paths.root }); + + const files = [ + 'contracts/UpgradableChunked.ts', + 'contracts/UpgradableChunkedFactory.ts', + 'contracts/Upgradable.ts', + 'contracts/UpgradableFactory.ts', + 'contracts/BarFoo.ts', + 'contracts/BarFooFactory.ts', + 'contracts/FooBar.ts', + 'contracts/FooBarFactory.ts', + 'contracts/index.ts', + 'index.ts', + ].map((f) => join(paths.outputDir, f)); + + files.forEach((file) => expect(existsSync(file), `${file} does not exist`).toBeTruthy()); + expect(readdirSync(paths.outputContractsDir)).toHaveLength(9); expect(autoStartFuelCore).toHaveBeenCalledTimes(0); expect(deploy).toHaveBeenCalledTimes(0); diff --git a/packages/fuels/test/features/init.test.ts b/packages/fuels/test/features/init.test.ts index 93b9fd72b7e..4c7be45929f 100644 --- a/packages/fuels/test/features/init.test.ts +++ b/packages/fuels/test/features/init.test.ts @@ -87,7 +87,7 @@ describe('init', () => { }); it('should error if no inputs/workspace is supplied', async () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); const exit = vi.spyOn(process, 'exit').mockResolvedValue({} as never); await runCommand(Commands.init, ['--path', paths.root, '-o', paths.outputDir]); diff --git a/packages/fuels/test/utils/runCommands.ts b/packages/fuels/test/utils/runCommands.ts index 88fd9edf656..3558d04eb97 100644 --- a/packages/fuels/test/utils/runCommands.ts +++ b/packages/fuels/test/utils/runCommands.ts @@ -40,14 +40,17 @@ export function bootstrapProject(testFilepath: string) { cpSync(sampleWorkspaceDir, workspaceDir, { recursive: true }); const contractsDir = join(workspaceDir, 'contracts'); + const contractsBarDir = join(contractsDir, 'bar'); const contractsFooDir = join(contractsDir, 'foo'); - const scriptsDir = join(workspaceDir, 'scripts'); - const predicateDir = join(workspaceDir, 'predicate'); const fooContractMainPath = join(contractsDir, 'foo', 'src', 'main.sw'); const upgradableContractPath = join(contractsDir, 'upgradable'); const upgradableChunkedContractPath = join(contractsDir, 'upgradable-chunked'); + const scriptsDir = join(workspaceDir, 'scripts'); + const predicateDir = join(workspaceDir, 'predicate'); + const outputDir = join(root, 'output'); + const outputContractsDir = join(outputDir, 'contracts'); const contractsJsonPath = join(outputDir, 'contract-ids.json'); const fooContractFactoryPath = join(outputDir, 'contracts', 'factories', 'FooBarAbi.ts'); @@ -58,7 +61,11 @@ export function bootstrapProject(testFilepath: string) { root, workspaceDir, contractsDir, + outputContractsDir, + contractsBarDir, contractsFooDir, + upgradableContractPath, + upgradableChunkedContractPath, scriptsDir, predicateDir, fooContractMainPath, @@ -68,8 +75,6 @@ export function bootstrapProject(testFilepath: string) { fooContractFactoryPath, forcPath, fuelCorePath, - upgradableContractPath, - upgradableChunkedContractPath, }; } diff --git a/packages/utils/src/utils/toUtf8String.test.ts b/packages/utils/src/utils/toUtf8String.test.ts index c61f36079e7..263c434bfdd 100644 --- a/packages/utils/src/utils/toUtf8String.test.ts +++ b/packages/utils/src/utils/toUtf8String.test.ts @@ -5,6 +5,10 @@ import { toUtf8String } from './toUtf8String'; * @group browser */ describe('toUtf8String', () => { + beforeAll(() => { + vi.spyOn(console, 'log').mockImplementation(() => {}); + }); + it('should convert valid UTF-8 bytes to a string', () => { const bytes = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); expect(toUtf8String(bytes)).toEqual('Hello World'); diff --git a/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts b/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts index 5753e268b32..3a71c11b4dd 100644 --- a/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts +++ b/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts @@ -69,7 +69,7 @@ describe('getDifferenceToUserFuelCoreVersion', () => { }); it("warns when the version doesn't conform to strict major.minor.patch versioning (e.g. nightly build)", () => { - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); vi.spyOn(getBuiltinVersionsMod, 'getBuiltinVersions').mockImplementation(() => ({ FUELS: '1', // not under test @@ -92,7 +92,7 @@ This unreleased fuel-core build may include features and updates not yet support FUEL_CORE: '0.1.2', })); - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); checkFuelCoreVersionCompatibility('0.1.2');