Skip to content

Commit bf78df6

Browse files
feat(tests): Add tests (#117)
* Basic tests setup * Add ts configs * Update configs * Remove cli dep * Add utils * Run fluence cli * Simplify configs * Quickstart test * Use Tree Kill * Test quickstart for all modes * Wait gateway start * Use sequential runner * Start writing deploy tests * Remove undefined * Tests with local env * Add comments * Use env variables * Wait for workers deploy * Remove bail * Update js-client * Remove log, wait for service * Remove skip * chore: Add tests CI (#130) * fix(aqua): Remove topology hack (#125) * Fix scripts * Remove hack * feat(readme): Add `fluence deal logs` output example to README [DXJ-512] (#126) Add deal logs output to README * Setup fcli with action * Use unstable * Test CI * Fix * Fx * Add colors * Fix * Dump logs * Bump js-client * More logs * Log stdout and stderr * Capture stderr * F * F * F * > * NO COLOR * Setup tmate * Add workers * Run without CI true * Run on builder * Run tmata * Setup rust * No colors * Do not setup tmate * Cleanup --------- Co-authored-by: InversionSpaces <[email protected]> --------- Co-authored-by: Anatolios Laskaris <[email protected]>
1 parent 5269f45 commit bf78df6

16 files changed

+4860
-39
lines changed

Diff for: .github/workflows/tests.yml

+109-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,37 @@ on:
77
description: "git ref to checkout to"
88
type: string
99
default: "main"
10+
nox-image:
11+
description: "nox image tag"
12+
type: string
13+
default: "null"
14+
fcli-version:
15+
description: "fcli version to use"
16+
type: string
17+
# default: "unstable"
18+
default: "main"
19+
js-client-version:
20+
description: "@fluencelabs/js-client version"
21+
type: string
22+
default: "null"
23+
fluence-env:
24+
description: "env to run tests against"
25+
type: string
26+
default: "local"
1027

1128
jobs:
1229
tests:
13-
name: "build"
14-
runs-on: ubuntu-latest
30+
name: "Run tests"
31+
runs-on: builder
32+
33+
env:
34+
FLUENCE_USER_DIR: "${{ github.workspace }}/tmp/.fluence"
35+
CI: true
36+
# FORCE_COLOR: true
37+
38+
permissions:
39+
contents: read
40+
id-token: write
1541

1642
steps:
1743
- name: Checkout repository
@@ -20,11 +46,86 @@ jobs:
2046
repository: fluencelabs/frpc
2147
ref: ${{ inputs.ref }}
2248

23-
- name: Install fluence-cli@unstable
24-
run: npm i -g @fluencelabs/[email protected]
49+
- name: Import secrets
50+
uses: hashicorp/[email protected]
51+
with:
52+
url: https://vault.fluence.dev
53+
path: jwt/github
54+
role: ci
55+
method: jwt
56+
jwtGithubAudience: "https://github.com/fluencelabs"
57+
jwtTtl: 300
58+
secrets: |
59+
kv/docker-registry/basicauth/ci username | DOCKER_USERNAME ;
60+
kv/docker-registry/basicauth/ci password | DOCKER_PASSWORD ;
61+
kv/npm-registry/basicauth/ci token | NODE_AUTH_TOKEN ;
62+
kv/ci/frpc chain_urls | RPC_PROVIDERS ;
63+
kv/ci/frpc private_key | FLUENCE_CHAIN_PRIVATE_KEY
64+
65+
- name: Login to DockerHub
66+
uses: docker/login-action@v2
67+
with:
68+
registry: docker.fluence.dev
69+
username: ${{ env.DOCKER_USERNAME }}
70+
password: ${{ env.DOCKER_PASSWORD }}
71+
72+
- name: Setup Rust toolchain
73+
uses: dsherret/rust-toolchain-file@v1
74+
75+
- name: Setup fcli
76+
uses: fluencelabs/setup-fluence@v1
77+
with:
78+
artifact: fcli
79+
version: ${{ inputs.fcli-version }}
80+
81+
- name: Init local env with fcli
82+
run: fluence local init --no-input
83+
84+
- name: Replace nox image in docker-compose
85+
if: inputs.nox-image != 'null'
86+
working-directory: .fluence
87+
run: |
88+
sed -i'' -e '/nox-/!b;n;s|image: fluencelabs/nox:.*$|image: ${{ inputs.nox-image }}|' docker-compose.yaml
89+
90+
- name: Run local env
91+
run: fluence local up
92+
93+
- name: Setup node with self-hosted registry
94+
uses: actions/setup-node@v3
95+
with:
96+
node-version: "18"
97+
registry-url: "https://npm.fluence.dev"
98+
cache: "npm"
99+
100+
- name: Run npm i
101+
run: npm i
102+
103+
- name: Run npm i in gateway
104+
working-directory: gateway
105+
run: npm i
106+
107+
- name: Set js-client version
108+
if: inputs.js-client-version != 'null'
109+
uses: fluencelabs/github-actions/npm-set-dependency@main
110+
with:
111+
package: "@fluencelabs/js-client"
112+
version: "${{ inputs.js-client-version }}"
113+
working-directory: gateway
114+
115+
- name: Run npm run build
116+
run: npm run build
117+
118+
- name: Run tests
119+
env:
120+
FLUENCE_ENV: ${{ inputs.fluence-env }}
121+
run: npm run test -- -t deploy
25122

26-
- name: Check if main.aqua compiles
27-
run: fluence aqua --dry
123+
- name: Dump container logs
124+
if: always()
125+
uses: jwalton/gh-docker-logs@v2
28126

29-
- name: Check if services builds
30-
run: fluence build
127+
- name: Cleanup
128+
if: always()
129+
run: |
130+
fluence local down
131+
rm -rf tmp ${{ env.FLUENCE_USER_DIR }}

Diff for: .gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ src/js/src/aqua
99
aqua-compiled
1010

1111
# recommended by Fluence Labs:
12-
/.fluence/project-secrets.yaml
13-
/.fluence/schemas
14-
/.fluence/tmp
12+
.fluence/project-secrets.yaml
13+
.fluence/docker-compose.yaml
14+
.fluence/schemas
15+
.fluence/secrets
16+
.fluence/tmp
1517

1618
# to avoid accidental publish of RPC URLs
1719
gateway/configs/quickstart_config.json

Diff for: fluence.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence.md
66

7-
version: 2
7+
version: 4
8+
89
aquaInputPath: src/aqua/main.aqua
10+
911
workers:
1012
defaultWorker:
1113
services: [ eth_rpc ]
14+
1215
deals:
1316
defaultWorker:
1417
minWorkers: 3
1518
targetWorkers: 3
19+
1620
relays: stage
21+
1722
services:
1823
eth_rpc:
1924
get: wasm-modules

Diff for: gateway/package-lock.json

+63-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gateway/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"author": "Fluence Labs",
2121
"license": "Apache-2.0",
2222
"dependencies": {
23-
"@fluencelabs/js-client": "0.3.0",
23+
"@fluencelabs/js-client": "0.4.2",
2424
"@fluencelabs/marine-worker": "0.3.3",
2525
"body-parser": "1.20.2",
2626
"express": "4.18.2",

Diff for: gateway/src/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function findSameResults(results, minNum) {
8686
if (getMaxRepeated >= minNum) {
8787
console.log(resultCounts);
8888
const max = Object.entries(resultCounts).find(
89-
(kv) => kv[1] === getMaxRepeated
89+
(kv) => kv[1] === getMaxRepeated,
9090
);
9191
return {
9292
value: max[0],
@@ -132,7 +132,7 @@ async function methodHandler(reqRaw, method) {
132132
req,
133133
counterServiceId,
134134
counterPeerId,
135-
config.serviceId
135+
config.serviceId,
136136
);
137137
} else if (mode === "quorum") {
138138
const quorumResult = await quorumEth(
@@ -143,14 +143,14 @@ async function methodHandler(reqRaw, method) {
143143
req,
144144
quorumServiceId,
145145
quorumPeerId,
146-
{ ttl: 20000 }
146+
{ ttl: 20000 },
147147
);
148148

149149
if (quorumResult.error) {
150150
console.error(
151151
`quorum failed: ${quorumResult.error}\n${JSON.stringify(
152-
quorumResult.results
153-
)}`
152+
quorumResult.results,
153+
)}`,
154154
);
155155
result = { success: false, error: quorumResult.error };
156156
} else {

Diff for: jest.config.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2023 Fluence Labs Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** @type {import('ts-jest').JestConfigWithTsJest} */
18+
export default {
19+
testEnvironment: "node",
20+
testTimeout: 1000 * 60 * 10, // 10 minutes in milliseconds
21+
projects: [
22+
{
23+
// Uses the serial runner for integration test files
24+
displayName: "INTEGRATION",
25+
runner: "jest-serial-runner",
26+
testMatch: ["<rootDir>/test/**/*.integration-test.ts"],
27+
extensionsToTreatAsEsm: [".ts"],
28+
transform: {
29+
"^.+\\.tsx?$": [
30+
"ts-jest",
31+
{
32+
useESM: true,
33+
tsconfig: "test/tsconfig.json",
34+
},
35+
],
36+
},
37+
},
38+
],
39+
};

0 commit comments

Comments
 (0)