Skip to content

Commit 8b15f71

Browse files
test: experimental networks configuration
1 parent fa8a4ba commit 8b15f71

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

packages/sdk/src/utils/getWeb3Provider.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { getSignerFromPrivateKey } from 'iexec/utils';
2-
import { ChainId, getChainConfig } from '../config/config.js';
2+
import { ChainId } from '../config/config.js';
33
import { Web3SignerProvider } from '../lib/types/index.js';
44

55
export const getWeb3Provider = (
66
privateKey: string,
7-
chainId: ChainId = 134,
8-
options?: { allowExperimentalNetworks?: boolean }
7+
options: { allowExperimentalNetworks?: boolean; host?: ChainId | string } = {}
98
): Web3SignerProvider => {
10-
const { name } = getChainConfig(chainId, {
11-
allowExperimentalNetworks: options?.allowExperimentalNetworks,
12-
});
13-
if (!name) {
14-
throw Error('Unsupported Network');
15-
}
16-
return getSignerFromPrivateKey(name, privateKey, {
9+
const chainHost = options?.host ? `${options.host}` : 'bellecour';
10+
return getSignerFromPrivateKey(chainHost, privateKey, {
1711
allowExperimentalNetworks: options?.allowExperimentalNetworks,
1812
providers: {},
1913
});

packages/sdk/tests/unit/constructor.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,43 @@ describe('IExecDataProtector()', () => {
188188
});
189189
});
190190
});
191+
192+
describe('When instantiating SDK with an experimental network', () => {
193+
const experimentalNetworkSigner = getWeb3Provider(
194+
Wallet.createRandom().privateKey,
195+
{
196+
host: 421614,
197+
allowExperimentalNetworks: true,
198+
}
199+
);
200+
201+
describe('Without allowExperimentalNetworks', () => {
202+
it('should throw a configuration error', async () => {
203+
const dataProtector = new IExecDataProtector(experimentalNetworkSigner);
204+
await expect(dataProtector['init']()).rejects.toThrow(
205+
'Missing required configuration for chainId 421614: subgraphUrl, dataprotectorContractAddress, sharingContractAddress, ipfsGateway, defaultWorkerpool, ipfsNode, smsDebugURL'
206+
);
207+
});
208+
});
209+
210+
describe('With allowExperimentalNetworks: true', () => {
211+
it('should resolve the configuration', async () => {
212+
const dataProtector = new IExecDataProtector(
213+
experimentalNetworkSigner,
214+
{ allowExperimentalNetworks: true }
215+
);
216+
await expect(dataProtector['init']()).resolves.toBeUndefined();
217+
expect(dataProtector['arweaveUploadApi']).toBeDefined();
218+
expect(dataProtector['dataprotectorContractAddress']).toBeDefined();
219+
expect(dataProtector['defaultWorkerpool']).toBeDefined();
220+
expect(dataProtector['ethProvider']).toBeDefined();
221+
expect(dataProtector['graphQLClient']).toBeDefined();
222+
expect(dataProtector['iexec']).toBeDefined();
223+
expect(dataProtector['iexecDebug']).toBeDefined();
224+
expect(dataProtector['ipfsGateway']).toBeDefined();
225+
expect(dataProtector['ipfsNode']).toBeDefined();
226+
expect(dataProtector['sharingContractAddress']).toBeDefined();
227+
});
228+
});
229+
});
191230
});

0 commit comments

Comments
 (0)