Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,45 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
bee-version: ['d0aa8b9-commit']

steps:
- name: Checkout
uses: actions/checkout@v2
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
41 changes: 34 additions & 7 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,13 +22,40 @@ export default async (): Promise<Config.InitialOptions> => {
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 {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected] start --detach --fresh"
"bee": "npx @fairdatasociety/[email protected] start --detach --fresh --bee-version 2.6.0"
},
"engines": {
"node": ">=14.0.0",
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 26 additions & 4 deletions test/command/upload.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading