diff --git a/.changeset/khaki-trees-wink.md b/.changeset/khaki-trees-wink.md new file mode 100644 index 00000000000..a423891100a --- /dev/null +++ b/.changeset/khaki-trees-wink.md @@ -0,0 +1,5 @@ +--- +"fuels": minor +--- + +feat!: `onDeploy` fuels config supports all Sway program types diff --git a/apps/demo-fuels/fuels.config.full.ts b/apps/demo-fuels/fuels.config.full.ts index 28b01d8831f..92c7cf944ed 100644 --- a/apps/demo-fuels/fuels.config.full.ts +++ b/apps/demo-fuels/fuels.config.full.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import { createConfig } from 'fuels'; -import type { ContractDeployOptions, DeployedContract, FuelsConfig } from 'fuels'; +import type { ContractDeployOptions, DeployedData, FuelsConfig } from 'fuels'; const MY_FIRST_DEPLOYED_CONTRACT_NAME = ''; @@ -91,9 +91,9 @@ export default createConfig({ // #endregion onBuild // #region onDeploy - // #import { DeployedContract, FuelsConfig }; + // #import { DeployedData, FuelsConfig }; - onDeploy: (config: FuelsConfig, data: DeployedContract[]) => { + onDeploy: (config: FuelsConfig, data: DeployedData) => { console.log('fuels:onDeploy', { config, data }); }, // #endregion onDeploy diff --git a/packages/fuels/src/cli/commands/deploy/index.test.ts b/packages/fuels/src/cli/commands/deploy/index.test.ts index c2f05420328..c36c4f39a67 100644 --- a/packages/fuels/src/cli/commands/deploy/index.test.ts +++ b/packages/fuels/src/cli/commands/deploy/index.test.ts @@ -2,7 +2,7 @@ import { Wallet } from '@fuel-ts/account'; import { fuelsConfig } from '../../../../test/fixtures/fuels.config'; import { launchTestNode } from '../../../test-utils'; -import type { DeployedContract } from '../../types'; +import type { DeployedData } from '../../types'; import { deploy } from '.'; import * as createWalletMod from './createWallet'; @@ -32,11 +32,16 @@ describe('deploy', () => { // TODO: Fix this test test.skip('should call onDeploy callback', async () => { const { onDeploy } = await mockAll(); - const expectedContracts: DeployedContract[] = []; - const config = { ...fuelsConfig, contracts: [], onDeploy }; + const expectedData: DeployedData = { + contracts: [], + scripts: [], + predicates: [], + }; + + const config = { ...fuelsConfig, contracts: [], scripts: [], predicates: [], onDeploy }; await deploy(config); - expect(onDeploy).toHaveBeenCalledWith(config, expectedContracts); + expect(onDeploy).toHaveBeenCalledWith(config, expectedData); }); }); diff --git a/packages/fuels/src/cli/commands/deploy/index.ts b/packages/fuels/src/cli/commands/deploy/index.ts index 536c5992b13..28b14181d41 100644 --- a/packages/fuels/src/cli/commands/deploy/index.ts +++ b/packages/fuels/src/cli/commands/deploy/index.ts @@ -12,10 +12,8 @@ export async function deploy(config: FuelsConfig) { /** * Deploy contract and save their IDs to JSON file. */ - const contractIds = await deployContracts(config); - await saveContractIds(contractIds, config.output); - - config.onDeploy?.(config, contractIds); + const contracts = await deployContracts(config); + await saveContractIds(contracts, config.output); /** * Deploy scripts and save deployed files to disk. @@ -29,11 +27,21 @@ export async function deploy(config: FuelsConfig) { const predicates = await deployPredicates(config); savePredicateFiles(predicates, config); + config.onDeploy?.(config, { + contracts, + scripts, + predicates, + }); + /** * After deploying scripts/predicates, we need to * re-generate factory classe with the loader coee */ await generateTypes(config); - return contractIds; + return { + contracts, + scripts, + predicates, + }; } diff --git a/packages/fuels/src/cli/commands/dev/index.test.ts b/packages/fuels/src/cli/commands/dev/index.test.ts index 2dccd88575b..f950daff5b4 100644 --- a/packages/fuels/src/cli/commands/dev/index.test.ts +++ b/packages/fuels/src/cli/commands/dev/index.test.ts @@ -42,7 +42,11 @@ describe('dev', () => { .mockReturnValue(Promise.resolve(fuelsConfig)); const build = vi.spyOn(buildMod, 'build').mockResolvedValue(); - const deploy = vi.spyOn(deployMod, 'deploy').mockResolvedValue([]); + const deploy = vi.spyOn(deployMod, 'deploy').mockResolvedValue({ + contracts: [], + scripts: [], + predicates: [], + }); return { autoStartFuelCore, diff --git a/packages/fuels/src/cli/commands/withConfig.test.ts b/packages/fuels/src/cli/commands/withConfig.test.ts index 7bef6dcafc7..cff61a5c9bb 100644 --- a/packages/fuels/src/cli/commands/withConfig.test.ts +++ b/packages/fuels/src/cli/commands/withConfig.test.ts @@ -45,7 +45,11 @@ describe('withConfig', () => { if (params?.shouldErrorOnDeploy) { throw new Error('Something happened'); } - return Promise.resolve([]); + return Promise.resolve({ + contracts: [], + scripts: [], + predicates: [], + }); }); const { error } = mockLogger(); diff --git a/packages/fuels/src/cli/types.ts b/packages/fuels/src/cli/types.ts index 2c5ed7c0ea8..f44c32cd93e 100644 --- a/packages/fuels/src/cli/types.ts +++ b/packages/fuels/src/cli/types.ts @@ -17,7 +17,7 @@ export type CommandEvent = } | { type: Commands.deploy; - data: DeployedContract[]; + data: DeployedData; } | { type: Commands.dev; @@ -51,6 +51,12 @@ export type DeployedPredicate = DeployedScript & { predicateRoot: string; }; +export type DeployedData = { + contracts?: DeployedContract[]; + scripts?: DeployedScript[]; + predicates?: DeployedPredicate[]; +}; + export type ContractDeployOptions = { contracts: DeployedContract[]; contractName: string; diff --git a/packages/fuels/test/features/build.test.ts b/packages/fuels/test/features/build.test.ts index 07ba32c8f40..4c2956c1c9f 100644 --- a/packages/fuels/test/features/build.test.ts +++ b/packages/fuels/test/features/build.test.ts @@ -32,7 +32,11 @@ describe('build', { timeout: 180000 }, () => { function mockAll() { const { autoStartFuelCore, killChildProcess } = mockStartFuelCore(); - const deploy = vi.spyOn(deployMod, 'deploy').mockResolvedValue([]); + const deploy = vi.spyOn(deployMod, 'deploy').mockResolvedValue({ + contracts: [], + scripts: [], + predicates: [], + }); return { autoStartFuelCore, killChildProcess, deploy }; } diff --git a/packages/fuels/test/features/dev.test.ts b/packages/fuels/test/features/dev.test.ts index b8aa63231f6..a03d97dfba1 100644 --- a/packages/fuels/test/features/dev.test.ts +++ b/packages/fuels/test/features/dev.test.ts @@ -40,7 +40,13 @@ describe('dev', () => { const { autoStartFuelCore, killChildProcess } = mockStartFuelCore(); const build = vi.spyOn(buildMod, 'build').mockReturnValue(Promise.resolve()); - const deploy = vi.spyOn(deployMod, 'deploy').mockReturnValue(Promise.resolve([])); + const deploy = vi.spyOn(deployMod, 'deploy').mockReturnValue( + Promise.resolve({ + contracts: [], + scripts: [], + predicates: [], + }) + ); // eslint-disable-next-line @typescript-eslint/no-explicit-any const on: any = vi.fn(() => ({ on }));