Skip to content

Commit

Permalink
Merge branch 'master' of github.com:FuelLabs/fuels-ts into db/docs/tx…
Browse files Browse the repository at this point in the history
…-speed
  • Loading branch information
danielbate committed Jan 10, 2025
2 parents eaaa903 + f293646 commit 8cca7c4
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 1,410 deletions.
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: usage of `providerUrl` in `fuels dev` command
1 change: 0 additions & 1 deletion .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
],
"ignore": [".github/**"],
"ignoreDependencies": [
"bun",
"fuels",
"bun",
"@types/rimraf",
Expand Down
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.

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 <[email protected]> (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({
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
48 changes: 48 additions & 0 deletions packages/fuels/test/features/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { deferPromise } from '@fuel-ts/account';
import { spawn } from 'child_process';
import * as chokidar from 'chokidar';
import { join } from 'path';
import { cwd } from 'process';

import * as buildMod from '../../src/cli/commands/build/index';
import * as deployMod from '../../src/cli/commands/deploy/index';
Expand Down Expand Up @@ -77,4 +81,48 @@ 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',
/**
* pnpm fuels dev fails because the test is run in the root directory
* and there is no `fuels` dependency in `package.json` there,
* so we have to give the spawn a cwd which has `fuels` as a dependency.
*/
cwd: join(cwd(), 'packages/fuel-gauge'),
});

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

0 comments on commit 8cca7c4

Please sign in to comment.