diff --git a/.changeset/six-moles-wonder.md b/.changeset/six-moles-wonder.md new file mode 100644 index 00000000000..353c095e211 --- /dev/null +++ b/.changeset/six-moles-wonder.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/abi-typegen": patch +"@fuel-ts/recipes": patch +--- + +chore: prevent naming collisions on typegen diff --git a/packages/abi-typegen/src/templates/contract/factory.hbs b/packages/abi-typegen/src/templates/contract/factory.hbs index d069631eebe..e1ea752fd61 100644 --- a/packages/abi-typegen/src/templates/contract/factory.hbs +++ b/packages/abi-typegen/src/templates/contract/factory.hbs @@ -1,13 +1,13 @@ {{header}} -import { ContractFactory, decompressBytecode } from "fuels"; +import { ContractFactory as __ContractFactory, decompressBytecode } from "fuels"; import type { Provider, Account, DeployContractOptions } from "fuels"; import { {{capitalizedName}} } from "./{{capitalizedName}}"; const bytecode = decompressBytecode("{{compressedBytecode}}"); -export class {{capitalizedName}}Factory extends ContractFactory<{{capitalizedName}}> { +export class {{capitalizedName}}Factory extends __ContractFactory<{{capitalizedName}}> { static readonly bytecode = bytecode; diff --git a/packages/abi-typegen/src/templates/contract/main.hbs b/packages/abi-typegen/src/templates/contract/main.hbs index eef7efd30a2..c446898ddeb 100644 --- a/packages/abi-typegen/src/templates/contract/main.hbs +++ b/packages/abi-typegen/src/templates/contract/main.hbs @@ -1,6 +1,6 @@ {{header}} -import { Contract, Interface } from "fuels"; +import { Contract as __Contract, Interface } from "fuels"; {{#if imports}} import type { Provider, @@ -69,7 +69,7 @@ export class {{capitalizedName}}Interface extends Interface { }; } -export class {{capitalizedName}} extends Contract { +export class {{capitalizedName}} extends __Contract { static readonly abi = abi; static readonly storageSlots = storageSlots; diff --git a/packages/abi-typegen/src/templates/predicate/main.hbs b/packages/abi-typegen/src/templates/predicate/main.hbs index 03cbaf76dd6..4ca75addf81 100644 --- a/packages/abi-typegen/src/templates/predicate/main.hbs +++ b/packages/abi-typegen/src/templates/predicate/main.hbs @@ -61,7 +61,7 @@ const abi = {{abiJsonString}}; const bytecode = decompressBytecode('{{compressedBytecode}}'); -export class {{capitalizedName}} extends Predicate< +export class {{capitalizedName}} extends __Predicate< {{capitalizedName}}Inputs, {{capitalizedName}}Configurables > { diff --git a/packages/abi-typegen/src/templates/predicate/main.ts b/packages/abi-typegen/src/templates/predicate/main.ts index a2c928ecf94..135aeef2bcc 100644 --- a/packages/abi-typegen/src/templates/predicate/main.ts +++ b/packages/abi-typegen/src/templates/predicate/main.ts @@ -34,7 +34,13 @@ export function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions const { structs } = formatStructs({ types }); const { imports } = formatImports({ types, - baseMembers: ['Predicate', 'Provider', 'InputValue', 'PredicateParams', 'decompressBytecode'], + baseMembers: [ + 'Predicate as __Predicate', + 'Provider', + 'InputValue', + 'PredicateParams', + 'decompressBytecode', + ], }); const { prefixedInputs: inputs, output } = func.attributes; diff --git a/packages/abi-typegen/src/templates/script/main.hbs b/packages/abi-typegen/src/templates/script/main.hbs index 225d540e9ca..600c1de516c 100644 --- a/packages/abi-typegen/src/templates/script/main.hbs +++ b/packages/abi-typegen/src/templates/script/main.hbs @@ -55,7 +55,7 @@ const abi = {{abiJsonString}}; const bytecode = decompressBytecode('{{compressedBytecode}}'); -export class {{capitalizedName}} extends Script<{{capitalizedName}}Inputs, {{capitalizedName}}Output> { +export class {{capitalizedName}} extends __Script<{{capitalizedName}}Inputs, {{capitalizedName}}Output> { static readonly abi = abi; static readonly bytecode = bytecode; diff --git a/packages/abi-typegen/src/templates/script/main.ts b/packages/abi-typegen/src/templates/script/main.ts index 36b76d2ce74..2943b3218e9 100644 --- a/packages/abi-typegen/src/templates/script/main.ts +++ b/packages/abi-typegen/src/templates/script/main.ts @@ -34,7 +34,7 @@ export function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions const { structs } = formatStructs({ types }); const { imports } = formatImports({ types, - baseMembers: ['Script', 'Account', 'decompressBytecode'], + baseMembers: ['Script as __Script', 'Account', 'decompressBytecode'], }); const { prefixedInputs: inputs, output } = func.attributes; diff --git a/packages/abi-typegen/test/fixtures/templates/contract-with-configurable/main.hbs b/packages/abi-typegen/test/fixtures/templates/contract-with-configurable/main.hbs index 0d9050c8f85..d6840c81bd4 100644 --- a/packages/abi-typegen/test/fixtures/templates/contract-with-configurable/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/contract-with-configurable/main.hbs @@ -10,7 +10,7 @@ Fuel-Core version: 33.33.33 */ -import { Contract, Interface } from "fuels"; +import { Contract as __Contract, Interface } from "fuels"; import type { Provider, Account, @@ -187,7 +187,7 @@ export class MyContractInterface extends Interface { }; } -export class MyContract extends Contract { +export class MyContract extends __Contract { static readonly abi = abi; static readonly storageSlots = storageSlots; diff --git a/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs b/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs index 0496f767c2d..8c40a8fda71 100644 --- a/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs @@ -10,14 +10,14 @@ Fuel-Core version: 33.33.33 */ -import { ContractFactory, decompressBytecode } from "fuels"; +import { ContractFactory as __ContractFactory, decompressBytecode } from "fuels"; import type { Provider, Account, DeployContractOptions } from "fuels"; import { MyContract } from "./MyContract"; const bytecode = decompressBytecode("0x-bytecode-here"); -export class MyContractFactory extends ContractFactory { +export class MyContractFactory extends __ContractFactory { static readonly bytecode = bytecode; diff --git a/packages/abi-typegen/test/fixtures/templates/contract/main.hbs b/packages/abi-typegen/test/fixtures/templates/contract/main.hbs index a0350d966f7..40f5f5aa793 100644 --- a/packages/abi-typegen/test/fixtures/templates/contract/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/contract/main.hbs @@ -10,7 +10,7 @@ Fuel-Core version: 33.33.33 */ -import { Contract, Interface } from "fuels"; +import { Contract as __Contract, Interface } from "fuels"; import type { Provider, Account, @@ -1199,7 +1199,7 @@ export class MyContractInterface extends Interface { }; } -export class MyContract extends Contract { +export class MyContract extends __Contract { static readonly abi = abi; static readonly storageSlots = storageSlots; diff --git a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/main.hbs b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/main.hbs index 3479186849f..6760a9439c9 100644 --- a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/main.hbs @@ -14,7 +14,7 @@ import { BigNumberish, decompressBytecode, InputValue, - Predicate, + Predicate as __Predicate, PredicateParams, Provider, } from 'fuels'; @@ -85,7 +85,7 @@ const abi = { const bytecode = decompressBytecode('0x-bytecode-here'); -export class MyPredicate extends Predicate< +export class MyPredicate extends __Predicate< MyPredicateInputs, MyPredicateConfigurables > { diff --git a/packages/abi-typegen/test/fixtures/templates/predicate/main.hbs b/packages/abi-typegen/test/fixtures/templates/predicate/main.hbs index 8eaed3fbf41..db72da7067d 100644 --- a/packages/abi-typegen/test/fixtures/templates/predicate/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/predicate/main.hbs @@ -15,7 +15,7 @@ import { BN, decompressBytecode, InputValue, - Predicate, + Predicate as __Predicate, PredicateParams, Provider, } from 'fuels'; @@ -276,7 +276,7 @@ const abi = { const bytecode = decompressBytecode('0x-bytecode-here'); -export class MyPredicate extends Predicate< +export class MyPredicate extends __Predicate< MyPredicateInputs, MyPredicateConfigurables > { diff --git a/packages/abi-typegen/test/fixtures/templates/script-with-configurable/main.hbs b/packages/abi-typegen/test/fixtures/templates/script-with-configurable/main.hbs index 1dba51d94b0..a574e27c8a1 100644 --- a/packages/abi-typegen/test/fixtures/templates/script-with-configurable/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/script-with-configurable/main.hbs @@ -14,7 +14,7 @@ import { Account, BigNumberish, decompressBytecode, - Script, + Script as __Script, } from 'fuels'; export type ScoreInput = { user: BigNumberish, points: BigNumberish }; @@ -88,7 +88,7 @@ const abi = { const bytecode = decompressBytecode('0x-bytecode-here'); -export class MyScript extends Script { +export class MyScript extends __Script { static readonly abi = abi; static readonly bytecode = bytecode; diff --git a/packages/abi-typegen/test/fixtures/templates/script/main.hbs b/packages/abi-typegen/test/fixtures/templates/script/main.hbs index aa93e951140..a3e0446c47b 100644 --- a/packages/abi-typegen/test/fixtures/templates/script/main.hbs +++ b/packages/abi-typegen/test/fixtures/templates/script/main.hbs @@ -15,7 +15,7 @@ import { BigNumberish, BN, decompressBytecode, - Script, + Script as __Script, } from 'fuels'; import type { Option, Enum, Vec, Result } from "./common"; @@ -268,7 +268,7 @@ const abi = { const bytecode = decompressBytecode('0x-bytecode-here'); -export class MyScript extends Script { +export class MyScript extends __Script { static readonly abi = abi; static readonly bytecode = bytecode; diff --git a/packages/fuel-gauge/src/auth-testing.test.ts b/packages/fuel-gauge/src/auth-testing.test.ts index 4b783a047b1..229407e8cef 100644 --- a/packages/fuel-gauge/src/auth-testing.test.ts +++ b/packages/fuel-gauge/src/auth-testing.test.ts @@ -1,7 +1,7 @@ import { getRandomB256 } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; -import { AuthTestingContractFactory } from '../test/typegen/contracts'; +import { ContractFactory } from '../test/typegen/contracts'; import { launchTestContract } from './utils'; @@ -12,7 +12,7 @@ import { launchTestContract } from './utils'; describe('Auth Testing', () => { it('can get is_caller_external', async () => { using contractInstance = await launchTestContract({ - factory: AuthTestingContractFactory, + factory: ContractFactory, }); const { waitForResult } = await contractInstance.functions.is_caller_external().call(); @@ -23,7 +23,7 @@ describe('Auth Testing', () => { it('can check_msg_sender [with correct id]', async () => { using launched = await launchTestNode({ - contractsConfigs: [{ factory: AuthTestingContractFactory }], + contractsConfigs: [{ factory: ContractFactory }], }); const { @@ -42,7 +42,7 @@ describe('Auth Testing', () => { it('can check_msg_sender [with incorrect id]', async () => { using contractInstance = await launchTestContract({ - factory: AuthTestingContractFactory, + factory: ContractFactory, }); await expect( diff --git a/packages/fuel-gauge/src/predicate/predicate-general.test.ts b/packages/fuel-gauge/src/predicate/predicate-general.test.ts index 2052d796222..66c9a8338d4 100644 --- a/packages/fuel-gauge/src/predicate/predicate-general.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-general.test.ts @@ -1,8 +1,8 @@ -import type { BN, FakeResources } from 'fuels'; -import { Address, Predicate, ScriptTransactionRequest, bn } from 'fuels'; +import type { FakeResources } from 'fuels'; +import { Address, ScriptTransactionRequest, bn } from 'fuels'; import { ASSET_A, ASSET_B, launchTestNode } from 'fuels/test-utils'; -import { PredicateSum } from '../../test/typegen'; +import { Predicate } from '../../test/typegen'; /** * @group node @@ -28,9 +28,7 @@ describe('Predicate', () => { const value2 = bn(200); const value1 = bn(100); - const predicate = new Predicate<[BN, BN]>({ - abi: PredicateSum.abi, - bytecode: PredicateSum.bytecode, + const predicate = new Predicate({ provider, data: [value1, value2], }); diff --git a/packages/fuel-gauge/src/script-main-args.test.ts b/packages/fuel-gauge/src/script-main-args.test.ts index 8395e0fb66f..78f90b64402 100644 --- a/packages/fuel-gauge/src/script-main-args.test.ts +++ b/packages/fuel-gauge/src/script-main-args.test.ts @@ -1,8 +1,8 @@ import type { BigNumberish } from 'fuels'; -import { bn, Script } from 'fuels'; +import { bn, Script as FuelScript } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; -import { ScriptMainArgs, ScriptMainReturnStruct, ScriptMainTwoArgs } from '../test/typegen'; +import { ScriptMainArgs, ScriptMainReturnStruct, Script } from '../test/typegen'; type Baz = { x: number; @@ -20,7 +20,7 @@ describe('Script Coverage', () => { } = launched; const foo = 33; - const scriptInstance = new Script( + const scriptInstance = new FuelScript( ScriptMainArgs.bytecode, ScriptMainArgs.abi, wallet @@ -40,7 +40,7 @@ describe('Script Coverage', () => { wallets: [wallet], } = launched; - const scriptInstance = new ScriptMainTwoArgs(wallet); + const scriptInstance = new Script(wallet); const foo = 33; const bar: Baz = { x: 12, @@ -79,7 +79,7 @@ describe('Script Coverage', () => { wallets: [wallet], } = launched; - const scriptInstance = new Script( + const scriptInstance = new FuelScript( ScriptMainArgs.bytecode, ScriptMainArgs.abi, wallet diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml index 7a4dc974141..795e150ae68 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml @@ -5,8 +5,7 @@ members = [ "advanced-logging-abi", "advanced-logging-other-contract", "advanced-logging-other-contract-abi", - "auth_testing_abi", - "auth_testing_contract", + "contract", "bytecode-sway-lib", "bytes-contract", "call-test-contract", @@ -22,6 +21,7 @@ members = [ "smo-contract", "options", "payable-annotation", + "predicate", "predicate-address", "predicate-assert-number", "predicate-assert-value", @@ -35,7 +35,6 @@ members = [ "predicate-raw-slice", "predicate-std-lib-string", "predicate-str-slice", - "predicate-sum", "predicate-triple-sig", "predicate-true", "predicate-u32", @@ -55,7 +54,7 @@ members = [ "script-main-arg-bool", "script-main-args", "script-main-return-struct", - "script-main-two-args", + "script", "script-raw-slice", "script-std-lib-string", "script-str-slice", diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/src/main.sw deleted file mode 100644 index bb6a3eb85ee..00000000000 --- a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/src/main.sw +++ /dev/null @@ -1,6 +0,0 @@ -library; - -abi AuthTesting { - fn is_caller_external() -> bool; - fn check_msg_sender(expected_id: Address) -> bool; -} diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/Forc.toml deleted file mode 100644 index 9d4134d59fc..00000000000 --- a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/Forc.toml +++ /dev/null @@ -1,7 +0,0 @@ -[project] -authors = ["Fuel Labs "] -license = "Apache-2.0" -name = "auth_testing_contract" - -[dependencies] -auth_testing_abi = { path = "../auth_testing_abi" } diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/contract/Forc.toml similarity index 77% rename from packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/Forc.toml rename to packages/fuel-gauge/test/fixtures/forc-projects/contract/Forc.toml index 3fa6b5db1d9..82f6118a370 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/contract/Forc.toml @@ -1,6 +1,6 @@ [project] authors = ["Fuel Labs "] license = "Apache-2.0" -name = "auth_testing_abi" +name = "contract" [dependencies] diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/contract/src/main.sw similarity index 81% rename from packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/src/main.sw rename to packages/fuel-gauge/test/fixtures/forc-projects/contract/src/main.sw index 0db57d7c419..fa26d8e8e47 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/src/main.sw +++ b/packages/fuel-gauge/test/fixtures/forc-projects/contract/src/main.sw @@ -1,9 +1,13 @@ contract; use std::auth::{AuthError, caller_is_external, msg_sender}; -use auth_testing_abi::*; -impl AuthTesting for Contract { +abi Contract { + fn is_caller_external() -> bool; + fn check_msg_sender(expected_id: Address) -> bool; +} + +impl Contract for Contract { fn is_caller_external() -> bool { caller_is_external() } diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/predicate/Forc.toml similarity index 82% rename from packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/Forc.toml rename to packages/fuel-gauge/test/fixtures/forc-projects/predicate/Forc.toml index 7ce852ac82a..b3325bf1458 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/predicate/Forc.toml @@ -2,6 +2,6 @@ authors = ["Fuel Labs "] entry = "main.sw" license = "Apache-2.0" -name = "predicate-sum" +name = "predicate" [dependencies] diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/predicate/src/main.sw similarity index 100% rename from packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/src/main.sw rename to packages/fuel-gauge/test/fixtures/forc-projects/predicate/src/main.sw diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/script-main-two-args/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/script/Forc.toml similarity index 75% rename from packages/fuel-gauge/test/fixtures/forc-projects/script-main-two-args/Forc.toml rename to packages/fuel-gauge/test/fixtures/forc-projects/script/Forc.toml index cfe4c43b7ff..37ce6874697 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/script-main-two-args/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/script/Forc.toml @@ -1,6 +1,6 @@ [project] authors = ["Fuel Labs "] license = "Apache-2.0" -name = "script-main-two-args" +name = "script" [dependencies] diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/script-main-two-args/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/script/src/main.sw similarity index 100% rename from packages/fuel-gauge/test/fixtures/forc-projects/script-main-two-args/src/main.sw rename to packages/fuel-gauge/test/fixtures/forc-projects/script/src/main.sw diff --git a/packages/recipes/scripts/build-recipes.ts b/packages/recipes/scripts/build-recipes.ts index 9df639cbcfa..fcad1f909e8 100644 --- a/packages/recipes/scripts/build-recipes.ts +++ b/packages/recipes/scripts/build-recipes.ts @@ -6,8 +6,8 @@ execSync(`fuels-typegen -i src/contracts/**/*-abi.json -o src/types`); const supportedRecipes = ['Src14OwnedProxy'].map((s) => [s, `${s}Factory`]).flat(); const importReplacementMap = { - Contract: '@fuel-ts/program', - ContractFactory: '@fuel-ts/contract', + 'Contract as __Contract': '@fuel-ts/program', + 'ContractFactory as __ContractFactory': '@fuel-ts/contract', DeployContractOptions: '@fuel-ts/contract', Interface: '@fuel-ts/abi-coder', Provider: '@fuel-ts/account',