diff --git a/.changeset/nervous-shirts-know.md b/.changeset/nervous-shirts-know.md new file mode 100644 index 00000000000..ee22a1a5aaf --- /dev/null +++ b/.changeset/nervous-shirts-know.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/account": minor +"fuels": patch +--- + +chore!: deprecate `FUEL_NETWORK_URL` and `LOCAL_NETWORK_URL` diff --git a/.env.example b/.env.example index c742d422bce..d848920a46b 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ -FUEL_NETWORK_URL= -TEST_WALLET_PVT_KEY= +DEVNET_WALLET_PVT_KEY= +TESTNET_WALLET_PVT_KEY= PUBLISHED_NPM_TAG= \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b34a6f140c..10fe95498c9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -156,8 +156,8 @@ cp .env.example .env.test And changing the below variables: ```sh -FUEL_NETWORK_URL=https://testnet.fuel.network/v1/graphql -TEST_WALLET_PVT_KEY=0x... +DEVNET_WALLET_PVT_KEY=0x... +TESTNET_WALLET_PVT_KEY=0x... ``` diff --git a/apps/docs-snippets/src/guide/introduction/getting-started.test.ts b/apps/docs-snippets/src/guide/introduction/getting-started.test.ts index 2479c139cc4..1b69fa72674 100644 --- a/apps/docs-snippets/src/guide/introduction/getting-started.test.ts +++ b/apps/docs-snippets/src/guide/introduction/getting-started.test.ts @@ -7,10 +7,11 @@ import { launchTestNode } from 'fuels/test-utils'; */ describe('Getting started', () => { it('can connect to a local network', async () => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - using launched = await launchTestNode({ - nodeOptions: { port: '4000' }, - }); + using launched = await launchTestNode(); + + const mockedProvider = await Provider.create(launched.provider.url); + vi.spyOn(Provider, 'create').mockResolvedValueOnce(mockedProvider); + // #region connecting-to-the-local-node // #import { Provider, Wallet }; @@ -30,6 +31,11 @@ describe('Getting started', () => { }); it('can connect to testnet', async () => { + using launched = await launchTestNode(); + + const mockedProvider = await Provider.create(launched.provider.url); + vi.spyOn(Provider, 'create').mockResolvedValueOnce(mockedProvider); + // #region connecting-to-the-testnet // #import { Provider, Wallet, TESTNET_NETWORK_URL }; diff --git a/apps/docs-snippets/src/guide/provider/provider.test.ts b/apps/docs-snippets/src/guide/provider/provider.test.ts index e260b637234..e4da394b958 100644 --- a/apps/docs-snippets/src/guide/provider/provider.test.ts +++ b/apps/docs-snippets/src/guide/provider/provider.test.ts @@ -1,14 +1,4 @@ -/* eslint-disable @typescript-eslint/no-shadow */ -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { - Provider, - ScriptTransactionRequest, - sleep, - WalletUnlocked, - Address, - FUEL_NETWORK_URL, -} from 'fuels'; +import { Provider, ScriptTransactionRequest, sleep, WalletUnlocked, Address } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; async function fetchSomeExternalCredentials() { @@ -27,10 +17,13 @@ describe('Provider', () => { it('base examples', async () => { using launched = await launchTestNode(); - const FUEL_NETWORK_URL = launched.provider.url; + const mockedProvider = await Provider.create(launched.provider.url); + vi.spyOn(Provider, 'create').mockResolvedValueOnce(mockedProvider); // #region provider-definition - // #import { Provider, FUEL_NETWORK_URL, WalletUnlocked }; + // #import { Provider, WalletUnlocked }; + + const FUEL_NETWORK_URL = 'http://127.0.0.1:4000/v1/graphql'; // Create the provider const provider = await Provider.create(FUEL_NETWORK_URL); @@ -57,6 +50,7 @@ describe('Provider', () => { using launched = await launchTestNode(); const FUEL_NETWORK_URL = launched.provider.url; + // #region options-requestMiddleware // synchronous request middleware await Provider.create(FUEL_NETWORK_URL, { @@ -147,10 +141,13 @@ describe('Provider', () => { const recipientAddress = Address.fromRandom(); using launched = await launchTestNode(); - const FUEL_NETWORK_URL = launched.provider.url; + const mockedProvider = await Provider.create(launched.provider.url); + vi.spyOn(Provider, 'create').mockResolvedValueOnce(mockedProvider); // #region provider-getBaseAssetId - // #import { Provider, FUEL_NETWORK_URL, ScriptTransactionRequest }; + // #import { Provider, ScriptTransactionRequest }; + + const FUEL_NETWORK_URL = 'http://127.0.0.1:4000/v1/graphql'; // Fetch the base asset ID using the provider const provider = await Provider.create(FUEL_NETWORK_URL); diff --git a/apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts b/apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts index 6b139ba6b5c..cc8ba8c574d 100644 --- a/apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts +++ b/apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable @typescript-eslint/no-shadow */ import type { TransactionResultMessageOutReceipt, CoinQuantityLike, ExcludeResourcesOption, } from 'fuels'; -import { ScriptTransactionRequest, FUEL_NETWORK_URL, Provider } from 'fuels'; +import { ScriptTransactionRequest, Provider } from 'fuels'; import { TestAssetId, TestMessage, launchTestNode } from 'fuels/test-utils'; /** @@ -28,7 +27,7 @@ describe('querying the chain', () => { const FUEL_NETWORK_URL = testProvider.url; // #region get-coins-1 - // #import { Provider, FUEL_NETWORK_URL }; + // #import { Provider }; const provider = await Provider.create(FUEL_NETWORK_URL); @@ -74,7 +73,7 @@ describe('querying the chain', () => { const FUEL_NETWORK_URL = testProvider.url; // #region get-spendable-resources-1 - // #import { Provider, FUEL_NETWORK_URL, ScriptTransactionRequest, CoinQuantityLike, ExcludeResourcesOption }; + // #import { Provider, ScriptTransactionRequest, CoinQuantityLike, ExcludeResourcesOption }; const provider = await Provider.create(FUEL_NETWORK_URL); const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101'; @@ -125,7 +124,7 @@ describe('querying the chain', () => { const FUEL_NETWORK_URL = testProvider.url; // #region get-balances-1 - // #import { Provider, FUEL_NETWORK_URL }; + // #import { Provider }; const provider = await Provider.create(FUEL_NETWORK_URL); @@ -149,7 +148,7 @@ describe('querying the chain', () => { const FUEL_NETWORK_URL = launched.provider.url; // #region Provider-get-blocks - // #import { Provider, FUEL_NETWORK_URL }; + // #import { Provider }; const provider = await Provider.create(FUEL_NETWORK_URL); @@ -172,7 +171,7 @@ describe('querying the chain', () => { const FUEL_NETWORK_URL = testProvider.url; // #region get-message-by-nonce-1 - // #import { Provider, FUEL_NETWORK_URL }; + // #import { Provider }; const provider = await Provider.create(FUEL_NETWORK_URL); diff --git a/internal/check-imports/src/references.ts b/internal/check-imports/src/references.ts index 9585d70691d..aa4fbbe098a 100644 --- a/internal/check-imports/src/references.ts +++ b/internal/check-imports/src/references.ts @@ -13,7 +13,6 @@ import { Predicate, Provider, } from '@fuel-ts/account'; -import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs'; import { Address } from '@fuel-ts/address'; import { ContractFactory } from '@fuel-ts/contract'; import { encrypt, decrypt } from '@fuel-ts/crypto'; @@ -167,7 +166,6 @@ log(WalletManager); * wallet */ log(Wallet); -log(FUEL_NETWORK_URL); /** * wordlists diff --git a/packages/account/src/configs.test.ts b/packages/account/src/configs.test.ts index 96a0a598347..b33435a1ddb 100644 --- a/packages/account/src/configs.test.ts +++ b/packages/account/src/configs.test.ts @@ -1,17 +1,8 @@ /** * @group node + * @group browser */ describe('Configs', () => { - it('exports FUEL_NETWORK_URL', async () => { - const configs = await import('./configs'); - expect(configs.FUEL_NETWORK_URL).toBe('http://127.0.0.1:4000/v1/graphql'); - }); - - it('exports LOCAL_NETWORK_URL', async () => { - const configs = await import('./configs'); - expect(configs.LOCAL_NETWORK_URL).toBe('http://127.0.0.1:4000/v1/graphql'); - }); - it('exports DEVNET_NETWORK_URL', async () => { const configs = await import('./configs'); expect(configs.DEVNET_NETWORK_URL).toBe('https://devnet.fuel.network/v1/graphql'); @@ -22,49 +13,3 @@ describe('Configs', () => { expect(configs.TESTNET_NETWORK_URL).toBe('https://testnet.fuel.network/v1/graphql'); }); }); - -describe('Configs - undefined process', () => { - const originalProcess = process; - - beforeEach(() => { - vi.resetModules(); - - // @ts-expect-error - test to assert undefined process - // eslint-disable-next-line no-global-assign - process = undefined; - }); - - afterEach(() => { - // eslint-disable-next-line no-global-assign - process = originalProcess; - }); - - it('exports FUEL_NETWORK_URL with undefined process', async () => { - expect(typeof process).toBe('undefined'); - expect(process).toBeUndefined(); - - const configs = await import('./configs'); - - expect(configs.FUEL_NETWORK_URL).toBe('http://127.0.0.1:4000/v1/graphql'); - }); -}); - -describe('Configs - overridden env', () => { - const originalEnv = process.env; - - beforeEach(() => { - vi.resetModules(); - - process.env = { ...originalEnv, FUEL_NETWORK_URL: 'some-other-network-url' }; - }); - - afterEach(() => { - process.env = originalEnv; - }); - - it('exports FUEL_NETWORK_URL with overridden env', async () => { - const configs = await import('./configs'); - - expect(configs.FUEL_NETWORK_URL).toBe('some-other-network-url'); - }); -}); diff --git a/packages/account/src/configs.ts b/packages/account/src/configs.ts index 9d150651fff..816ddf0a0dd 100644 --- a/packages/account/src/configs.ts +++ b/packages/account/src/configs.ts @@ -1,10 +1,4 @@ -export const LOCAL_NETWORK_URL = 'http://127.0.0.1:4000/v1/graphql'; export const DEVNET_NETWORK_URL = 'https://devnet.fuel.network/v1/graphql'; export const TESTNET_NETWORK_URL = 'https://testnet.fuel.network/v1/graphql'; // TODO: replace placeholder with mainnet network url // export const NETWORK_URL = ''; - -export const FUEL_NETWORK_URL: string = - typeof process !== 'undefined' - ? process?.env?.FUEL_NETWORK_URL || LOCAL_NETWORK_URL - : LOCAL_NETWORK_URL; diff --git a/packages/account/test/fixtures/mocked-connector.ts b/packages/account/test/fixtures/mocked-connector.ts index db52e51f9f3..cbdedaeb9ae 100644 --- a/packages/account/test/fixtures/mocked-connector.ts +++ b/packages/account/test/fixtures/mocked-connector.ts @@ -9,7 +9,6 @@ import type { ConnectorMetadata, Network, } from '../../src'; -import { FUEL_NETWORK_URL } from '../../src/configs'; import { FuelConnector } from '../../src/connectors/fuel-connector'; import { FuelConnectorEventTypes } from '../../src/connectors/types'; import type { Asset } from '../../src/providers/assets/types'; @@ -51,7 +50,7 @@ export class MockConnector extends FuelConnector { this._networks = options.networks ?? [ { chainId: 0, - url: FUEL_NETWORK_URL, + url: 'http://127.0.0.1/v1/graphql', }, ]; // Time should be under 1 second diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index 53f87ded6b2..d950c510c91 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -34,6 +34,7 @@ describe('autoStartFuelCore', () => { port: '4000', url: 'http://127.0.0.1:4000/v1/graphql', snapshotDir: '/some/path', + pid: 1234, }) ); return { launchNode }; diff --git a/packages/fuels/src/cli/config/loadConfig.ts b/packages/fuels/src/cli/config/loadConfig.ts index 72ffc764a98..9afb74d95c6 100644 --- a/packages/fuels/src/cli/config/loadConfig.ts +++ b/packages/fuels/src/cli/config/loadConfig.ts @@ -1,4 +1,3 @@ -import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs'; import { FuelError } from '@fuel-ts/errors'; import { defaultConsensusKey } from '@fuel-ts/utils'; import { bundleRequire } from 'bundle-require'; @@ -64,7 +63,7 @@ export async function loadConfig(cwd: string): Promise { deployConfig: {}, autoStartFuelCore: true, fuelCorePort: 4000, - providerUrl: FUEL_NETWORK_URL, + providerUrl: process.env.FUEL_NETWORK_URL ?? 'http://127.0.0.1:4000/v1/graphql', privateKey: defaultConsensusKey, ...userConfig, basePath: cwd, diff --git a/packages/fuels/test/fixtures/fuels.config.ts b/packages/fuels/test/fixtures/fuels.config.ts index ce52f7fe227..012c70bfc43 100644 --- a/packages/fuels/test/fixtures/fuels.config.ts +++ b/packages/fuels/test/fixtures/fuels.config.ts @@ -1,4 +1,3 @@ -import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs'; import { join } from 'path'; import type { FuelsConfig } from '../../src'; @@ -21,7 +20,7 @@ export const fuelsConfig: FuelsConfig = { deployConfig: {}, autoStartFuelCore: true, fuelCorePort: 4000, - providerUrl: FUEL_NETWORK_URL, + providerUrl: 'http://127.0.0.1:4000/v1/graphql', configPath: __filename, forcBuildFlags: [], buildMode: 'debug', diff --git a/packages/fuels/test/utils/mockAutoStartFuelCore.ts b/packages/fuels/test/utils/mockAutoStartFuelCore.ts index 579d22883ba..2ef24daf138 100644 --- a/packages/fuels/test/utils/mockAutoStartFuelCore.ts +++ b/packages/fuels/test/utils/mockAutoStartFuelCore.ts @@ -1,4 +1,3 @@ -import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs'; import type { SpyInstance } from 'vitest'; import * as autoStartFuelCoreMod from '../../src/cli/commands/dev/autoStartFuelCore'; @@ -14,7 +13,7 @@ export const mockStartFuelCore = (): { bindIp: '0.0.0.0', accessIp: '127.0.0.1', port: 4000, - providerUrl: FUEL_NETWORK_URL, + providerUrl: 'http://127.0.0.1:4000/v1/graphql', killChildProcess, snapshotDir: '/some/path', };