Skip to content

Commit 8e50e00

Browse files
committed
fix: renterd hostd config tests
1 parent 5611d44 commit 8e50e00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1196
-17
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
GITHUB_TOKEN=secret_token
22
NOTION_TOKEN=secret_token
33
ASSETS=/User/bob/web/assets
4+
HOSTD_E2E_TEST_API_URL=https://hostd.zen.local
5+
HOSTD_E2E_TEST_API_PASSWORD=password
6+
RENTERD_E2E_TEST_API_URL=https://renterd.zen.local
7+
RENTERD_E2E_TEST_API_PASSWORD=password
8+
WALLETD_E2E_TEST_API_URL=https://walletd.zen.local
9+
WALLETD_E2E_TEST_API_PASSWORD=password
410

511
# Make Go use UTC for time formatting
612
TZ=UTC

.github/workflows/pr.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ jobs:
4141
- name: Test TypeScript
4242
shell: bash
4343
run: npx nx affected --target=test --parallel=5
44-
- name: Install playwright deps for e2e
45-
shell: bash
46-
run: npx playwright install-deps
47-
- name: Test e2e
48-
shell: bash
49-
run: npx nx affected --target=e2e --parallel=5
50-
env:
51-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5244
- name: Build
5345
shell: bash
5446
run: npx nx affected --target=build --configuration=production --parallel=5
@@ -59,6 +51,53 @@ jobs:
5951
shell: bash
6052
# issue with parallelism
6153
run: npx nx affected --target=build --configuration=export --parallel=5
54+
test-e2e:
55+
runs-on: ubuntu-latest
56+
# Only run one test-e2e job at a time because they mutate the same data
57+
concurrency: test-e2e
58+
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
59+
steps:
60+
- name: Checkout all commits
61+
uses: actions/checkout@v3
62+
with:
63+
fetch-depth: 0
64+
# Full setup required since building the JS SDK requires Go
65+
- name: Setup
66+
uses: ./.github/actions/setup-all
67+
with:
68+
node_version: 20.10.0
69+
go_version: 1.21.7
70+
# The SDK is referenced via dist in the tsconfig.base.json
71+
# because the next executor does not actually support
72+
# buildLibsFromSource=false
73+
# With this configuration NX does not build the SDK as expected
74+
# when it is an app dependency
75+
- name: Force build SDK
76+
shell: bash
77+
run: npx nx run sdk:build
78+
- name: Install playwright deps for e2e
79+
shell: bash
80+
run: npx playwright install-deps
81+
- name: Test e2e
82+
shell: bash
83+
run: npx nx affected --target=e2e --parallel=5
84+
env:
85+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
86+
RENTERD_E2E_TEST_API_URL: ${{ secrets.RENTERD_E2E_TEST_API_URL }}
87+
RENTERD_E2E_TEST_API_PASSWORD: ${{ secrets.RENTERD_E2E_TEST_API_PASSWORD }}
88+
HOSTD_E2E_TEST_API_URL: ${{ secrets.HOSTD_E2E_TEST_API_URL }}
89+
HOSTD_E2E_TEST_API_PASSWORD: ${{ secrets.HOSTD_E2E_TEST_API_PASSWORD }}
90+
WALLETD_E2E_TEST_API_URL: ${{ secrets.WALLETD_E2E_TEST_API_URL }}
91+
WALLETD_E2E_TEST_API_PASSWORD: ${{ secrets.WALLETD_E2E_TEST_API_PASSWORD }}
92+
- uses: actions/upload-artifact@v4
93+
if: ${{ !cancelled() }}
94+
with:
95+
name: playwright-report
96+
path: |
97+
apps/renterd-e2e/output/
98+
apps/hostd-e2e/output/
99+
apps/walletd-e2e/output/
100+
retention-days: 7
62101
test-go:
63102
# Run matrix since Go modules are used across all platforms
64103
runs-on: ${{ matrix.os }}

.github/workflows/release-main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ jobs:
140140
- name: Test TypeScript
141141
shell: bash
142142
run: npx nx run-many --target=test --all --parallel=5
143+
# This job should always pass because the workflow is running run against code that
144+
# was already linted and tested in PR.
145+
# This runs in parallel to the build and release process as an extra check but does
146+
# not actually block the release if job fails.
147+
test-e2e:
148+
runs-on: ubuntu-latest
149+
# Only run one test-e2e job at a time because they mutate the same data
150+
concurrency: test-e2e
151+
steps:
152+
- name: Checkout all commits
153+
uses: actions/checkout@v3
154+
with:
155+
fetch-depth: 0
156+
- name: Setup
157+
uses: ./.github/actions/setup-all
158+
with:
159+
node_version: 20.10.0
160+
go_version: 1.21.7
161+
# The SDK is referenced via dist in the tsconfig.base.json
162+
# because the next executor does not actually support
163+
# buildLibsFromSource=false
164+
# With this configuration NX does not build the SDK as expected
165+
# when it is an app dependency
166+
- name: Force build SDK
167+
shell: bash
168+
run: npx nx run sdk:build
143169
- name: Install playwright deps for e2e
144170
shell: bash
145171
run: npx playwright install-deps
@@ -148,6 +174,21 @@ jobs:
148174
run: npx nx run-many --target=e2e --all --parallel=5
149175
env:
150176
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
177+
RENTERD_E2E_TEST_API_URL: ${{ secrets.RENTERD_E2E_TEST_API_URL }}
178+
RENTERD_E2E_TEST_API_PASSWORD: ${{ secrets.RENTERD_E2E_TEST_API_PASSWORD }}
179+
HOSTD_E2E_TEST_API_URL: ${{ secrets.HOSTD_E2E_TEST_API_URL }}
180+
HOSTD_E2E_TEST_API_PASSWORD: ${{ secrets.HOSTD_E2E_TEST_API_PASSWORD }}
181+
WALLETD_E2E_TEST_API_URL: ${{ secrets.WALLETD_E2E_TEST_API_URL }}
182+
WALLETD_E2E_TEST_API_PASSWORD: ${{ secrets.WALLETD_E2E_TEST_API_PASSWORD }}
183+
- uses: actions/upload-artifact@v4
184+
if: ${{ !cancelled() }}
185+
with:
186+
name: playwright-report
187+
path: |
188+
apps/renterd-e2e/output/
189+
apps/hostd-e2e/output/
190+
apps/walletd-e2e/output/
191+
retention-days: 7
151192
# This job should always pass because the workflow is running run against code that
152193
# was already linted and tested in PR.
153194
# This runs in parallel to the build and release process as an extra check but does

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi
6565
### Testing
6666

6767
- [walletd-e2e](walletd-e2e) - App for testing walletd.
68+
- [renterd-e2e](renterd-e2e) - App for testing renterd.
69+
- [hostd-e2e](hostd-e2e) - App for testing hostd.
6870
- [@siafoundation/walletd-mock](walletd-mock) - `walletd` data and API mock library for testing.
6971
- [@siafoundation/sia-central-mock](sia-central-mock) - Sia Central data and API mock library for testing.
7072

apps/hostd-e2e/.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["plugin:playwright/recommended", "../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["src/**/*.{ts,js,tsx,jsx}"],
19+
"rules": {}
20+
}
21+
],
22+
"rules": {
23+
"playwright/expect-expect": "off"
24+
}
25+
}

apps/hostd-e2e/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output

apps/hostd-e2e/playwright.config.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import { nxE2EPreset } from '@nx/playwright/preset'
3+
4+
import { workspaceRoot } from '@nx/devkit'
5+
6+
// For CI, you may want to set BASE_URL to the deployed application.
7+
const baseURL = process.env['BASE_URL'] || 'http://localhost:3006'
8+
9+
/**
10+
* Read environment variables from file.
11+
* https://github.com/motdotla/dotenv
12+
*/
13+
// require('dotenv').config();
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig({
19+
...nxE2EPreset(__filename, { testDir: './src' }),
20+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
21+
use: {
22+
baseURL,
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: 'on-first-retry',
25+
video: 'on-first-retry',
26+
},
27+
expect: {
28+
// Raise the timeout because it is running against next dev mode
29+
// which requires compilation the first to a page is visited
30+
timeout: 10_000,
31+
},
32+
outputDir: 'output',
33+
/* Run your local dev server before starting the tests */
34+
webServer: {
35+
command: 'npx nx serve hostd',
36+
url: baseURL,
37+
reuseExistingServer: !process.env.CI,
38+
cwd: workspaceRoot,
39+
},
40+
// Run the tests serially as they may mutate the state of the same application.
41+
workers: 1,
42+
projects: [
43+
{
44+
name: 'chromium',
45+
use: { ...devices['Desktop Chrome'] },
46+
},
47+
48+
// Disable firefox and webkit to save time since tests are running serially.
49+
// {
50+
// name: 'firefox',
51+
// use: { ...devices['Desktop Firefox'] },
52+
// },
53+
54+
// {
55+
// name: 'webkit',
56+
// use: { ...devices['Desktop Safari'] },
57+
// },
58+
59+
// Uncomment for mobile browsers support
60+
/* {
61+
name: 'Mobile Chrome',
62+
use: { ...devices['Pixel 5'] },
63+
},
64+
{
65+
name: 'Mobile Safari',
66+
use: { ...devices['iPhone 12'] },
67+
}, */
68+
69+
// Uncomment for branded browsers
70+
/* {
71+
name: 'Microsoft Edge',
72+
use: { ...devices['Desktop Edge'], channel: 'msedge' },
73+
},
74+
{
75+
name: 'Google Chrome',
76+
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
77+
} */
78+
],
79+
})

apps/hostd-e2e/project.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "hostd-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "apps/hostd-e2e/src",
5+
"projectType": "application",
6+
"implicitDependencies": ["hostd"],
7+
"targets": {
8+
"e2e": {
9+
"executor": "@nx/playwright:playwright",
10+
"outputs": ["{workspaceRoot}/dist/.playwright/apps/hostd-e2e"],
11+
"options": {
12+
"config": "apps/hostd-e2e/playwright.config.ts"
13+
}
14+
},
15+
"lint": {
16+
"executor": "@nx/eslint:lint"
17+
}
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Page } from '@playwright/test'
2+
3+
export async function clearToasts({ page }: { page: Page }) {
4+
const clearButtons = page.getByTestId('toasts').locator('button')
5+
while ((await clearButtons.count()) > 0) {
6+
await clearButtons.first().click()
7+
// Timeout required because the toast animation is not instantaneous.
8+
// eslint-disable-next-line playwright/no-wait-for-timeout
9+
await page.waitForTimeout(1000)
10+
}
11+
}

apps/hostd-e2e/src/fixtures/click.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Locator, expect } from '@playwright/test'
2+
3+
export async function clickAndWaitIfEnabled(
4+
locator: Locator,
5+
waitForLocator?: Locator
6+
) {
7+
const isDisabled = await locator.isDisabled()
8+
if (!isDisabled) {
9+
await locator.click()
10+
if (waitForLocator) {
11+
await expect(waitForLocator).toBeVisible()
12+
}
13+
return true
14+
}
15+
return false
16+
}
17+
18+
export async function clickAndWait(locator: Locator, waitForLocator?: Locator) {
19+
await locator.click()
20+
if (waitForLocator) {
21+
await expect(waitForLocator).toBeVisible()
22+
}
23+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Page } from '@playwright/test'
2+
import { setSwitchByLabel } from './switchValue'
3+
import { setViewMode } from './configViewMode'
4+
import { fillTextInputByName } from './textInput'
5+
import { fillSelectInputByName } from './selectInput'
6+
import { clearToasts } from './clearToasts'
7+
import { clickAndWaitIfEnabled } from './click'
8+
9+
export async function configResetAllSettings({ page }: { page: Page }) {
10+
await setViewMode({ page, state: 'advanced' })
11+
12+
// host
13+
await setSwitchByLabel(page, 'acceptingContracts', false)
14+
await fillTextInputByName(page, 'netAddress', 'foobar.com:9880')
15+
await fillTextInputByName(page, 'maxContractDuration', '6')
16+
17+
// pricing
18+
await fillSelectInputByName(page, 'pinnedCurrency', 'USD')
19+
await fillTextInputByName(page, 'pinnedThreshold', '3')
20+
21+
await setSwitchByLabel(page, 'shouldPinStoragePrice', false)
22+
await fillTextInputByName(page, 'storagePrice', '10')
23+
await setSwitchByLabel(page, 'shouldPinStoragePrice', true)
24+
await fillTextInputByName(page, 'storagePricePinned', '5')
25+
await setSwitchByLabel(page, 'shouldPinStoragePrice', false)
26+
27+
await setSwitchByLabel(page, 'shouldPinEgressPrice', false)
28+
await fillTextInputByName(page, 'egressPrice', '10')
29+
await setSwitchByLabel(page, 'shouldPinEgressPrice', true)
30+
await fillTextInputByName(page, 'egressPricePinned', '5')
31+
await setSwitchByLabel(page, 'shouldPinEgressPrice', false)
32+
33+
await setSwitchByLabel(page, 'shouldPinIngressPrice', false)
34+
await fillTextInputByName(page, 'ingressPrice', '10')
35+
await setSwitchByLabel(page, 'shouldPinIngressPrice', true)
36+
await fillTextInputByName(page, 'ingressPricePinned', '5')
37+
await setSwitchByLabel(page, 'shouldPinIngressPrice', false)
38+
39+
await fillTextInputByName(page, 'collateralMultiplier', '2')
40+
41+
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
42+
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
43+
await setSwitchByLabel(page, 'autoMaxCollateral', false)
44+
await fillTextInputByName(page, 'maxCollateral', '10')
45+
await setSwitchByLabel(page, 'shouldPinMaxCollateral', true)
46+
await fillTextInputByName(page, 'maxCollateralPinned', '5')
47+
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
48+
49+
await fillTextInputByName(page, 'contractPrice', '0.2')
50+
await fillTextInputByName(page, 'baseRPCPrice', '1')
51+
await fillTextInputByName(page, 'sectorAccessPrice', '1')
52+
await fillTextInputByName(page, 'priceTableValidity', '30')
53+
54+
// accounts
55+
await fillTextInputByName(page, 'accountExpiry', '30')
56+
await fillTextInputByName(page, 'maxAccountBalance', '10')
57+
58+
// bandwidth
59+
await fillTextInputByName(page, 'ingressLimit', '0')
60+
await fillTextInputByName(page, 'egressLimit', '0')
61+
62+
// DNS
63+
await fillSelectInputByName(page, 'dnsProvider', '')
64+
65+
// save
66+
await clickAndWaitIfEnabled(
67+
page.getByText('Save changes'),
68+
page.getByText('Settings have been saved')
69+
)
70+
await clearToasts({ page })
71+
}

0 commit comments

Comments
 (0)