Skip to content

Commit da9883d

Browse files
ci: update test utilities and scripts for GitHub Actions compatibility
- Update test-utils.ts to remove Drone-specific logic and use localhost URLs - Simplify prepare-test-env.js to only create .env file - Update prepare-bellecour-fork-for-tests.js to work with GitHub Actions - Add sdk-ci.yml workflow for automated testing on push
1 parent c4e2bf5 commit da9883d

File tree

4 files changed

+126
-64
lines changed

4 files changed

+126
-64
lines changed

.github/workflows/sdk-ci.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: web3telegram SDK - CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths:
8+
- 'src/**'
9+
- 'tests/**'
10+
- 'package.json'
11+
- 'package-lock.json'
12+
- 'tsconfig*.json'
13+
- '.eslintrc.json'
14+
- '.prettierrc'
15+
16+
concurrency:
17+
group: ${{ github.ref }}-sdk-ci
18+
cancel-in-progress: true
19+
20+
jobs:
21+
check-code:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 18
29+
cache: 'npm'
30+
31+
- name: Install Dependencies
32+
run: npm ci
33+
34+
- name: Lint
35+
run: npm run lint
36+
37+
- name: Check formatting
38+
run: npm run check-format
39+
40+
- name: Check types
41+
run: npm run check-types
42+
43+
test:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: actions/setup-node@v4
49+
with:
50+
node-version: 18
51+
cache: 'npm'
52+
53+
- name: Install Dependencies
54+
run: npm ci
55+
56+
- name: Test unit
57+
run: npm run test:unit
58+
59+
- name: Start e2e test stack
60+
run: npm run start-test-stack
61+
62+
- name: Test e2e
63+
run: npm run test:e2e
64+
65+
- name: Stop e2e test stack
66+
if: always()
67+
run: npm run stop-test-stack
68+
69+
build:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- uses: actions/setup-node@v4
75+
with:
76+
node-version: 18
77+
cache: 'npm'
78+
79+
- name: Install Dependencies
80+
run: npm ci
81+
82+
- name: Build
83+
run: npm run build
84+
85+
- name: publish dry-run
86+
run: npm publish --dry-run

tests/scripts/prepare-bellecour-fork-for-tests.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
toBeHex,
1010
} from 'ethers';
1111

12-
const { DRONE } = process.env;
13-
1412
const VOUCHER_HUB_ADDRESS = '0x3137B6DF4f36D338b82260eDBB2E7bab034AFEda';
1513
const TARGET_VOUCHER_MANAGER_WALLET =
1614
'0x44cA21A3c4efE9B1A0268e2e9B2547E7d9C8f19C'; // Should be same wallet as TEST_CHAIN.voucherManagerWallet
@@ -24,7 +22,7 @@ const PROD_WORKERPOOL_ENS = 'prod-v8-bellecour.main.pools.iexec.eth';
2422
// TODO change to prod ens when it's available
2523
const WEB3_TELEGRAM_DAPP_ADDRESS_ENS = 'web3telegram.apps.iexec.eth';
2624

27-
const rpcURL = DRONE ? 'http://bellecour-fork:8545' : 'http://127.0.0.1:8545';
25+
const rpcURL = 'http://localhost:8545';
2826

2927
const provider = new JsonRpcProvider(
3028
rpcURL,
@@ -43,7 +41,7 @@ const WEB3_TELEGRAM_DAPP_ADDRESS = await provider.resolveName(
4341
);
4442

4543
const setBalance = async (address, weiAmount) => {
46-
fetch(rpcURL, {
44+
await fetch(rpcURL, {
4745
method: 'POST',
4846
body: JSON.stringify({
4947
method: 'anvil_setBalance',

tests/scripts/prepare-test-env.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { mkdirSync, writeFileSync } from 'fs';
2-
import { join } from 'path';
1+
import { writeFileSync } from 'fs';
32

4-
const forkUrl = process.env.BELLECOUR_FORK_URL || 'https://bellecour.iex.ec';
3+
const forkUrl = 'https://bellecour.iex.ec';
54

65
fetch(forkUrl, {
76
method: 'POST',
@@ -15,31 +14,19 @@ fetch(forkUrl, {
1514
.then((res) => res.json())
1615
.then((jsonRes) => {
1716
const forkBlockNumber = parseInt(jsonRes.result.substring(2), 16);
18-
if (process.env.DRONE) {
19-
const LOCAL_STACK_ENV_DIR = 'local-stack-env';
20-
console.log(
21-
`Creating ${LOCAL_STACK_ENV_DIR} directory for drone test-stack`
22-
);
23-
mkdirSync(LOCAL_STACK_ENV_DIR, { recursive: true });
24-
writeFileSync(join(LOCAL_STACK_ENV_DIR, 'BELLECOUR_FORK_URL'), forkUrl);
25-
writeFileSync(
26-
join(LOCAL_STACK_ENV_DIR, 'BELLECOUR_FORK_BLOCK'),
27-
`${forkBlockNumber}`
28-
);
29-
} else {
30-
console.log('Creating .env file for docker-compose test-stack');
31-
writeFileSync(
32-
'.env',
33-
`############ THIS FILE IS GENERATED ############
17+
18+
console.log('Creating .env file for docker-compose test-stack');
19+
writeFileSync(
20+
'.env',
21+
`############ THIS FILE IS GENERATED ############
3422
# run "node prepare-test-env.js" to regenerate #
3523
################################################
3624
3725
# blockchain node to use as the reference for the local fork
3826
BELLECOUR_FORK_URL=${forkUrl}
3927
# block number to fork from
4028
BELLECOUR_FORK_BLOCK=${forkBlockNumber}`
41-
);
42-
}
29+
);
4330
})
4431
.catch((e) => {
4532
throw Error(`Failed to get current block number from ${forkUrl}: ${e}`);

tests/test-utils.ts

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-nocheck
31
import { Wallet, JsonRpcProvider, ethers, Contract } from 'ethers';
42
import {
5-
Web3SignerProvider,
6-
Web3TelegramConfigOptions,
3+
type Web3TelegramConfigOptions,
4+
type Web3SignerProvider,
75
} from '../src/web3telegram/types.js';
86
import { IExec, utils } from 'iexec';
97
import { randomInt } from 'crypto';
108
import { getSignerFromPrivateKey } from 'iexec/utils';
119

12-
export const TEST_CHAIN = {
13-
rpcURL: process.env.DRONE
14-
? 'http://bellecour-fork:8545'
15-
: 'http://127.0.0.1:8545',
10+
const TEST_CHAIN = {
11+
rpcURL: 'http://localhost:8545',
1612
chainId: '134',
17-
smsURL: process.env.DRONE ? 'http://sms:13300' : 'http://127.0.0.1:13300',
18-
resultProxyURL: process.env.DRONE
19-
? 'http://result-proxy:13200'
20-
: 'http://127.0.0.1:13200',
21-
iexecGatewayURL: process.env.DRONE
22-
? 'http://market-api:3000'
23-
: 'http://127.0.0.1:3000',
13+
smsURL: 'http://127.0.0.1:13300',
14+
smsDebugURL: 'http://127.0.0.1:13301',
15+
resultProxyURL: 'http://127.0.0.1:13200',
16+
iexecGatewayURL: 'http://127.0.0.1:3000',
2417
voucherHubAddress: '0x3137B6DF4f36D338b82260eDBB2E7bab034AFEda',
2518
voucherManagerWallet: new Wallet(
2619
'0x2c906d4022cace2b3ee6c8b596564c26c4dcadddf1e949b769bcb0ad75c40c33'
2720
),
28-
voucherSubgraphURL: process.env.DRONE
29-
? 'http://graphnode:8000/subgraphs/name/bellecour/iexec-voucher'
30-
: 'http://127.0.0.1:8000/subgraphs/name/bellecour/iexec-voucher',
21+
voucherSubgraphURL:
22+
'http://127.0.0.1:8000/subgraphs/name/bellecour/iexec-voucher',
3123
learnProdWorkerpool: 'prod-v8-learn.main.pools.iexec.eth',
3224
learnProdWorkerpoolOwnerWallet: new Wallet(
3325
'0x800e01919eadf36f110f733decb1cc0f82e7941a748e89d7a3f76157f6654bb3'
@@ -39,13 +31,9 @@ export const TEST_CHAIN = {
3931
appOwnerWallet: new Wallet(
4032
'0xa911b93e50f57c156da0b8bff2277d241bcdb9345221a3e246a99c6e7cedcde5'
4133
),
42-
provider: new JsonRpcProvider(
43-
process.env.DRONE ? 'http://bellecour-fork:8545' : 'http://127.0.0.1:8545',
44-
undefined,
45-
{
46-
pollingInterval: 1000, // speed up tests
47-
}
48-
),
34+
provider: new JsonRpcProvider('http://localhost:8545', undefined, {
35+
pollingInterval: 1000, // speed up tests
36+
}),
4937
hubAddress: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f',
5038
};
5139

@@ -80,27 +68,28 @@ export const getTestWeb3SignerProvider = (
8068
): Web3SignerProvider =>
8169
utils.getSignerFromPrivateKey(TEST_CHAIN.rpcURL, privateKey);
8270

71+
export const getTestRpcProvider = () => new JsonRpcProvider(TEST_CHAIN.rpcURL);
72+
8373
export const getTestIExecOption = () => ({
8474
smsURL: TEST_CHAIN.smsURL,
75+
smsDebugURL: TEST_CHAIN.smsDebugURL,
8576
resultProxyURL: TEST_CHAIN.resultProxyURL,
8677
iexecGatewayURL: TEST_CHAIN.iexecGatewayURL,
8778
voucherHubAddress: TEST_CHAIN.voucherHubAddress,
8879
voucherSubgraphURL: TEST_CHAIN.voucherSubgraphURL,
8980
});
9081

9182
export const getTestConfig = (
92-
privateKey: string
83+
privateKey?: string
9384
): [Web3SignerProvider, Web3TelegramConfigOptions] => {
94-
const ethProvider = getTestWeb3SignerProvider(privateKey);
85+
const ethProvider = privateKey
86+
? getTestWeb3SignerProvider(privateKey)
87+
: undefined;
9588
const options = {
9689
iexecOptions: getTestIExecOption(),
97-
ipfsGateway: process.env.DRONE
98-
? 'http://ipfs:8080'
99-
: 'http://127.0.0.1:8080',
100-
ipfsNode: process.env.DRONE ? 'http://ipfs:5001' : 'http://127.0.0.1:5001',
101-
dataProtectorSubgraph: process.env.DRONE
102-
? 'http://graphnode:8000/subgraphs/name/DataProtector-v2'
103-
: 'http://127.0.0.1:8000/subgraphs/name/DataProtector-v2',
90+
ipfsGateway: 'http://127.0.0.1:8080',
91+
ipfsNode: 'http://127.0.0.1:5001',
92+
subgraphUrl: 'http://127.0.0.1:8000/subgraphs/name/bellecour/web3telegram',
10493
};
10594
return [ethProvider, options];
10695
};
@@ -231,7 +220,7 @@ export const createVoucherType = async ({
231220
TEST_CHAIN.voucherHubAddress,
232221
VOUCHER_HUB_ABI,
233222
TEST_CHAIN.provider
234-
);
223+
) as any;
235224
const signer = TEST_CHAIN.voucherManagerWallet.connect(TEST_CHAIN.provider);
236225
const createVoucherTypeTxHash = await voucherHubContract
237226
.connect(signer)
@@ -380,7 +369,7 @@ export const createVoucher = async ({
380369
TEST_CHAIN.voucherHubAddress,
381370
VOUCHER_HUB_ABI,
382371
TEST_CHAIN.provider
383-
);
372+
) as any;
384373

385374
const signer = TEST_CHAIN.voucherManagerWallet.connect(TEST_CHAIN.provider);
386375

@@ -397,7 +386,9 @@ export const createVoucher = async ({
397386

398387
if (!skipOrders) {
399388
try {
400-
const workerpoolprice = Math.floor(value / WORKERPOOL_ORDER_PER_VOUCHER);
389+
const workerpoolprice = Math.floor(
390+
Number(value) / WORKERPOOL_ORDER_PER_VOUCHER
391+
);
401392
await createAndPublishWorkerpoolOrder(
402393
TEST_CHAIN.prodWorkerpool,
403394
TEST_CHAIN.prodWorkerpoolOwnerWallet,
@@ -412,7 +403,7 @@ export const createVoucher = async ({
412403
}
413404

414405
try {
415-
return await voucherHubContract.getVoucher(owner);
406+
return voucherHubContract.getVoucher(owner);
416407
} catch (error) {
417408
console.error('Error getting voucher:', error);
418409
throw error;
@@ -439,7 +430,7 @@ export const addVoucherEligibleAsset = async (assetAddress, voucherTypeId) => {
439430
stateMutability: 'nonpayable',
440431
type: 'function',
441432
},
442-
]);
433+
]) as any;
443434

444435
const signer = TEST_CHAIN.voucherManagerWallet.connect(TEST_CHAIN.provider);
445436

0 commit comments

Comments
 (0)