Skip to content

Commit 62da0dc

Browse files
feat(sdk): add experimental networks (#456)
* feat: add allowExperimentalNetworks option and arbitrum-sepolia-testnet * test: experimental networks configuration * test: getWeb3Provider options * test: increase subgraph call timeout for tests in GHA
1 parent d5dcf91 commit 62da0dc

File tree

16 files changed

+186
-45
lines changed

16 files changed

+186
-45
lines changed

packages/sdk/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"debug": "^4.3.4",
6262
"ethers": "^6.13.2",
6363
"graphql-request": "^6.0.0",
64-
"iexec": "^8.14.0",
64+
"iexec": "^8.16.0",
6565
"jszip": "^3.7.1",
6666
"kubo-rpc-client": "^4.1.1",
6767
"magic-bytes.js": "^1.0.15",

packages/sdk/src/config/config.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
export type ChainId = number;
22

33
export interface ChainConfig {
4-
name: string;
5-
dataprotectorContractAddress: string;
6-
sharingContractAddress: string;
7-
subgraphUrl: string;
8-
ipfsGateway: string;
9-
ipfsNode: string;
10-
smsDebugURL: string;
11-
workerpoolAddress: string;
4+
name?: string;
5+
dataprotectorContractAddress?: string;
6+
sharingContractAddress?: string;
7+
subgraphUrl?: string;
8+
ipfsGateway?: string;
9+
ipfsNode?: string;
10+
smsDebugURL?: string;
11+
workerpoolAddress?: string;
12+
isExperimental?: boolean;
1213
}
1314

14-
export const CHAIN_CONFIG: Record<ChainId, ChainConfig> = {
15+
const CHAIN_CONFIG: Record<ChainId, ChainConfig> = {
1516
// Bellecour
1617
134: {
1718
name: 'bellecour',
@@ -24,6 +25,30 @@ export const CHAIN_CONFIG: Record<ChainId, ChainConfig> = {
2425
smsDebugURL: 'https://sms-debug.iex.ec',
2526
workerpoolAddress: 'prod-v8-bellecour.main.pools.iexec.eth',
2627
},
28+
// Arbitrum Sepolia
29+
421614: {
30+
name: 'arbitrum-sepolia-testnet',
31+
dataprotectorContractAddress: '0x2296daeDD3090750a80fFB2D0147669984909ED2',
32+
sharingContractAddress: '0x2485Ed90d4566516298B7D01462df8d1A41E13AE',
33+
subgraphUrl:
34+
'https://thegraph.arbitrum-sepolia-testnet.iex.ec/api/subgraphs/id/5YjRPLtjS6GH6bB4yY55Qg4HzwtRGQ8TaHtGf9UBWWd',
35+
ipfsGateway: 'https://ipfs-gateway.arbitrum-sepolia-testnet.iex.ec',
36+
ipfsNode: 'https://ipfs-upload.arbitrum-sepolia-testnet.iex.ec',
37+
smsDebugURL: 'https://sms.arbitrum-sepolia-testnet.iex.ec', // ⚠️ default SMS is a debug SMS
38+
workerpoolAddress: '0x39c3cdd91a7f1c4ed59108a9da4e79de9a1c1b59',
39+
isExperimental: true,
40+
},
41+
};
42+
43+
export const getChainConfig = (
44+
chainId: ChainId,
45+
options?: { allowExperimentalNetworks?: boolean }
46+
): ChainConfig => {
47+
const config = CHAIN_CONFIG[chainId] || {};
48+
if (config?.isExperimental && !options?.allowExperimentalNetworks) {
49+
return {};
50+
}
51+
return config;
2752
};
2853

2954
export const DEFAULT_CHAIN_ID = 134;

packages/sdk/src/lib/IExecDataProtectorModule.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
22
import { GraphQLClient } from 'graphql-request';
33
import { IExec } from 'iexec';
4-
import { CHAIN_CONFIG, DEFAULT_ARWEAVE_UPLOAD_API } from '../config/config.js';
4+
import {
5+
getChainConfig,
6+
DEFAULT_ARWEAVE_UPLOAD_API,
7+
} from '../config/config.js';
58
import { getChainIdFromProvider } from '../utils/getChainId.js';
69
import {
710
AddressOrENS,
@@ -78,7 +81,9 @@ abstract class IExecDataProtectorModule {
7881

7982
private async resolveConfig(): Promise<IExecDataProtectorResolvedConfig> {
8083
const chainId = await getChainIdFromProvider(this.ethProvider);
81-
const chainDefaultConfig = CHAIN_CONFIG[chainId];
84+
const chainDefaultConfig = getChainConfig(chainId, {
85+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
86+
});
8287

8388
const subgraphUrl =
8489
this.options?.subgraphUrl || chainDefaultConfig?.subgraphUrl;
@@ -122,6 +127,7 @@ abstract class IExecDataProtectorModule {
122127
{
123128
ipfsGatewayURL: ipfsGateway,
124129
...this.options?.iexecOptions,
130+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
125131
}
126132
);
127133

@@ -131,6 +137,7 @@ abstract class IExecDataProtectorModule {
131137
ipfsGatewayURL: ipfsGateway,
132138
...this.options?.iexecOptions,
133139
smsURL,
140+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
134141
}
135142
);
136143
} catch (e: any) {

packages/sdk/src/lib/types/commonTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export type DataProtectorConfigOptions = {
7070
* If not provided, default iexec options will be used.
7171
*/
7272
iexecOptions?: IExecConfigOptionsExtended;
73+
74+
/**
75+
* if true allows using a provider connected to an experimental networks (default false)
76+
*
77+
* ⚠️ experimental networks are networks on which the iExec's stack is partially deployed, experimental networks can be subject to instabilities or discontinuity. Access is provided without warranties.
78+
*/
79+
allowExperimentalNetworks?: boolean;
7380
};
7481

7582
interface IExecConfigOptionsExtended extends IExecConfigOptions {
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { getSignerFromPrivateKey } from 'iexec/utils';
2+
import { ChainId } from '../config/config.js';
23
import { Web3SignerProvider } from '../lib/types/index.js';
34

4-
export const getWeb3Provider = (privateKey: string): Web3SignerProvider =>
5-
getSignerFromPrivateKey('bellecour', privateKey);
5+
export const getWeb3Provider = (
6+
privateKey: string,
7+
options: { allowExperimentalNetworks?: boolean; host?: ChainId | string } = {}
8+
): Web3SignerProvider => {
9+
const chainHost = options?.host ? `${options.host}` : 'bellecour';
10+
return getSignerFromPrivateKey(chainHost, privateKey, {
11+
allowExperimentalNetworks: options?.allowExperimentalNetworks,
12+
providers: {},
13+
});
14+
};

packages/sdk/tests/e2e/dataProtectorSharing/addAppToAppWhitelist.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HDNodeWallet, Wallet } from 'ethers';
22
import { Address, IExec } from 'iexec';
33
import { ValidationError } from 'yup';
4-
import { CHAIN_CONFIG } from '../../../src/config/config.js';
4+
import { getChainConfig } from '../../../src/config/config.js';
55
import { IExecDataProtector } from '../../../src/index.js';
66
import {
77
getTestConfig,
@@ -38,7 +38,7 @@ describe('dataProtector.addAppToAddOnlyAppWhitelist()', () => {
3838
appWhitelistAddress = createAppWhitelistResponse.addOnlyAppWhitelist;
3939
appAddress = await createAppFor(
4040
wallet,
41-
CHAIN_CONFIG['134'].sharingContractAddress
41+
getChainConfig(134).sharingContractAddress
4242
);
4343
}, timeouts.createAddOnlyAppWhitelist + timeouts.createAppInPocoRegistry);
4444

packages/sdk/tests/e2e/dataProtectorSharing/addToCollection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeAll, describe, expect, it, jest } from '@jest/globals';
22
import { type HDNodeWallet, Wallet } from 'ethers';
33
import { IExec } from 'iexec';
4-
import { CHAIN_CONFIG } from '../../../src/config/config.js';
4+
import { getChainConfig } from '../../../src/config/config.js';
55
import { IExecDataProtector } from '../../../src/index.js';
66
import { approveProtectedDataForCollectionContract } from '../../../src/lib/dataProtectorSharing/smartContract/approveProtectedDataForCollectionContract.js';
77
import { getTestConfig, timeouts } from '../../test-utils.js';
@@ -76,7 +76,7 @@ describe('dataProtector.addToCollection()', () => {
7676
await approveProtectedDataForCollectionContract({
7777
iexec,
7878
protectedData,
79-
sharingContractAddress: CHAIN_CONFIG['134'].sharingContractAddress,
79+
sharingContractAddress: getChainConfig(134).sharingContractAddress,
8080
});
8181

8282
// --- WHEN

packages/sdk/tests/e2e/dataProtectorSharing/buyProtectedData.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeAll, describe, expect, it } from '@jest/globals';
22
import { Wallet, type HDNodeWallet } from 'ethers';
33
import { ValidationError } from 'yup';
4-
import { CHAIN_CONFIG } from '../../../src/config/config.js';
4+
import { getChainConfig } from '../../../src/config/config.js';
55
import { IExecDataProtector } from '../../../src/index.js';
66
import {
77
approveAccount,
@@ -104,7 +104,7 @@ describe('dataProtector.buyProtectedData()', () => {
104104
await depositNRlcForAccount(buyer.address, price);
105105
await approveAccount(
106106
buyer.privateKey,
107-
CHAIN_CONFIG['134'].sharingContractAddress,
107+
getChainConfig(134).sharingContractAddress,
108108
price
109109
);
110110

packages/sdk/tests/e2e/dataProtectorSharing/rentProtectedData.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { beforeAll, describe, expect, it } from '@jest/globals';
22
import { HDNodeWallet, Wallet } from 'ethers';
3-
import { CHAIN_CONFIG } from '../../../src/config/config.js';
3+
import { getChainConfig } from '../../../src/config/config.js';
44
import { IExecDataProtector } from '../../../src/index.js';
55
import {
66
approveAccount,
@@ -154,7 +154,7 @@ describe('dataProtector.rentProtectedData()', () => {
154154
);
155155
await approveAccount(
156156
walletEndUser.privateKey,
157-
CHAIN_CONFIG['134'].sharingContractAddress,
157+
getChainConfig(134).sharingContractAddress,
158158
rentingParams.price
159159
);
160160

0 commit comments

Comments
 (0)