22// needed to access and assert IExecDataProtector's private properties
33import { describe , expect , it } from '@jest/globals' ;
44import { Wallet } from 'ethers' ;
5- import { IExecWeb3telegram } from '../../src/index.js' ;
5+ import { getWeb3Provider , IExecWeb3telegram } from '../../src/index.js' ;
66import {
77 getTestWeb3SignerProvider ,
88 MAX_EXPECTED_WEB2_SERVICES_TIME ,
99} from '../test-utils.js' ;
10- import { CHAIN_CONFIG , CHAIN_IDS } from '../../src/config/config.js' ;
10+ import {
11+ DEFAULT_CHAIN_ID ,
12+ getChainDefaultConfig ,
13+ } from '../../src/config/config.js' ;
1114
1215describe ( 'IExecWeb3telegram()' , ( ) => {
1316 it ( 'instantiates with a valid ethProvider' , async ( ) => {
@@ -25,7 +28,9 @@ describe('IExecWeb3telegram()', () => {
2528 ) ;
2629 await web3telegram . init ( ) ;
2730 const ipfsGateway = web3telegram [ 'ipfsGateway' ] ;
28- expect ( ipfsGateway ) . toStrictEqual ( CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ) ;
31+ const defaultConfig = getChainDefaultConfig ( DEFAULT_CHAIN_ID ) ;
32+ expect ( defaultConfig ) . not . toBeNull ( ) ;
33+ expect ( ipfsGateway ) . toStrictEqual ( defaultConfig ! . ipfsGateway ) ;
2934 } ) ;
3035
3136 it ( 'should use provided ipfs gateway url when ipfsGateway is provided' , async ( ) => {
@@ -48,8 +53,10 @@ describe('IExecWeb3telegram()', () => {
4853 getTestWeb3SignerProvider ( wallet . privateKey )
4954 ) ;
5055 await web3telegram . init ( ) ;
51- const graphQLClientUrl = web3telegram [ 'graphQLClient' ] ;
52- expect ( graphQLClientUrl [ 'url' ] ) . toBe ( CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dataProtectorSubgraph ) ;
56+ const graphQLClient = web3telegram [ 'graphQLClient' ] ;
57+ const defaultConfig = getChainDefaultConfig ( DEFAULT_CHAIN_ID ) ;
58+ expect ( defaultConfig ) . not . toBeNull ( ) ;
59+ expect ( graphQLClient [ 'url' ] ) . toBe ( defaultConfig ! . dataProtectorSubgraph ) ;
5360 } ) ;
5461
5562 it ( 'should use provided data Protector Subgraph URL when subgraphUrl is provided' , async ( ) => {
@@ -102,11 +109,101 @@ describe('IExecWeb3telegram()', () => {
102109 expect ( ipfsNode ) . toStrictEqual ( customIpfsNode ) ;
103110 expect ( ipfsGateway ) . toStrictEqual ( customIpfsGateway ) ;
104111 expect ( dappAddressOrENS ) . toStrictEqual ( customDapp ) ;
105- expect ( whitelistAddress ) . toStrictEqual ( customDappWhitelistAddress . toLowerCase ( ) ) ;
112+ expect ( whitelistAddress ) . toStrictEqual (
113+ customDappWhitelistAddress . toLowerCase ( )
114+ ) ;
106115 expect ( await iexec . config . resolveSmsURL ( ) ) . toBe ( smsURL ) ;
107116 expect ( await iexec . config . resolveIexecGatewayURL ( ) ) . toBe ( iexecGatewayURL ) ;
108117 } ) ;
109118
119+ describe ( 'When instantiating SDK with an experimental network' , ( ) => {
120+ const experimentalNetworkSigner = getWeb3Provider (
121+ Wallet . createRandom ( ) . privateKey ,
122+ {
123+ host : 421614 ,
124+ allowExperimentalNetworks : true ,
125+ }
126+ ) ;
127+
128+ describe ( 'Without allowExperimentalNetworks' , ( ) => {
129+ it ( 'should throw a configuration error' , async ( ) => {
130+ const web3telegram = new IExecWeb3telegram ( experimentalNetworkSigner ) ;
131+ await expect ( web3telegram . init ( ) ) . rejects . toThrow (
132+ 'Missing required configuration for chainId 421614: dataProtectorSubgraph, dappAddress, whitelistSmartContract, ipfsGateway, prodWorkerpoolAddress, ipfsUploadUrl'
133+ ) ;
134+ } ) ;
135+ } ) ;
136+
137+ describe ( 'With allowExperimentalNetworks: true' , ( ) => {
138+ it ( 'should resolve the configuration' , async ( ) => {
139+ const web3telegram = new IExecWeb3telegram ( experimentalNetworkSigner , {
140+ allowExperimentalNetworks : true ,
141+ } ) ;
142+ await expect ( web3telegram . init ( ) ) . resolves . toBeUndefined ( ) ;
143+ expect ( web3telegram ) . toBeInstanceOf ( IExecWeb3telegram ) ;
144+ } ) ;
145+
146+ it ( 'should use Arbitrum Sepolia default configuration' , async ( ) => {
147+ const web3telegram = new IExecWeb3telegram ( experimentalNetworkSigner , {
148+ allowExperimentalNetworks : true ,
149+ } ) ;
150+ await web3telegram . init ( ) ;
151+
152+ const arbitrumSepoliaConfig = getChainDefaultConfig ( 421614 , {
153+ allowExperimentalNetworks : true ,
154+ } ) ;
155+ expect ( arbitrumSepoliaConfig ) . not . toBeNull ( ) ;
156+
157+ expect ( web3telegram [ 'ipfsGateway' ] ) . toBe (
158+ arbitrumSepoliaConfig ! . ipfsGateway
159+ ) ;
160+ expect ( web3telegram [ 'ipfsNode' ] ) . toBe ( arbitrumSepoliaConfig ! . ipfsUploadUrl ) ;
161+ expect ( web3telegram [ 'dappAddressOrENS' ] ) . toBe (
162+ arbitrumSepoliaConfig ! . dappAddress
163+ ) ;
164+ expect ( web3telegram [ 'dappWhitelistAddress' ] ) . toBe (
165+ arbitrumSepoliaConfig ! . whitelistSmartContract . toLowerCase ( )
166+ ) ;
167+ expect ( web3telegram [ 'defaultWorkerpool' ] ) . toBe (
168+ arbitrumSepoliaConfig ! . prodWorkerpoolAddress
169+ ) ;
170+ expect ( web3telegram [ 'graphQLClient' ] [ 'url' ] ) . toBe (
171+ arbitrumSepoliaConfig ! . dataProtectorSubgraph
172+ ) ;
173+ } ) ;
174+
175+ it ( 'should allow custom configuration override for Arbitrum Sepolia' , async ( ) => {
176+ const customIpfsGateway = 'https://custom-arbitrum-ipfs.com' ;
177+ const customDappAddress = 'custom.arbitrum.app.eth' ;
178+
179+ const web3telegram = new IExecWeb3telegram ( experimentalNetworkSigner , {
180+ allowExperimentalNetworks : true ,
181+ ipfsGateway : customIpfsGateway ,
182+ dappAddressOrENS : customDappAddress ,
183+ } ) ;
184+ await web3telegram . init ( ) ;
185+
186+ expect ( web3telegram [ 'ipfsGateway' ] ) . toBe ( customIpfsGateway ) ;
187+ expect ( web3telegram [ 'dappAddressOrENS' ] ) . toBe ( customDappAddress ) ;
188+
189+ const arbitrumSepoliaConfig = getChainDefaultConfig ( 421614 , {
190+ allowExperimentalNetworks : true ,
191+ } ) ;
192+ expect ( arbitrumSepoliaConfig ) . not . toBeNull ( ) ;
193+ expect ( web3telegram [ 'ipfsNode' ] ) . toBe ( arbitrumSepoliaConfig ! . ipfsUploadUrl ) ;
194+ expect ( web3telegram [ 'dappWhitelistAddress' ] ) . toBe (
195+ arbitrumSepoliaConfig ! . whitelistSmartContract . toLowerCase ( )
196+ ) ;
197+ expect ( web3telegram [ 'defaultWorkerpool' ] ) . toBe (
198+ arbitrumSepoliaConfig ! . prodWorkerpoolAddress
199+ ) ;
200+ expect ( web3telegram [ 'graphQLClient' ] [ 'url' ] ) . toBe (
201+ arbitrumSepoliaConfig ! . dataProtectorSubgraph
202+ ) ;
203+ } ) ;
204+ } ) ;
205+ } ) ;
206+
110207 it (
111208 'When calling a read method should work as expected' ,
112209 async ( ) => {
0 commit comments