Skip to content

Commit

Permalink
chore: prevent naming collisions on typegen (#3620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Jan 24, 2025
1 parent ab56ded commit 68e4b5a
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 61 deletions.
6 changes: 6 additions & 0 deletions .changeset/six-moles-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/abi-typegen": patch
"@fuel-ts/recipes": patch
---

chore: prevent naming collisions on typegen
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/templates/contract/factory.hbs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/templates/contract/main.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{header}}

import { Contract, Interface } from "fuels";
import { Contract as __Contract, Interface } from "fuels";
{{#if imports}}
import type {
Provider,
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/templates/predicate/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
> {
Expand Down
8 changes: 7 additions & 1 deletion packages/abi-typegen/src/templates/predicate/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/templates/script/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/templates/script/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyContract> {
export class MyContractFactory extends __ContractFactory<MyContract> {

static readonly bytecode = bytecode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
BigNumberish,
decompressBytecode,
InputValue,
Predicate,
Predicate as __Predicate,
PredicateParams,
Provider,
} from 'fuels';
Expand Down Expand Up @@ -85,7 +85,7 @@ const abi = {

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

export class MyPredicate extends Predicate<
export class MyPredicate extends __Predicate<
MyPredicateInputs,
MyPredicateConfigurables
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
BN,
decompressBytecode,
InputValue,
Predicate,
Predicate as __Predicate,
PredicateParams,
Provider,
} from 'fuels';
Expand Down Expand Up @@ -276,7 +276,7 @@ const abi = {

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

export class MyPredicate extends Predicate<
export class MyPredicate extends __Predicate<
MyPredicateInputs,
MyPredicateConfigurables
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Account,
BigNumberish,
decompressBytecode,
Script,
Script as __Script,
} from 'fuels';

export type ScoreInput = { user: BigNumberish, points: BigNumberish };
Expand Down Expand Up @@ -88,7 +88,7 @@ const abi = {

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

export class MyScript extends Script<MyScriptInputs, MyScriptOutput> {
export class MyScript extends __Script<MyScriptInputs, MyScriptOutput> {

static readonly abi = abi;
static readonly bytecode = bytecode;
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/test/fixtures/templates/script/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
BigNumberish,
BN,
decompressBytecode,
Script,
Script as __Script,
} from 'fuels';

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

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

export class MyScript extends Script<MyScriptInputs, MyScriptOutput> {
export class MyScript extends __Script<MyScriptInputs, MyScriptOutput> {

static readonly abi = abi;
static readonly bytecode = bytecode;
Expand Down
8 changes: 4 additions & 4 deletions packages/fuel-gauge/src/auth-testing.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions packages/fuel-gauge/src/predicate/predicate-general.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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],
});
Expand Down
10 changes: 5 additions & 5 deletions packages/fuel-gauge/src/script-main-args.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +20,7 @@ describe('Script Coverage', () => {
} = launched;

const foo = 33;
const scriptInstance = new Script<BigNumberish[], BigNumberish>(
const scriptInstance = new FuelScript<BigNumberish[], BigNumberish>(
ScriptMainArgs.bytecode,
ScriptMainArgs.abi,
wallet
Expand All @@ -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,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Script Coverage', () => {
wallets: [wallet],
} = launched;

const scriptInstance = new Script<BigNumberish[], BigNumberish>(
const scriptInstance = new FuelScript<BigNumberish[], BigNumberish>(
ScriptMainArgs.bytecode,
ScriptMainArgs.abi,
wallet
Expand Down
7 changes: 3 additions & 4 deletions packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,6 +21,7 @@ members = [
"smo-contract",
"options",
"payable-annotation",
"predicate",
"predicate-address",
"predicate-assert-number",
"predicate-assert-value",
Expand All @@ -35,7 +35,6 @@ members = [
"predicate-raw-slice",
"predicate-std-lib-string",
"predicate-str-slice",
"predicate-sum",
"predicate-triple-sig",
"predicate-true",
"predicate-u32",
Expand All @@ -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",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "auth_testing_abi"
name = "contract"

[dependencies]
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "predicate-sum"
name = "predicate"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "script-main-two-args"
name = "script"

[dependencies]
Loading

0 comments on commit 68e4b5a

Please sign in to comment.