Skip to content

Commit

Permalink
fix(renterd): network average prices
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 30, 2024
1 parent 9a99d95 commit 99c662c
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 178 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-avocados-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Max RPC price and max contract price now show a suggestion instead of a network average.
5 changes: 5 additions & 0 deletions .changeset/popular-rocks-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': patch
---

Fixed a bug where the network average prices would show as 0 in the configuration fields. Closes https://github.com/SiaFoundation/renterd/issues/1565
2 changes: 0 additions & 2 deletions apps/hostd-e2e/src/fixtures/configResetAllSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { setSwitchByLabel } from './switchValue'
import { setViewMode } from './configViewMode'
import { fillTextInputByName } from './textInput'
import { fillSelectInputByName } from './selectInput'
import { clearToasts } from './clearToasts'
import { clickIfEnabledAndWait } from './click'
import { navigateToConfig } from './navigate'

Expand Down Expand Up @@ -67,7 +66,6 @@ export async function configResetAllSettings({ page }: { page: Page }) {
page.getByText('Save changes'),
page.getByText('Settings have been saved')
)
await clearToasts({ page })
await setViewMode({ page, state: 'basic' })
await navigateToConfig({ page })
}
2 changes: 0 additions & 2 deletions apps/renterd-e2e/src/fixtures/buckets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Page, expect } from '@playwright/test'
import { navigateToBuckets } from './navigate'
import { fillTextInputByName } from './textInput'
import { clearToasts } from './clearToasts'
import { deleteDirectory, deleteFile } from './files'

export async function createBucket(page: Page, name: string) {
Expand All @@ -11,7 +10,6 @@ export async function createBucket(page: Page, name: string) {
await page.locator('input[name=name]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
await expect(page.getByText('Bucket created')).toBeVisible()
await clearToasts({ page })
await expect(page.getByRole('cell', { name })).toBeVisible()
}

Expand Down
5 changes: 5 additions & 0 deletions apps/renterd-e2e/src/fixtures/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ export async function clickIf(
}
return false
}

export async function clickTwice(locator: Locator) {
await locator.click()
await locator.click()
}
2 changes: 0 additions & 2 deletions apps/renterd-e2e/src/fixtures/configResetAllSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Page } from '@playwright/test'
import { setSwitchByLabel } from './switchValue'
import { setViewMode } from './configViewMode'
import { fillTextInputByName } from './textInput'
import { clearToasts } from './clearToasts'
import { clickIfEnabledAndWait } from './click'
import { fillSelectInputByName } from './selectInput'
import { navigateToConfig } from './navigate'
Expand Down Expand Up @@ -73,6 +72,5 @@ export async function configResetAllSettings({ page }: { page: Page }) {
page.getByText('Save changes'),
page.getByText('Configuration has been saved')
)
await clearToasts({ page })
await setViewMode({ page, state: 'basic' })
}
9 changes: 7 additions & 2 deletions apps/renterd-e2e/src/fixtures/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Page } from 'playwright'
import { fillSelectInputByName } from './selectInput'
import { CurrencyId } from '@siafoundation/react-core'

export async function setCurrencyDisplay(
page: Page,
display: 'sc' | 'fiat' | 'bothPreferSc' | 'bothPreferFiat'
display: 'sc' | 'fiat' | 'bothPreferSc' | 'bothPreferFiat',
currency?: CurrencyId
) {
await page.getByLabel('App preferences').click()
await page.getByTestId('sidenav').getByLabel('App preferences').click()
await fillSelectInputByName(page, 'currencyDisplay', display)
if (currency) {
await fillSelectInputByName(page, 'currencyFiat', currency)
}
await page.getByRole('dialog').getByLabel('close').click()
}
21 changes: 20 additions & 1 deletion apps/renterd-e2e/src/fixtures/siascan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ export async function mockApiSiaScanExchangeRates({ page }: { page: Page }) {
await page.route(
'https://api.siascan.com/exchange-rate/siacoin/*',
async (route) => {
await route.fulfill({ json: 0.003944045283 })
if (route.request().url().endsWith('jpy')) {
await route.fulfill({ json: 0.727779694168 })
} else {
await route.fulfill({ json: 0.003944045283 })
}
}
)
}

export async function mockApiSiaScanExchangeRatesHanging({
page,
}: {
page: Page
}) {
await page.route(
'https://api.siascan.com/exchange-rate/siacoin/*',
async () => {
await new Promise(() => {
// Never resolve, leaving the request hanging.
})
}
)
}
58 changes: 28 additions & 30 deletions apps/renterd-e2e/src/specs/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { afterTest, beforeTest } from '../fixtures/beforeTest'
import { setCurrencyDisplay } from '../fixtures/preferences'
import { configResetAllSettings } from '../fixtures/configResetAllSettings'
import { fillSelectInputByName } from '../fixtures/selectInput'
import { clickTwice } from '../fixtures/click'

test.beforeEach(async ({ page }) => {
await beforeTest(page)
Expand All @@ -20,7 +21,7 @@ test.afterEach(async () => {
await afterTest()
})

test('basic field change and save behaviour', async ({ page }) => {
test('field change and save behaviours', async ({ page }) => {
// Reset state.
await navigateToConfig({ page })
await setViewMode({ page, state: 'basic' })
Expand Down Expand Up @@ -62,33 +63,6 @@ test('basic field change and save behaviour', async ({ page }) => {
for (const part of estimateParts) {
await expect(page.getByText(part)).toBeVisible()
}

// Tips are displayed in the correct currency.
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('341')
).toBeVisible()
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.getByText('300')
).toBeVisible()
await setCurrencyDisplay(page, 'bothPreferFiat')
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('$1.34')
).toBeVisible()
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.getByText('$1.18')
).toBeVisible()
})

test('set max prices to fit current allowance', async ({ page }) => {
Expand Down Expand Up @@ -243,11 +217,11 @@ test('set max prices via individual field tips', async ({ page }) => {
await expect(
page.getByText('Current pricing may not fit allowance')
).toBeVisible()
await page
const fitButton = page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
.click()
// TODO: remove the need to click twice, there is some sort of glitch after toggling the pinning switch.
await clickTwice(fitButton)
await page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Fit current allowance')
Expand All @@ -273,3 +247,27 @@ test('set max prices via individual field tips', async ({ page }) => {
await expectTextInputByName(page, 'maxUploadPriceTBPinned', '$0.88')
await expectTextInputByName(page, 'maxDownloadPriceTB', '1,118.588756')
})

test('pinned currency and app display currency can be different', async ({
page,
}) => {
await navigateToConfig({ page })
await setViewMode({ page, state: 'basic' })
await fillSelectInputByName(page, 'pinnedCurrency', 'usd')
await setCurrencyDisplay(page, 'bothPreferFiat', 'jpy')
await setSwitchByLabel(page, 'shouldPinMaxStoragePrice', true)
await expectTextInputByName(page, 'maxStoragePriceTBMonthPinned', '$5')
await expect(
page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('¥248.17')
).toBeVisible()
const averageButton = page
.getByTestId('maxStoragePriceTBMonthGroup')
.getByLabel('Network average')
.getByText('¥248.17')
// TODO: remove the need to click twice, there is some sort of glitch after toggling the pinning switch.
await clickTwice(averageButton)
await expectTextInputByName(page, 'maxStoragePriceTBMonthPinned', '$1.34')
})
Loading

0 comments on commit 99c662c

Please sign in to comment.