Skip to content

Commit

Permalink
chore: improve node incompatibility warning (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf committed Aug 19, 2024
1 parent b185484 commit 2be4a5e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-paws-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

chore: improve node incompatibility warning
44 changes: 44 additions & 0 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,50 @@ Supported fuel-core version: ${mock.supportedVersion}.`
);
});

it('should ensure fuel node version warning is shown before chain incompatibility error', async () => {
const { FUEL_CORE } = versions;
const [major, minor, patch] = FUEL_CORE.split('.');
const majorMismatch = major === '0' ? 1 : parseInt(patch, 10) - 1;

const mock = {
isMajorSupported: false,
isMinorSupported: true,
isPatchSupported: true,
supportedVersion: `${majorMismatch}.${minor}.${patch}`,
};

if (mock.supportedVersion === FUEL_CORE) {
throw new Error();
}

const spy = vi.spyOn(fuelTsVersionsMod, 'checkFuelCoreVersionCompatibility');
spy.mockImplementationOnce(() => mock);

const consoleWarnSpy = vi.spyOn(console, 'warn');

const graphQLDummyError = `Unknown field "height" on type "Block".
Unknown field "version" on type "ScriptParameters".
Unknown field "version" on type "ConsensusParameters".`;

const fuelError = new FuelError(ErrorCode.INVALID_REQUEST, graphQLDummyError);

const fetchChainSpy = vi
.spyOn(Provider.prototype, 'fetchChain')
.mockImplementationOnce(async () => Promise.reject(fuelError));

await expectToThrowFuelError(() => setupTestProviderAndWallets(), fuelError);

expect(consoleWarnSpy).toHaveBeenCalledOnce();
expect(consoleWarnSpy).toHaveBeenCalledWith(
`The Fuel Node that you are trying to connect to is using fuel-core version ${FUEL_CORE},
which is not supported by the version of the TS SDK that you are using.
Things may not work as expected.
Supported fuel-core version: ${mock.supportedVersion}.`
);

expect(fetchChainSpy).toHaveBeenCalledOnce();
});

it('An invalid subscription request throws a FuelError and does not hold the test runner (closes all handles)', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;
Expand Down
3 changes: 1 addition & 2 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,9 @@ export default class Provider {
* @returns A promise that resolves to the Chain and NodeInfo.
*/
async fetchChainAndNodeInfo() {
const chain = await this.fetchChain();
const nodeInfo = await this.fetchNode();

Provider.ensureClientVersionIsSupported(nodeInfo);
const chain = await this.fetchChain();

return {
chain,
Expand Down

0 comments on commit 2be4a5e

Please sign in to comment.