diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a7abbfb1..cbaa1f30 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x, 22.x] + bee-version: ['d0aa8b9-commit'] steps: - name: Checkout @@ -26,19 +26,37 @@ jobs: with: fetch-depth: 1 - - name: Use Node.js ${{ matrix.node-version }} + - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 20.x - - name: Install npm deps - run: npm ci && npm install -g @fairdatasociety/fdp-play + - name: Install dependencies + run: npm ci + + - name: Install fdp-play + run: npm install --global @fairdatasociety/fdp-play + + - name: Install swarm-cli + run: npm install --global @ethersphere/swarm-cli - name: Run bee-dev run: npx bee-dev --port 16337 & - name: Start fdp-play environment - run: npm run bee + run: fdp-play start --detach --fresh --bee-version ${{ matrix.bee-version }} + + - name: Deposit to chequebook + run: | + swarm-cli cheque deposit 100000000000000000 + swarm-cli cheque deposit 100000000000000000 --bee-api-url http://localhost:11633 + swarm-cli cheque deposit 100000000000000000 --bee-api-url http://localhost:21633 + swarm-cli cheque deposit 100000000000000000 --bee-api-url http://localhost:31633 + swarm-cli cheque deposit 100000000000000000 --bee-api-url http://localhost:41633 + + - name: Print swarm-cli status + continue-on-error: true + run: swarm-cli status - name: Tests run: npm run test diff --git a/jest.config.ts b/jest.config.ts index cc2d56a8..e0419161 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -2,7 +2,7 @@ * For a detailed explanation regarding each configuration property and type check, visit: * https://jestjs.io/docs/en/configuration.html */ -import { Bee } from '@ethersphere/bee-js' +import { Bee, BZZ } from '@ethersphere/bee-js' import type { Config } from '@jest/types' import { Dates, System } from 'cafe-utility' import { getPssAddress } from './test/utility/address' @@ -22,13 +22,40 @@ export default async (): Promise => { process.env.TEST_STAMP = (await getOrBuyStamp()).toHex() } - const bee = new Bee('http://localhost:1633') - while (1) { - const topology = await bee.getTopology() - if (topology.depth < 31) { - break + for (let i = 0; i < 5; i++) { + const port = 1633 + i * 10000 + const bee = new Bee(`http://localhost:${port}`) + + const startedAt = Date.now() + console.log('Waiting for Bee node to warm up on port', port) + const { version } = await bee.getHealth() + if (version.includes('2.5') || version.startsWith('2.4')) { + await System.waitFor(async () => (await bee.getTopology()).depth < 31, { + attempts: 300, + waitMillis: Dates.seconds(1), + requiredConsecutivePasses: 3, + }) + } else { + await System.waitFor(async () => (await bee.getStatus()).isWarmingUp === false, { + attempts: 300, + waitMillis: Dates.seconds(1), + requiredConsecutivePasses: 3, + }) + } + const elapsed = Date.now() - startedAt + console.log(`Bee node on port ${port} warmed up in ${elapsed} milliseconds`) + } + + for (let i = 0; i < 5; i++) { + const port = 1633 + i * 10000 + const bee = new Bee(`http://localhost:${port}`) + + console.log('Asserting chequebook balance on port', port) + const chequebookBalance = await bee.getChequebookBalance() + if (!chequebookBalance.totalBalance.eq(BZZ.fromDecimalString('10'))) { + throw Error('Chequebook total balance is not 10 xBZZ: ' + chequebookBalance.totalBalance.toDecimalString()) } - await System.sleepMillis(Dates.seconds(15)) + console.log(`Chequebook balance on port ${port} is 10 xBZZ`) } return { diff --git a/package-lock.json b/package-lock.json index 38cae100..dd10269b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,12 +6,12 @@ "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.33.0", + "version": "2.34.0", "license": "BSD-3-Clause", "dependencies": { "@ethereumjs/wallet": "^2.0.4", - "@ethersphere/bee-js": "^9.6.1", - "cafe-utility": "^27.14.0", + "@ethersphere/bee-js": "^9.7.0", + "cafe-utility": "^31.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", "ethers": "^5.7.2", @@ -1129,9 +1129,9 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-9.6.1.tgz", - "integrity": "sha512-YauFLtjY7ZXiO19HfM9vJaZOBxjKvwRN7dRfzh4FldP78SomK/8T9cT5hagrFJIgHr0MPQxvQRHvUKQifYRlvg==", + "version": "9.7.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-9.7.0.tgz", + "integrity": "sha512-kA03jVgxz01TYAIKWwUQ6ob9I/hzl4XrqO48ZYaivuvMX9n+8WG1FPx+qcCUHSm6L1LBtGJ52WKnrWmdcTKWFw==", "license": "BSD-3-Clause", "dependencies": { "axios": "^0.30.0", @@ -3729,9 +3729,9 @@ } }, "node_modules/cafe-utility": { - "version": "27.14.2", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-27.14.2.tgz", - "integrity": "sha512-/FKZKrfdj46VcinJHvXoIbj3FWTmVEU5Lc83+0Ep08B1O85NMGuCDLRI8CLUCpTb2clvJ0osscPBGEx/Ql1tKQ==", + "version": "31.0.0", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-31.0.0.tgz", + "integrity": "sha512-SBSXCnaYcgoaUxXcMFQkCoIdZuPBzxF2cl3FKxw4HpcDNtfdMQfbNYXZqV3HxP6bu6JOGkak8O93DkKojUC6Ow==", "license": "MIT" }, "node_modules/callsites": { diff --git a/package.json b/package.json index d45a8194..6e23747b 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "start": "ts-node src/index.ts", "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"", - "bee": "npx @fairdatasociety/fdp-play@3.3.0 start --detach --fresh" + "bee": "npx @fairdatasociety/fdp-play@3.3.0 start --detach --fresh --bee-version 2.6.0" }, "engines": { "node": ">=14.0.0", @@ -63,8 +63,8 @@ }, "dependencies": { "@ethereumjs/wallet": "^2.0.4", - "@ethersphere/bee-js": "^9.6.1", - "cafe-utility": "^27.14.0", + "@ethersphere/bee-js": "^9.7.0", + "cafe-utility": "^31.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", "ethers": "^5.7.2", diff --git a/test/command/upload.spec.ts b/test/command/upload.spec.ts index a18e13f4..78273b74 100644 --- a/test/command/upload.spec.ts +++ b/test/command/upload.spec.ts @@ -1,9 +1,21 @@ import { existsSync, unlinkSync, writeFileSync } from 'fs' import { LeafCommand } from 'furious-commander' import type { Upload } from '../../src/command/upload' +import { toMatchLinesInOrder } from '../custom-matcher' import { describeCommand, invokeTestCli } from '../utility' import { getStampOption } from '../utility/stamp' +const SUCCESSFUL_SYNC_PATTERN = [ + ['Data has been sent to the Bee node successfully!'], + ['Waiting for file chunks to be synced on Swarm network...'], + ['Data has been synced on Swarm network'], + ['Uploading was successful!'], +] + +expect.extend({ + toMatchLinesInOrder, +}) + function actUpload(command: { runnable?: LeafCommand | undefined }): [string, string] { const uploadCommand = command.runnable as Upload const ref = uploadCommand.result.getOrThrow().toHex() @@ -132,14 +144,24 @@ describeCommand('Test Upload command', ({ consoleMessages, hasMessageContaining expect(hasMessageContaining('does not support syncing')).toBeTruthy() }) - it('should succeed with --sync', async () => { + it('should succeed with --sync <1MB', async () => { await invokeTestCli(['upload', 'README.md', '--sync', '-v', ...getStampOption()]) - expect(hasMessageContaining('Uploading was successful!')).toBeTruthy() + expect(consoleMessages).toMatchLinesInOrder(SUCCESSFUL_SYNC_PATTERN) }) - it('should succeed with --sync and --encrypt', async () => { + it('should succeed with --sync >1MB', async () => { + await invokeTestCli(['upload', 'docs/stamp-buy.gif', '--sync', '-v', ...getStampOption()]) + expect(consoleMessages).toMatchLinesInOrder(SUCCESSFUL_SYNC_PATTERN) + }) + + it('should succeed with --sync and --encrypt <1MB', async () => { await invokeTestCli(['upload', 'README.md', '--sync', '--encrypt', '-v', ...getStampOption()]) - expect(hasMessageContaining('Uploading was successful!')).toBeTruthy() + expect(consoleMessages).toMatchLinesInOrder(SUCCESSFUL_SYNC_PATTERN) + }) + + it('should succeed with --sync and --encrypt >1MB', async () => { + await invokeTestCli(['upload', 'docs/stamp-buy.gif', '--sync', '--encrypt', '-v', ...getStampOption()]) + expect(consoleMessages).toMatchLinesInOrder(SUCCESSFUL_SYNC_PATTERN) }) it('should not print double trailing slashes', async () => {