Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: usage of providerUrl in fuels dev command #3528

Merged
merged 19 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-oranges-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

fix: enable usage of `0` port for the `fuelCorePort` field
33 changes: 24 additions & 9 deletions .knip.json
nedsalk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{
"entry": [
"apps/docs/src/versions.data.ts",
"apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-2.ts"
"ignore": [
".github/**",
"**/*/fuels.config.*",
"**/*/.vitepress/*",
"/apps/docs/*",
"/packages/abi-typegen/test/**",
"templates/**",
"/apps/docs/**/*.test.ts",
"apps/create-fuels-counter-guide/**",
"apps/docs-api/**"
],
"ignore": [".github/**"],
"ignoreDependencies": [
"bun",
"fuels",
"autocannon",
"bun",
"@types/rimraf",
"@fuel-ts/abi-typegen",
"@/sway-api/*",
"@fuel-ts/*",
"@fuels/connectors",
"@internal/fuel-core",
"@internal/forc",
"@types/jest",
"@types/rimraf",
"@graphql-codegen*",
"graphql-tag",
"get-graphql-schema",
"events",
"eslint-plugin-jsdoc",
Expand All @@ -19,11 +31,14 @@
"eslint-plugin-react",
"eslint-plugin-react-hooks",
"dotenv",
"ethers",
"kill",
"lsof",
"memfs",
"open",
"markdown-link-check",
"ts-generator",
"vitepress-plugin-search",
"vue"
"webdriverio",
"syncpack"
]
}
1 change: 1 addition & 0 deletions apps/docs/fuels.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default createConfig({
forcBuildFlags: ['--release'],
forcPath: 'fuels-forc',
fuelCorePath: 'fuels-core',
fuelCorePort: 0,
});
3 changes: 1 addition & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"dev": "nodemon --config nodemon.config.json -x 'run-s build:snippets dev:docs'",
"build": "run-s build:snippets build:docs",
"preview": "run-s build:snippets preview:docs",
"pretest": "./scripts/pretest.sh",
"test": "cd ../.. && pnpm run test:filter apps/docs",
"build:snippets": "run-s wrap:snippets build:forc",
"build:docs": "vitepress build",
"preview:docs": "vitepress preview",
"dev:docs": "vitepress dev",
"wrap:snippets": "tsx ./scripts/wrap-snippets.ts",
"build:forc": "pnpm fuels build",
"build:forc": "pnpm fuels build --deploy",
"type:check": "pnpm tsc --noEmit --project tsconfig.emit.json"
},
"keywords": [],
Expand Down
16 changes: 0 additions & 16 deletions apps/docs/scripts/pretest.sh

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
"vite-plugin-json5": "1.1.2",
"vite-plugin-node-polyfills": "0.22.0",
"vite-plugin-plain-text": "1.4.2",
"vitest": "2.0.5"
"vitest": "2.0.5",
"fuels": "workspace:*"
nedsalk marked this conversation as resolved.
Show resolved Hide resolved
nedsalk marked this conversation as resolved.
Show resolved Hide resolved
},
"pnpm": {
"overrides": {
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-gauge/fuels.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default createConfig({
forcBuildFlags: ['--release'],
forcPath: 'fuels-forc',
fuelCorePath: 'fuels-core',
fuelCorePort: 0,
});
2 changes: 1 addition & 1 deletion packages/fuel-gauge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"scripts": {
"pretest": "pnpm build:forc",
"build:forc": "pnpm fuels build",
"build:forc": "pnpm fuels build --deploy",
"type:check": "tsc --noEmit"
},
"license": "Apache-2.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => {

const port = config.fuelCorePort ?? (await getPortPromise({ port: 4000 }));

const providerUrl = `http://${accessIp}:${port}/v1/graphql`;

const { cleanup, snapshotDir } = await launchNode({
const { cleanup, url, snapshotDir } = await launchNode({
nedsalk marked this conversation as resolved.
Show resolved Hide resolved
args: [
['--snapshot', config.snapshotDir],
['--db-type', 'in-memory'],
Expand All @@ -45,7 +43,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => {
bindIp,
accessIp,
port,
providerUrl,
providerUrl: url,
snapshotDir,
killChildProcess: cleanup,
};
Expand Down
40 changes: 40 additions & 0 deletions packages/fuels/test/features/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deferPromise } from '@fuel-ts/account';
import { spawn } from 'child_process';
import * as chokidar from 'chokidar';

import * as buildMod from '../../src/cli/commands/build/index';
Expand Down Expand Up @@ -77,4 +79,42 @@ describe('dev', () => {
expect(watch).toHaveBeenCalledTimes(2);
expect(on).toHaveBeenCalledTimes(2);
});

test('`dev` command can work with ephemeral port 0', { timeout: 25000 }, async () => {
await runInit({
root: paths.root,
workspace: paths.workspaceDir,
output: paths.outputDir,
forcPath: paths.forcPath,
fuelCorePath: paths.fuelCorePath,
fuelCorePort: '0',
});

const devProcess = spawn(`pnpm fuels dev --path ${paths.root}`, {
shell: 'bash',
});

const nodeLaunched = deferPromise<string>();

const graphQLStartSubstring = 'Binding GraphQL provider to';

devProcess.stdout.on('data', (chunk) => {
const text: string = chunk.toString();
if (text.indexOf(graphQLStartSubstring) !== -1) {
const rows = text.split('\n');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1)!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const [, port] = rowWithUrl.split(' ').at(-1)!.trim().split(':'); // e.g. "2024-02-13T12:31:44.445844Z INFO new{name=fuel-core}: fuel_core::graphql_api::service: 216: Binding GraphQL provider to 127.0.0.1:35039"

nodeLaunched.resolve(port);
}
});

const nodePort = await nodeLaunched.promise;

expect(nodePort).not.toBe('0');
// we verify it not to be the default port
expect(nodePort).not.toBe('4000');
});
});
Loading
Loading