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: provider connect method accept options #1388

Merged
merged 19 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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/khaki-years-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/providers": patch
---

You can now pass in `ProviderOptions` to `Provider.connect`
4 changes: 2 additions & 2 deletions packages/providers/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ export default class Provider {
/**
* Updates the URL for the provider and fetches the consensus parameters for the new URL, if needed.
*/
async connect(url: string) {
async connect(url: string, options?: ProviderOptions) {
this.url = url;
this.operations = this.createOperations(url);
this.operations = this.createOperations(url, options ?? this.options);
await this.fetchChainAndNodeInfo();
}

Expand Down
32 changes: 32 additions & 0 deletions packages/providers/test/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,38 @@ describe('Provider', () => {
const provider = await Provider.create(providerUrl, {
fetch: getCustomFetch('getVersion', { nodeInfo: { nodeVersion: '0.30.0' } }),
});

expect(await provider.getVersion()).toEqual('0.30.0');
});

it('can accept options override in connect method', async () => {
const providerUrl = FUEL_NETWORK_URL;

/**
* Mocking and initializing Provider with an invalid fetcher just
* to ensure it'll be properly overriden in `connect` method below
*/
const fetchChainAndNodeInfo = jest
.spyOn(Provider.prototype, 'fetchChainAndNodeInfo')
.mockImplementation();

const provider = await Provider.create(providerUrl, {
fetch: () => {
throw new Error('This should never happen');
},
});

expect(fetchChainAndNodeInfo).toHaveBeenCalledTimes(1);

/**
* Restore mock and call connect with a proper fetch override
*/
fetchChainAndNodeInfo.mockRestore();

await provider.connect(providerUrl, {
fetch: getCustomFetch('getVersion', { nodeInfo: { nodeVersion: '0.30.0' } }),
});

expect(await provider.getVersion()).toEqual('0.30.0');
});

Expand Down