diff --git a/.github/workflows/sdk-ci.yml b/.github/workflows/sdk-ci.yml new file mode 100644 index 000000000..6d911d0a0 --- /dev/null +++ b/.github/workflows/sdk-ci.yml @@ -0,0 +1,97 @@ +name: dataprotector SDK - CI + +on: + pull_request: + branches: + - '*' + paths: + - 'packages/sdk/**' + # also trigger sdk tests when subgraph is modified to ensure backward compatibility + - 'packages/subgraph/**' + +concurrency: + group: ${{ github.ref }}-sdk-ci + cancel-in-progress: true + +jobs: + check-code: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: packages/sdk/package-lock.json + + - name: Install Dependencies + working-directory: packages/sdk + run: npm ci && npm run codegen + + - name: Lint + working-directory: packages/sdk + run: npm run lint + + - name: Check formatting + working-directory: packages/sdk + run: npm run check-format + + - name: Check types + working-directory: packages/sdk + run: npm run check-types + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: packages/sdk/package-lock.json + + - name: Install Dependencies + working-directory: packages/sdk + run: npm ci && npm run codegen + + - name: Test unit + working-directory: packages/sdk + run: npm run test:unit + + - name: Start e2e test stack + working-directory: packages/sdk + run: npm run start-test-stack + + - name: Test e2e + working-directory: packages/sdk + run: npm run test:e2e + + - name: Stop e2e test stack + working-directory: packages/sdk + if: always() + run: npm run stop-test-stack + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: packages/sdk/package-lock.json + + - name: Install Dependencies + working-directory: packages/sdk + run: npm ci && npm run codegen + + - name: Build + working-directory: packages/sdk + run: npm run build + + - name: publish dry-run + working-directory: packages/sdk + run: npm publish --dry-run diff --git a/packages/sdk/.drone.yml b/packages/sdk/.drone.yml deleted file mode 100644 index e7dc682e4..000000000 --- a/packages/sdk/.drone.yml +++ /dev/null @@ -1,384 +0,0 @@ -###################### SDK DRONE CI ###################### -kind: pipeline -type: docker -name: sdk-default - -trigger: - event: push - -steps: - - name: install - image: node:18.19 - pull: always - commands: - - node -v - - npm -v - - cd packages/sdk - - npm ci - - npm run codegen - - - name: format - image: node:18.19 - commands: - - cd packages/sdk - - npm run check-format - depends_on: - - install - - - name: lint - image: node:18.19 - commands: - - cd packages/sdk - - npm run lint - depends_on: - - format - - - name: check-types - image: node:18.19 - commands: - - cd packages/sdk - - npm run check-types - depends_on: - - lint - - - name: test:unit - image: node:18.19 - commands: - - cd packages/sdk - - npm run test:unit - depends_on: - - check-types - - ##### START LOCAL STACK ##### - - name: prepare-local-stack-env - image: node - commands: - - node packages/sdk/tests/prepare-test-env.js - depends_on: - - test:unit - - - name: bellecour-fork - detach: true - image: ghcr.io/foundry-rs/foundry:v1.0.0 - pull: always - expose: - - 8545 - commands: - - anvil --host 0.0.0.0 --port 8545 --block-time 1 --hardfork berlin --fork-url $(cat local-stack-env/BELLECOUR_FORK_URL) --fork-block-number $(cat local-stack-env/BELLECOUR_FORK_BLOCK) --chain-id 134 --gas-limit 6700000 --gas-price 0 - depends_on: - - prepare-local-stack-env - - - name: bellecour-fork-healthy - image: bash - commands: - - while ! nc -z bellecour-fork 8545 ; do sleep 1 ; done && echo "bellecour-fork ready" - depends_on: - - bellecour-fork - - - name: ipfs - image: ipfs/go-ipfs:v0.9.1 - detach: true - expose: - - 8080 - - 5001 - depends_on: - - test:unit - - - name: ipfs-healthy - image: bash - commands: - - while ! nc -z ipfs 8080 ; do sleep 1 ; done && echo "ipfs gateway ready" - - while ! nc -z ipfs 5001 ; do sleep 1 ; done && echo "ipfs upload ready" - depends_on: - - ipfs - - - name: market-mongo - image: mongo:6.0.3 - detach: true - expose: - - 27017 - depends_on: - - test:unit - - - name: market-mongo-healthy - image: bash - commands: - - while ! nc -z market-mongo 27017 ; do sleep 1 ; done && echo "market-mongo ready" - depends_on: - - market-mongo - - - name: market-redis - image: redis:7.0.7-alpine - detach: true - commands: - - redis-server --appendonly yes - expose: - - 6379 - depends_on: - - test:unit - - - name: market-redis-healthy - image: bash - commands: - - while ! nc -z market-redis 6379 ; do sleep 1 ; done && echo "market-redis ready" - depends_on: - - market-redis - - - name: result-proxy-mongo - image: library/mongo:4.2 - detach: true - commands: - - mongod --bind_ip_all --port 13202 - expose: - - 13202 - depends_on: - - test:unit - - - name: result-proxy-mongo-healthy - image: bash - commands: - - while ! nc -z result-proxy-mongo 13202 ; do sleep 1 ; done && echo "result-proxy-mongo ready" - depends_on: - - result-proxy-mongo - - - name: graphnode-postgres - image: postgres:12 - detach: true - commands: - - docker-entrypoint.sh postgres -cshared_preload_libraries=pg_stat_statements - expose: - - 5432 - environment: - POSTGRES_USER: graphnode - POSTGRES_PASSWORD: password - POSTGRES_DB: graphnode-db - PGDATA: '/var/lib/postgresql/data' - POSTGRES_INITDB_ARGS: '-E UTF8 --locale=C' - depends_on: - - test:unit - - - name: graphnode-postgres-healthy - image: bash - commands: - - while ! nc -z graphnode-postgres 5432 ; do sleep 1 ; done && echo "graphnode-postgres ready" - depends_on: - - graphnode-postgres - - - name: graphnode - image: graphprotocol/graph-node:v0.34.1 - detach: true - expose: - - 8000 - - 8020 - environment: - postgres_host: graphnode-postgres - postgres_port: 5432 - postgres_user: graphnode - postgres_pass: password - postgres_db: graphnode-db - ipfs: ipfs:5001 - ethereum: bellecour:http://bellecour-fork:8545 - commands: - - export GRAPH_ETHEREUM_GENESIS_BLOCK_NUMBER=$(cat local-stack-env/BELLECOUR_FORK_BLOCK) - - cat local-stack-env/BELLECOUR_FORK_BLOCK - - start - depends_on: - - prepare-local-stack-env - - bellecour-fork-healthy - - ipfs-healthy - - graphnode-postgres-healthy - - - name: graphnode-healthy - image: bash - commands: - - while ! nc -z graphnode 8020 ; do sleep 1 ; done && echo "graphnode admin ready" - - while ! nc -z graphnode 8000 ; do sleep 1 ; done && echo "graphnode gql ready" - depends_on: - - graphnode - - - name: sms - image: iexechub/iexec-sms:8.7.0 - detach: true - environment: - JAVA_TOOL_OPTIONS: '-Xmx256M' - IEXEC_SMS_BLOCKCHAIN_NODE_ADDRESS: http://bellecour-fork:8545 - IEXEC_HUB_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f' - IEXEC_SMS_TEE_RUNTIME_FRAMEWORK: scone - IEXEC_SMS_IMAGE_LAS_IMAGE: 'las-image' - IEXEC_TEE_WORKER_PRE_COMPUTE_IMAGE: 'pre-compute-image' - IEXEC_TEE_WORKER_PRE_COMPUTE_FINGERPRINT: 'pre-compute-fingerprint' - IEXEC_TEE_WORKER_POST_COMPUTE_IMAGE: 'post-compute-image' - IEXEC_TEE_WORKER_POST_COMPUTE_FINGERPRINT: 'post-compute-fingerprint' - expose: - - 13300 - depends_on: - - bellecour-fork-healthy - - - name: sms-healthy - image: bash - commands: - - while ! nc -z sms 13300 ; do sleep 1 ; done && echo "sms ready" - depends_on: - - sms - - - name: sms-debug - image: iexechub/iexec-sms:8.7.0 - detach: true - environment: - JAVA_TOOL_OPTIONS: '-Xmx256M' - IEXEC_SMS_BLOCKCHAIN_NODE_ADDRESS: http://bellecour-fork:8545 - IEXEC_HUB_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f' - IEXEC_SMS_TEE_RUNTIME_FRAMEWORK: scone - IEXEC_SMS_IMAGE_LAS_IMAGE: 'las-image' - IEXEC_TEE_WORKER_PRE_COMPUTE_IMAGE: 'pre-compute-image' - IEXEC_TEE_WORKER_PRE_COMPUTE_FINGERPRINT: 'pre-compute-fingerprint' - IEXEC_TEE_WORKER_POST_COMPUTE_IMAGE: 'post-compute-image' - IEXEC_TEE_WORKER_POST_COMPUTE_FINGERPRINT: 'post-compute-fingerprint' - expose: - - 13300 - depends_on: - - bellecour-fork-healthy - - - name: sms-debug-healthy - image: bash - commands: - - while ! nc -z sms-debug 13300 ; do sleep 1 ; done && echo "sms-debug ready" - depends_on: - - sms-debug - - - name: result-proxy - image: iexechub/iexec-result-proxy:7.1.0 - detach: true - environment: - IEXEC_PRIVATE_CHAIN_ADDRESS: http://bellecour-fork:8545 - IEXEC_PUBLIC_CHAIN_ADDRESS: http://bellecour-fork:8545 - IEXEC_HUB_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f' - MONGO_HOST: result-proxy-mongo - MONGO_PORT: 13202 - IEXEC_IPFS_HOST: ipfs - expose: - - 13200 - depends_on: - - bellecour-fork-healthy - - ipfs-healthy - - result-proxy-mongo-healthy - - - name: result-proxy-healthy - image: bash - commands: - - while ! nc -z result-proxy 13200 ; do sleep 1 ; done && echo "result-proxy ready" - depends_on: - - result-proxy - - - name: market-watcher - image: iexechub/iexec-market-watcher:6.4 - detach: true - environment: - CHAIN: BELLECOUR - ETH_WS_HOST: ws://bellecour-fork:8545 - ETH_RPC_HOST: http://bellecour-fork:8545 - MONGO_HOST: market-mongo - REDIS_HOST: market-redis - commands: - - export START_BLOCK=$(cat local-stack-env/BELLECOUR_FORK_BLOCK) - - cd /app - - npm start - depends_on: - - prepare-local-stack-env - - bellecour-fork-healthy - - market-redis-healthy - - market-mongo-healthy - - - name: market-api - image: iexechub/iexec-market-api:6.4 - detach: true - expose: - - 3000 - environment: - CHAINS: BELLECOUR_FORK - BELLECOUR_FORK_ETH_RPC_HOST: http://bellecour-fork:8545 - BELLECOUR_FORK_CHAIN_ID: 134 - BELLECOUR_FORK_IS_NATIVE: 'true' - BELLECOUR_FORK_IEXEC_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f' - MONGO_HOST: market-mongo - REDIS_HOST: market-redis - RATE_LIMIT_MAX: 10000 - RATE_LIMIT_PERIOD: 60000 - MAX_OPEN_ORDERS_PER_WALLET: 1000 - depends_on: - - bellecour-fork-healthy - - market-redis-healthy - - market-mongo-healthy - - - name: market-api-healthy - image: bash - commands: - - while ! nc -z market-api 3000 ; do sleep 1 ; done && echo "market-api ready" - depends_on: - - market-api - - market-watcher - - - name: subgraph-install-deps - image: node:18.19 - commands: - - cd packages/subgraph - - npm ci - depends_on: - - test:unit - - - name: subgraph-deploy - image: node:20.18 - environment: - GRAPHNODE_URL: http://graphnode:8020 - IPFS_URL: http://ipfs:5001 - ENV: prod - commands: - - export START_BLOCK=$(cat local-stack-env/BELLECOUR_FORK_BLOCK) - - cd packages/subgraph - - npm run all - depends_on: - - prepare-local-stack-env - - subgraph-install-deps - - ipfs-healthy - - graphnode-healthy - - - name: stack-ready - image: bash - commands: - - echo "all services ready" - depends_on: - - bellecour-fork-healthy - - sms-healthy - - sms-debug-healthy - - result-proxy-healthy - - market-api-healthy - - ipfs-healthy - - graphnode-healthy - - subgraph-deploy - - ### START LOCAL STACK END ### - - - name: test:e2e - image: node:18.19 - commands: - - cd packages/sdk - - npm run test:e2e - depends_on: - - install - - stack-ready - - - name: build - image: node:18.19 - commands: - - cd packages/sdk - - npm run build - depends_on: - - test:e2e - - - name: npm publish dry-run - image: node:18.19 - commands: - - cd packages/sdk - - npm publish --dry-run - depends_on: - - build diff --git a/packages/sdk/tests/prepare-test-env.js b/packages/sdk/tests/prepare-test-env.js index b27d62280..7cdb445ba 100644 --- a/packages/sdk/tests/prepare-test-env.js +++ b/packages/sdk/tests/prepare-test-env.js @@ -1,7 +1,6 @@ -import { mkdirSync, writeFileSync } from 'fs'; -import { join } from 'path'; +import { writeFileSync } from 'fs'; -const forkUrl = process.env.BELLECOUR_FORK_URL || 'https://bellecour.iex.ec'; +const forkUrl = 'https://bellecour.iex.ec'; fetch(forkUrl, { method: 'POST', @@ -15,22 +14,11 @@ fetch(forkUrl, { .then((res) => res.json()) .then((jsonRes) => { const forkBlockNumber = parseInt(jsonRes.result.substring(2), 16); - if (process.env.DRONE) { - const LOCAL_STACK_ENV_DIR = 'local-stack-env'; - console.log( - `Creating ${LOCAL_STACK_ENV_DIR} directory for drone test-stack` - ); - mkdirSync(LOCAL_STACK_ENV_DIR, { recursive: true }); - writeFileSync(join(LOCAL_STACK_ENV_DIR, 'BELLECOUR_FORK_URL'), forkUrl); - writeFileSync( - join(LOCAL_STACK_ENV_DIR, 'BELLECOUR_FORK_BLOCK'), - `${forkBlockNumber}` - ); - } else { - console.log('Creating .env file for docker-compose test-stack'); - writeFileSync( - '.env', - `############ THIS FILE IS GENERATED ############ + + console.log('Creating .env file for docker-compose test-stack'); + writeFileSync( + '.env', + `############ THIS FILE IS GENERATED ############ # run "node prepare-test-env.js" to regenerate # ################################################ @@ -38,8 +26,7 @@ fetch(forkUrl, { BELLECOUR_FORK_URL=${forkUrl} # block number to fork from BELLECOUR_FORK_BLOCK=${forkBlockNumber}` - ); - } + ); }) .catch((e) => { throw Error(`Failed to get current block number from ${forkUrl}: ${e}`); diff --git a/packages/sdk/tests/test-utils.ts b/packages/sdk/tests/test-utils.ts index 2fd9e4b3f..3446dd09a 100644 --- a/packages/sdk/tests/test-utils.ts +++ b/packages/sdk/tests/test-utils.ts @@ -8,20 +8,14 @@ import { import { getWeb3Provider } from '../src/utils/getWeb3Provider.js'; import { WAIT_FOR_SUBGRAPH_INDEXING } from './utils/waitForSubgraphIndexing.js'; -const { DRONE } = process.env; - const TEST_CHAIN = { - rpcURL: DRONE ? 'http://bellecour-fork:8545' : 'http://localhost:8545', + rpcURL: 'http://localhost:8545', chainId: '134', - smsURL: DRONE ? 'http://sms:13300' : 'http://127.0.0.1:13300', - smsDebugURL: DRONE ? 'http://sms-debug:13300' : 'http://127.0.0.1:13301', - resultProxyURL: DRONE - ? 'http://result-proxy:13200' - : 'http://127.0.0.1:13200', // TODO remove - iexecGatewayURL: DRONE ? 'http://market-api:3000' : 'http://127.0.0.1:3000', - provider: new JsonRpcProvider( - DRONE ? 'http://bellecour-fork:8545' : 'http://localhost:8545' - ), + smsURL: 'http://127.0.0.1:13300', + smsDebugURL: 'http://127.0.0.1:13301', + resultProxyURL: 'http://127.0.0.1:13200', // TODO remove + iexecGatewayURL: 'http://127.0.0.1:3000', + provider: new JsonRpcProvider('http://localhost:8545'), }; export const getTestWeb3SignerProvider = ( @@ -46,13 +40,10 @@ export const getTestConfig = ( : undefined; const options = { iexecOptions: getTestIExecOption(), - ipfsGateway: process.env.DRONE - ? 'http://ipfs:8080' - : 'http://127.0.0.1:8080', - ipfsNode: process.env.DRONE ? 'http://ipfs:5001' : 'http://127.0.0.1:5001', - subgraphUrl: process.env.DRONE - ? 'http://graphnode:8000/subgraphs/name/bellecour/dataprotector-v2' - : 'http://127.0.0.1:8000/subgraphs/name/bellecour/dataprotector-v2', + ipfsGateway: 'http://127.0.0.1:8080', + ipfsNode: 'http://127.0.0.1:5001', + subgraphUrl: + 'http://127.0.0.1:8000/subgraphs/name/bellecour/dataprotector-v2', }; return [ethProvider, options]; };