Skip to content

Commit 68e4b5a

Browse files
authored
chore: prevent naming collisions on typegen (#3620)
1 parent ab56ded commit 68e4b5a

File tree

27 files changed

+61
-61
lines changed

27 files changed

+61
-61
lines changed

.changeset/six-moles-wonder.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@fuel-ts/abi-typegen": patch
3+
"@fuel-ts/recipes": patch
4+
---
5+
6+
chore: prevent naming collisions on typegen

packages/abi-typegen/src/templates/contract/factory.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{header}}
22

3-
import { ContractFactory, decompressBytecode } from "fuels";
3+
import { ContractFactory as __ContractFactory, decompressBytecode } from "fuels";
44
import type { Provider, Account, DeployContractOptions } from "fuels";
55

66
import { {{capitalizedName}} } from "./{{capitalizedName}}";
77

88
const bytecode = decompressBytecode("{{compressedBytecode}}");
99

10-
export class {{capitalizedName}}Factory extends ContractFactory<{{capitalizedName}}> {
10+
export class {{capitalizedName}}Factory extends __ContractFactory<{{capitalizedName}}> {
1111

1212
static readonly bytecode = bytecode;
1313

packages/abi-typegen/src/templates/contract/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{header}}
22

3-
import { Contract, Interface } from "fuels";
3+
import { Contract as __Contract, Interface } from "fuels";
44
{{#if imports}}
55
import type {
66
Provider,
@@ -69,7 +69,7 @@ export class {{capitalizedName}}Interface extends Interface {
6969
};
7070
}
7171

72-
export class {{capitalizedName}} extends Contract {
72+
export class {{capitalizedName}} extends __Contract {
7373
static readonly abi = abi;
7474
static readonly storageSlots = storageSlots;
7575

packages/abi-typegen/src/templates/predicate/main.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const abi = {{abiJsonString}};
6161

6262
const bytecode = decompressBytecode('{{compressedBytecode}}');
6363

64-
export class {{capitalizedName}} extends Predicate<
64+
export class {{capitalizedName}} extends __Predicate<
6565
{{capitalizedName}}Inputs,
6666
{{capitalizedName}}Configurables
6767
> {

packages/abi-typegen/src/templates/predicate/main.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions
3434
const { structs } = formatStructs({ types });
3535
const { imports } = formatImports({
3636
types,
37-
baseMembers: ['Predicate', 'Provider', 'InputValue', 'PredicateParams', 'decompressBytecode'],
37+
baseMembers: [
38+
'Predicate as __Predicate',
39+
'Provider',
40+
'InputValue',
41+
'PredicateParams',
42+
'decompressBytecode',
43+
],
3844
});
3945

4046
const { prefixedInputs: inputs, output } = func.attributes;

packages/abi-typegen/src/templates/script/main.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const abi = {{abiJsonString}};
5555

5656
const bytecode = decompressBytecode('{{compressedBytecode}}');
5757

58-
export class {{capitalizedName}} extends Script<{{capitalizedName}}Inputs, {{capitalizedName}}Output> {
58+
export class {{capitalizedName}} extends __Script<{{capitalizedName}}Inputs, {{capitalizedName}}Output> {
5959

6060
static readonly abi = abi;
6161
static readonly bytecode = bytecode;

packages/abi-typegen/src/templates/script/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function renderMainTemplate(params: { abi: Abi; versions: BinaryVersions
3434
const { structs } = formatStructs({ types });
3535
const { imports } = formatImports({
3636
types,
37-
baseMembers: ['Script', 'Account', 'decompressBytecode'],
37+
baseMembers: ['Script as __Script', 'Account', 'decompressBytecode'],
3838
});
3939

4040
const { prefixedInputs: inputs, output } = func.attributes;

packages/abi-typegen/test/fixtures/templates/contract-with-configurable/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Fuel-Core version: 33.33.33
1111
*/
1212

13-
import { Contract, Interface } from "fuels";
13+
import { Contract as __Contract, Interface } from "fuels";
1414
import type {
1515
Provider,
1616
Account,
@@ -187,7 +187,7 @@ export class MyContractInterface extends Interface {
187187
};
188188
}
189189

190-
export class MyContract extends Contract {
190+
export class MyContract extends __Contract {
191191
static readonly abi = abi;
192192
static readonly storageSlots = storageSlots;
193193

packages/abi-typegen/test/fixtures/templates/contract/factory.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
Fuel-Core version: 33.33.33
1111
*/
1212

13-
import { ContractFactory, decompressBytecode } from "fuels";
13+
import { ContractFactory as __ContractFactory, decompressBytecode } from "fuels";
1414
import type { Provider, Account, DeployContractOptions } from "fuels";
1515

1616
import { MyContract } from "./MyContract";
1717

1818
const bytecode = decompressBytecode("0x-bytecode-here");
1919

20-
export class MyContractFactory extends ContractFactory<MyContract> {
20+
export class MyContractFactory extends __ContractFactory<MyContract> {
2121

2222
static readonly bytecode = bytecode;
2323

packages/abi-typegen/test/fixtures/templates/contract/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Fuel-Core version: 33.33.33
1111
*/
1212

13-
import { Contract, Interface } from "fuels";
13+
import { Contract as __Contract, Interface } from "fuels";
1414
import type {
1515
Provider,
1616
Account,
@@ -1199,7 +1199,7 @@ export class MyContractInterface extends Interface {
11991199
};
12001200
}
12011201

1202-
export class MyContract extends Contract {
1202+
export class MyContract extends __Contract {
12031203
static readonly abi = abi;
12041204
static readonly storageSlots = storageSlots;
12051205

packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
BigNumberish,
1515
decompressBytecode,
1616
InputValue,
17-
Predicate,
17+
Predicate as __Predicate,
1818
PredicateParams,
1919
Provider,
2020
} from 'fuels';
@@ -85,7 +85,7 @@ const abi = {
8585

8686
const bytecode = decompressBytecode('0x-bytecode-here');
8787

88-
export class MyPredicate extends Predicate<
88+
export class MyPredicate extends __Predicate<
8989
MyPredicateInputs,
9090
MyPredicateConfigurables
9191
> {

packages/abi-typegen/test/fixtures/templates/predicate/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
BN,
1616
decompressBytecode,
1717
InputValue,
18-
Predicate,
18+
Predicate as __Predicate,
1919
PredicateParams,
2020
Provider,
2121
} from 'fuels';
@@ -276,7 +276,7 @@ const abi = {
276276

277277
const bytecode = decompressBytecode('0x-bytecode-here');
278278

279-
export class MyPredicate extends Predicate<
279+
export class MyPredicate extends __Predicate<
280280
MyPredicateInputs,
281281
MyPredicateConfigurables
282282
> {

packages/abi-typegen/test/fixtures/templates/script-with-configurable/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Account,
1515
BigNumberish,
1616
decompressBytecode,
17-
Script,
17+
Script as __Script,
1818
} from 'fuels';
1919

2020
export type ScoreInput = { user: BigNumberish, points: BigNumberish };
@@ -88,7 +88,7 @@ const abi = {
8888

8989
const bytecode = decompressBytecode('0x-bytecode-here');
9090

91-
export class MyScript extends Script<MyScriptInputs, MyScriptOutput> {
91+
export class MyScript extends __Script<MyScriptInputs, MyScriptOutput> {
9292

9393
static readonly abi = abi;
9494
static readonly bytecode = bytecode;

packages/abi-typegen/test/fixtures/templates/script/main.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
BigNumberish,
1616
BN,
1717
decompressBytecode,
18-
Script,
18+
Script as __Script,
1919
} from 'fuels';
2020

2121
import type { Option, Enum, Vec, Result } from "./common";
@@ -268,7 +268,7 @@ const abi = {
268268

269269
const bytecode = decompressBytecode('0x-bytecode-here');
270270

271-
export class MyScript extends Script<MyScriptInputs, MyScriptOutput> {
271+
export class MyScript extends __Script<MyScriptInputs, MyScriptOutput> {
272272

273273
static readonly abi = abi;
274274
static readonly bytecode = bytecode;

packages/fuel-gauge/src/auth-testing.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getRandomB256 } from 'fuels';
22
import { launchTestNode } from 'fuels/test-utils';
33

4-
import { AuthTestingContractFactory } from '../test/typegen/contracts';
4+
import { ContractFactory } from '../test/typegen/contracts';
55

66
import { launchTestContract } from './utils';
77

@@ -12,7 +12,7 @@ import { launchTestContract } from './utils';
1212
describe('Auth Testing', () => {
1313
it('can get is_caller_external', async () => {
1414
using contractInstance = await launchTestContract({
15-
factory: AuthTestingContractFactory,
15+
factory: ContractFactory,
1616
});
1717

1818
const { waitForResult } = await contractInstance.functions.is_caller_external().call();
@@ -23,7 +23,7 @@ describe('Auth Testing', () => {
2323

2424
it('can check_msg_sender [with correct id]', async () => {
2525
using launched = await launchTestNode({
26-
contractsConfigs: [{ factory: AuthTestingContractFactory }],
26+
contractsConfigs: [{ factory: ContractFactory }],
2727
});
2828

2929
const {
@@ -42,7 +42,7 @@ describe('Auth Testing', () => {
4242

4343
it('can check_msg_sender [with incorrect id]', async () => {
4444
using contractInstance = await launchTestContract({
45-
factory: AuthTestingContractFactory,
45+
factory: ContractFactory,
4646
});
4747

4848
await expect(

packages/fuel-gauge/src/predicate/predicate-general.test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { BN, FakeResources } from 'fuels';
2-
import { Address, Predicate, ScriptTransactionRequest, bn } from 'fuels';
1+
import type { FakeResources } from 'fuels';
2+
import { Address, ScriptTransactionRequest, bn } from 'fuels';
33
import { ASSET_A, ASSET_B, launchTestNode } from 'fuels/test-utils';
44

5-
import { PredicateSum } from '../../test/typegen';
5+
import { Predicate } from '../../test/typegen';
66

77
/**
88
* @group node
@@ -28,9 +28,7 @@ describe('Predicate', () => {
2828
const value2 = bn(200);
2929
const value1 = bn(100);
3030

31-
const predicate = new Predicate<[BN, BN]>({
32-
abi: PredicateSum.abi,
33-
bytecode: PredicateSum.bytecode,
31+
const predicate = new Predicate({
3432
provider,
3533
data: [value1, value2],
3634
});

packages/fuel-gauge/src/script-main-args.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { BigNumberish } from 'fuels';
2-
import { bn, Script } from 'fuels';
2+
import { bn, Script as FuelScript } from 'fuels';
33
import { launchTestNode } from 'fuels/test-utils';
44

5-
import { ScriptMainArgs, ScriptMainReturnStruct, ScriptMainTwoArgs } from '../test/typegen';
5+
import { ScriptMainArgs, ScriptMainReturnStruct, Script } from '../test/typegen';
66

77
type Baz = {
88
x: number;
@@ -20,7 +20,7 @@ describe('Script Coverage', () => {
2020
} = launched;
2121

2222
const foo = 33;
23-
const scriptInstance = new Script<BigNumberish[], BigNumberish>(
23+
const scriptInstance = new FuelScript<BigNumberish[], BigNumberish>(
2424
ScriptMainArgs.bytecode,
2525
ScriptMainArgs.abi,
2626
wallet
@@ -40,7 +40,7 @@ describe('Script Coverage', () => {
4040
wallets: [wallet],
4141
} = launched;
4242

43-
const scriptInstance = new ScriptMainTwoArgs(wallet);
43+
const scriptInstance = new Script(wallet);
4444
const foo = 33;
4545
const bar: Baz = {
4646
x: 12,
@@ -79,7 +79,7 @@ describe('Script Coverage', () => {
7979
wallets: [wallet],
8080
} = launched;
8181

82-
const scriptInstance = new Script<BigNumberish[], BigNumberish>(
82+
const scriptInstance = new FuelScript<BigNumberish[], BigNumberish>(
8383
ScriptMainArgs.bytecode,
8484
ScriptMainArgs.abi,
8585
wallet

packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ members = [
55
"advanced-logging-abi",
66
"advanced-logging-other-contract",
77
"advanced-logging-other-contract-abi",
8-
"auth_testing_abi",
9-
"auth_testing_contract",
8+
"contract",
109
"bytecode-sway-lib",
1110
"bytes-contract",
1211
"call-test-contract",
@@ -22,6 +21,7 @@ members = [
2221
"smo-contract",
2322
"options",
2423
"payable-annotation",
24+
"predicate",
2525
"predicate-address",
2626
"predicate-assert-number",
2727
"predicate-assert-value",
@@ -35,7 +35,6 @@ members = [
3535
"predicate-raw-slice",
3636
"predicate-std-lib-string",
3737
"predicate-str-slice",
38-
"predicate-sum",
3938
"predicate-triple-sig",
4039
"predicate-true",
4140
"predicate-u32",
@@ -55,7 +54,7 @@ members = [
5554
"script-main-arg-bool",
5655
"script-main-args",
5756
"script-main-return-struct",
58-
"script-main-two-args",
57+
"script",
5958
"script-raw-slice",
6059
"script-std-lib-string",
6160
"script-str-slice",

packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_abi/src/main.sw

-6
This file was deleted.

packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/Forc.toml

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
authors = ["Fuel Labs <[email protected]>"]
33
license = "Apache-2.0"
4-
name = "auth_testing_abi"
4+
name = "contract"
55

66
[dependencies]

packages/fuel-gauge/test/fixtures/forc-projects/auth_testing_contract/src/main.sw renamed to packages/fuel-gauge/test/fixtures/forc-projects/contract/src/main.sw

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
contract;
22

33
use std::auth::{AuthError, caller_is_external, msg_sender};
4-
use auth_testing_abi::*;
54

6-
impl AuthTesting for Contract {
5+
abi Contract {
6+
fn is_caller_external() -> bool;
7+
fn check_msg_sender(expected_id: Address) -> bool;
8+
}
9+
10+
impl Contract for Contract {
711
fn is_caller_external() -> bool {
812
caller_is_external()
913
}

packages/fuel-gauge/test/fixtures/forc-projects/predicate-sum/Forc.toml renamed to packages/fuel-gauge/test/fixtures/forc-projects/predicate/Forc.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
authors = ["Fuel Labs <[email protected]>"]
33
entry = "main.sw"
44
license = "Apache-2.0"
5-
name = "predicate-sum"
5+
name = "predicate"
66

77
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
authors = ["Fuel Labs <[email protected]>"]
33
license = "Apache-2.0"
4-
name = "script-main-two-args"
4+
name = "script"
55

66
[dependencies]

0 commit comments

Comments
 (0)