Skip to content

Commit

Permalink
chore!: deprecate FUEL_NETWORK_URL and LOCAL_NETWORK_URL (#2915)
Browse files Browse the repository at this point in the history
* refactor: integrated launchTestNode in remaining files

* docs: update changeset

* test: integrated launchTestNode into all tests excluding doc-snippets

* wip

* test: refactored many tests in docs-snippets

* test: skipping currently failing test suites for ci tests

* docs: add changeset

* deps: update dependencies

* deps: remove cyclical dependency

* deps: updated dependencies to use setupTestWallet for now

* fix: add error handling for in memory store historical view issues

* test: enable browser for demo-fuels index test

* docs: added comments about typegen contract call mismatches

* revert error supression on provider

* test: increasing block production time

* test: browser test adjusments

* test: browser test adjustments

* test: update provider test case for snippets

* chore: refactor to use new typegen types

* linting

* chore: resolve issue with account tests

* chore: undo create-fuels.js change

* chore: update poa-interval-period

* chore: update querying chain docs tests

* test: update FUEL_CORE compatability tests

* linting fixes

* docs: use custom port for launchTestNode

* docs: update docs with PR feedback

* chore: remove unused testing utilities

* chore: more PR feedback refactors

* ci: update CI workflow test scripts

* ci: update workflow steps

* test: update tests to spin up temp nodes in setup

* linting

* docs: update changesets

Co-authored-by: Peter Smith <[email protected]>

* chore: update variable assignment

Co-authored-by: Peter Smith <[email protected]>

* docs: update imports

Co-authored-by: Peter Smith <[email protected]>

* chore: pr feedback changes

* docs: re-introduce testing wallets docs (#2635)

Co-authored-by: Anderson Arboleya <[email protected]>

* chore: update changesets + feedback

* ci: remove unnecessary clean step

* chore: deprecated urls

* chore: changeset

* docs: update contributing docs

* chore: update test asset IDs

* Update network url

* chore: refactor account tests to use helper

* chore: pr feedback

* docs: update changesets

* docs: update changeset to breaking

* docs: remove unnecessary updates from changeset

* chore: removed `FUEL_NETWORK_URL` env

* chore: updated pvt key envs

* chore: changeset

---------

Co-authored-by: chad <[email protected]>
Co-authored-by: Sérgio Torres <[email protected]>
Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
4 people authored Aug 15, 2024
1 parent 6b4d754 commit 56018e3
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 102 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-shirts-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": minor
"fuels": patch
---

chore!: deprecate `FUEL_NETWORK_URL` and `LOCAL_NETWORK_URL`
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FUEL_NETWORK_URL=
TEST_WALLET_PVT_KEY=
DEVNET_WALLET_PVT_KEY=
TESTNET_WALLET_PVT_KEY=
PUBLISHED_NPM_TAG=
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
```

<!-- TODO: add/fix block explorer URL after testnet support- Checking Wallet Balance: https://fuellabs.github.io/block-explorer-v2/beta-5/?#/address/fuel1x33ajpj0jy5p2wcqqu45e32r75zrwfeh6hwqfv5un670rv4p0mns58enjg -->
Expand Down
14 changes: 10 additions & 4 deletions apps/docs-snippets/src/guide/introduction/getting-started.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -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 };

Expand Down
27 changes: 12 additions & 15 deletions apps/docs-snippets/src/guide/provider/provider.test.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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);
Expand All @@ -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, {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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);

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions internal/check-imports/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -167,7 +166,6 @@ log(WalletManager);
* wallet
*/
log(Wallet);
log(FUEL_NETWORK_URL);

/**
* wordlists
Expand Down
57 changes: 1 addition & 56 deletions packages/account/src/configs.test.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
});
});
6 changes: 0 additions & 6 deletions packages/account/src/configs.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 1 addition & 2 deletions packages/account/test/fixtures/mocked-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('autoStartFuelCore', () => {
port: '4000',
url: 'http://127.0.0.1:4000/v1/graphql',
snapshotDir: '/some/path',
pid: 1234,
})
);
return { launchNode };
Expand Down
3 changes: 1 addition & 2 deletions packages/fuels/src/cli/config/loadConfig.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,7 +63,7 @@ export async function loadConfig(cwd: string): Promise<FuelsConfig> {
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,
Expand Down
3 changes: 1 addition & 2 deletions packages/fuels/test/fixtures/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs';
import { join } from 'path';

import type { FuelsConfig } from '../../src';
Expand All @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions packages/fuels/test/utils/mockAutoStartFuelCore.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
};
Expand Down

0 comments on commit 56018e3

Please sign in to comment.