Skip to content

Commit 7ee2bfa

Browse files
authored
ci: run tests with fdp-play (#1056)
* ci: run tests with fdp-play * test: fix some long waiting times * test: fix some long waiting times * test: fix some long waiting times * ci: run tests with bee-version matrix * chore: increase attempts for warm up waits * ci: change warmup check * chore: revert * test: add detectOpenHandles * ci: stake bzz before running tests * ci: deposit to chequebook before running tests * ci: skip staking * ci: skip staking * test: adjust native token balance range
1 parent 7b41f23 commit 7ee2bfa

File tree

15 files changed

+87
-72
lines changed

15 files changed

+87
-72
lines changed

.github/workflows/tests.yaml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,49 @@ on:
88
branches:
99
- '**'
1010

11-
env:
12-
BEE_API_URL: 'http://127.0.0.1:1633'
13-
BEE_PEER_API_URL: 'http://127.0.0.1:11633'
14-
BEE_TEST_CHEQUEBOOK: true
15-
1611
jobs:
1712
nodejs:
1813
runs-on: ubuntu-latest
1914

20-
strategy:
21-
matrix:
22-
node-version: [18.x]
23-
2415
steps:
2516
- name: Checkout
26-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
2718
with:
2819
fetch-depth: 1
2920

30-
- name: Use Node.js ${{ matrix.node-version }}
31-
uses: actions/setup-node@v3
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
3223
with:
33-
node-version: ${{ matrix.node-version }}
24+
node-version: 20.x
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Install fdp-play
30+
run: npm install --global @fairdatasociety/fdp-play
3431

35-
- name: Install npm deps
36-
run: npm install -g npm && npm ci && npm install -g @fairdatasociety/fdp-play
32+
- name: Install swarm-cli
33+
run: npm install --global @ethersphere/swarm-cli
3734

3835
- name: Start fdp-play environment
39-
run: npm run bee
36+
run: fdp-play start --detach --fresh --bee-version 2.6.0 --workers 1
37+
38+
- name: Stake
39+
if: false
40+
run: swarm-cli stake deposit --bzz 10.1 --yes
41+
42+
- name: Deposit to chequebook
43+
run: swarm-cli cheque deposit 1000000000000000
44+
45+
- name: Create managed postage batch
46+
run: echo "JEST_MANAGED_BATCH_ID=$(swarm-cli stamp buy --depth 20 --amount 1b --quiet)" >> $GITHUB_ENV
47+
48+
- name: Create external postage batch
49+
run: echo "JEST_EXTERNAL_BATCH_ID=$(swarm-cli stamp buy --depth 20 --amount 1b --quiet)" >> $GITHUB_ENV
4050

4151
- name: Tests
42-
run: npm run test
52+
env:
53+
JEST_BEE_URL: http://localhost:1633
54+
JEST_BEE_SIGNER: '566058308ad5fa3888173c741a1fb902c9f1f19559b11fc2738dfc53637ce4e9'
55+
JEST_WITHDRAW_ADDRESS: '0x0000000000000000000000000000000000000000'
56+
run: npm test

jest.config.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55
import type { Config } from '@jest/types'
66

7-
import { Dates, Types } from 'cafe-utility'
7+
import { Assertions, Dates, System, Types } from 'cafe-utility'
8+
import { Bee } from './src'
89

910
export default async (): Promise<Config.InitialOptions> => {
1011
Types.asString(process.env.JEST_BEE_URL, { name: 'JEST_BEE_URL' })
@@ -13,6 +14,19 @@ export default async (): Promise<Config.InitialOptions> => {
1314
Types.asHexString(process.env.JEST_EXTERNAL_BATCH_ID, { name: 'JEST_EXTERNAL_BATCH_ID', byteLength: 32 })
1415
Types.asString(process.env.JEST_WITHDRAW_ADDRESS, { name: 'JEST_WITHDRAW_ADDRESS' })
1516

17+
const bee = new Bee(Types.asString(process.env.JEST_BEE_URL))
18+
19+
console.log(`Connecting to Bee at ${bee.url}...`)
20+
Assertions.asTrue(await bee.isConnected())
21+
22+
console.log('Waiting for Bee to warm up...')
23+
await System.waitFor(async () => (await bee.getStatus()).isWarmingUp === false, {
24+
attempts: 30,
25+
waitMillis: Dates.seconds(1),
26+
})
27+
28+
console.log('Bee is ready!')
29+
1630
return {
1731
collectCoverage: true,
1832
coverageDirectory: 'coverage',
@@ -29,7 +43,7 @@ export default async (): Promise<Config.InitialOptions> => {
2943
] as unknown[] as string[],
3044
rootDir: 'test',
3145
testPathIgnorePatterns: ['/node_modules/'],
32-
testTimeout: Dates.minutes(5),
46+
testTimeout: Dates.minutes(4),
3347
verbose: true,
3448
}
3549
}

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@
5555
"build:node": "tsc -p tsconfig.json && tsc -p tsconfig-mjs.json && ./build-fixup && babel --plugins \"babel-plugin-add-import-extension\" --out-dir dist/mjs/ dist/mjs/",
5656
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
5757
"build:browser": "webpack --progress",
58-
"test": "jest --config=jest.config.ts --runInBand --verbose",
58+
"test": "jest --config=jest.config.ts --runInBand --verbose --forceExit",
5959
"check": "tsc --project tsconfig.test.json",
6060
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
6161
"depcheck": "depcheck ."
6262
},
6363
"dependencies": {
6464
"axios": "^0.30.0",
65-
"cafe-utility": "^28.1.0",
65+
"cafe-utility": "^31.0.0",
6666
"isomorphic-ws": "^4.0.1",
6767
"semver": "^7.3.5",
6868
"ws": "^8.7.0"

src/bee.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,8 @@ export class Bee {
10421042
for (let i = 0n; i < 0xffffn; i++) {
10431043
const signer = new PrivateKey(Binary.numberToUint256(start + i, 'BE'))
10441044
const socAddress = makeSOCAddress(identifier, signer.publicKey().address())
1045-
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256)
1045+
// TODO: test the significance of the hardcoded 256
1046+
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array())
10461047

10471048
if (actualProximity <= 256 - proximity) {
10481049
return signer

src/utils/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function maybeRunOnRequestHook(options: BeeRequestOptions, requestConfig: AxiosR
7777
if (options.onRequest) {
7878
options.onRequest({
7979
method: requestConfig.method || 'GET',
80-
url: Strings.joinUrl(requestConfig.baseURL as string, requestConfig.url as string),
80+
url: Strings.joinUrl([requestConfig.baseURL as string, requestConfig.url as string]),
8181
headers: { ...requestConfig.headers } as Record<string, string>,
8282
params: requestConfig.params,
8383
})

test/integration/cheque.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ test('deposit/withdraw from chequebook', async () => {
4747

4848
return pendingTransactions.length === 0
4949
},
50-
Dates.seconds(1),
51-
60,
50+
{ attempts: 30, waitMillis: Dates.seconds(1), requiredConsecutivePasses: 3 },
5251
)
5352

5453
await bee.withdrawTokens('1')
@@ -58,7 +57,6 @@ test('deposit/withdraw from chequebook', async () => {
5857

5958
return pendingTransactions.length === 0
6059
},
61-
Dates.seconds(1),
62-
60,
60+
{ attempts: 30, waitMillis: Dates.seconds(1), requiredConsecutivePasses: 3 },
6361
)
6462
})

test/integration/feed.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ test('POST feed (reader)', async () => {
2626

2727
return payload === 'Second update'
2828
},
29-
Dates.seconds(1),
30-
60,
29+
{ attempts: 60, waitMillis: Dates.seconds(1) },
3130
)
3231

3332
// TODO: this is a reference... should it be auto-resolved?
@@ -63,8 +62,7 @@ test('POST feed (manifest)', async () => {
6362

6463
return payload === 'Second update'
6564
},
66-
Dates.seconds(1),
67-
60,
65+
{ attempts: 60, waitMillis: Dates.seconds(1) },
6866
)
6967

7068
expect(await bee.isFeedRetrievable(owner, NULL_TOPIC)).toBe(true)

test/integration/feed.ux.spec.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ test('Feed read/write as payload', async () => {
99
const writer = bee.makeFeedWriter(NULL_TOPIC, privateKey)
1010
writer.uploadPayload(batch(), 'Feed payload', { deferred: false })
1111

12-
await System.waitFor(
13-
async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)),
14-
Dates.seconds(1),
15-
30,
16-
)
12+
await System.waitFor(async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)), {
13+
attempts: 60,
14+
waitMillis: Dates.seconds(1),
15+
})
1716

1817
const explicitIndexReadResult = await writer.downloadPayload({ index: 0 })
1918
expect(explicitIndexReadResult.payload.toUtf8()).toBe('Feed payload')
@@ -31,11 +30,10 @@ test('Feed read/write as reference', async () => {
3130
const writer = bee.makeFeedWriter(NULL_TOPIC, privateKey)
3231
await writer.uploadReference(batch(), uploadResult.reference)
3332

34-
await System.waitFor(
35-
async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)),
36-
Dates.seconds(1),
37-
30,
38-
)
33+
await System.waitFor(async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)), {
34+
attempts: 60,
35+
waitMillis: Dates.seconds(1),
36+
})
3937

4038
const explicitIndexReadResult = await writer.downloadReference({ index: 0, hasTimestamp: true })
4139
expect(explicitIndexReadResult.reference.toHex()).toBe(uploadResult.reference.toHex())
@@ -51,11 +49,10 @@ test('Feed read/write 40 bytes payload', async () => {
5149
const writer = bee.makeFeedWriter(NULL_TOPIC, privateKey)
5250
writer.uploadPayload(batch(), 'This string is exactly 40 bytes in utf-8', { deferred: false })
5351

54-
await System.waitFor(
55-
async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)),
56-
Dates.seconds(1),
57-
30,
58-
)
52+
await System.waitFor(async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)), {
53+
attempts: 60,
54+
waitMillis: Dates.seconds(1),
55+
})
5956

6057
const latestReadResult = await writer.downloadPayload()
6158
expect(latestReadResult.payload.toUtf8()).toBe('This string is exactly 40 bytes in utf-8')
@@ -69,11 +66,10 @@ test('Feed read/write as payload when data does not fit into one chunk', async (
6966
const writer = bee.makeFeedWriter(NULL_TOPIC, privateKey)
7067
writer.uploadPayload(batch(), text, { deferred: false })
7168

72-
await System.waitFor(
73-
async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)),
74-
Dates.seconds(1),
75-
30,
76-
)
69+
await System.waitFor(async () => bee.isFeedRetrievable(writer.owner, writer.topic, FeedIndex.fromBigInt(0n)), {
70+
attempts: 60,
71+
waitMillis: Dates.seconds(1),
72+
})
7773

7874
const latestReadResult = await writer.downloadPayload()
7975
expect(latestReadResult.payload.toUtf8()).toHaveLength(5000)

test/integration/stake.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ test('POST stake', async () => {
3030

3131
return stake.eq(stakePreviously.plus('1'))
3232
},
33-
Dates.seconds(1),
34-
180,
33+
{ attempts: 180, waitMillis: Dates.seconds(1) },
3534
)
3635

3736
transactionId = await bee.depositStake(BZZ.fromPLUR(1n))
@@ -43,7 +42,6 @@ test('POST stake', async () => {
4342

4443
return stake.eq(stakePreviously.plus('2'))
4544
},
46-
Dates.seconds(1),
47-
180,
45+
{ attempts: 180, waitMillis: Dates.seconds(1) },
4846
)
4947
})

0 commit comments

Comments
 (0)