Skip to content

Commit

Permalink
Limit the contract duration to 7 for the testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
2-towns committed Nov 27, 2024
1 parent 1f4e7d0 commit e6e7730
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
50 changes: 29 additions & 21 deletions e2e/storage-requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@ test('create a storage request by using decimal values', async ({ page }) => {
await expect(page.getByText('Success, the CID has been')).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click();

await expect(page.getByRole('combobox')).toHaveValue("days");
await page.getByLabel("Full period of the contract").fill("10")
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled");

await page.getByLabel("Full period of the contract").fill("1")
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");

await page.getByLabel("Full period of the contract").fill("0")
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled");

const value = (Math.random() * 10);
await page.getByLabel("Full period of the contract").fill(value.toFixed(1))
await expect(page.getByRole('combobox')).toHaveValue("days");
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");

await page.getByRole('button', { name: 'Next' }).click();
await expect(page.getByText('Your request is being processed.')).toBeVisible();
Expand All @@ -101,25 +109,25 @@ test('create a storage request by using decimal values', async ({ page }) => {
await expect(page.getByText(value.toFixed(1) + " days").first()).toBeVisible();
})

test('create a storage request by using months', async ({ page }) => {
await page.goto('/dashboard');
await page.locator('a').filter({ hasText: 'Purchases' }).click();
await page.getByRole('button', { name: 'Storage Request' }).click();
// test('create a storage request by using months', async ({ page }) => {
// await page.goto('/dashboard');
// await page.locator('a').filter({ hasText: 'Purchases' }).click();
// await page.getByRole('button', { name: 'Storage Request' }).click();

await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await expect(page.locator('#cid')).not.toBeEmpty()
await expect(page.getByText('Success, the CID has been')).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click();
// await page.locator('div').getByTestId("upload").setInputFiles([
// path.join(__dirname, "assets", 'chatgpt.jpg'),
// ]);
// await expect(page.locator('#cid')).not.toBeEmpty()
// await expect(page.getByText('Success, the CID has been')).toBeVisible();
// await page.getByRole('button', { name: 'Next' }).click();

await page.getByLabel("Full period of the contract").fill("3")
await page.getByRole('combobox').selectOption('months');
await expect(page.getByLabel("Full period of the contract")).toHaveValue("3")
// await page.getByLabel("Full period of the contract").fill("3")
// await page.getByRole('combobox').selectOption('months');
// await expect(page.getByLabel("Full period of the contract")).toHaveValue("3")

await page.getByRole('button', { name: 'Next' }).click();
await expect(page.getByText('Your request is being processed.')).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click();
await expect(page.getByText('No data.')).not.toBeVisible();
await expect(page.getByText("3 months").first()).toBeVisible();
})
// await page.getByRole('button', { name: 'Next' }).click();
// await expect(page.getByText('Your request is being processed.')).toBeVisible();
// await page.getByRole('button', { name: 'Finish' }).click();
// await expect(page.getByText('No data.')).not.toBeVisible();
// await expect(page.getByText("3 months").first()).toBeVisible();
// })
6 changes: 5 additions & 1 deletion src/components/StorageRequestSetup/Commitment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Props = {
onValidation?: (value: string) => string;
};

const TESTNET_MAX_VALUE = 7;

export function Commitment({ unit, value, onValidation, onChange }: Props) {
const [error, setError] = useState("");

Expand Down Expand Up @@ -50,9 +52,11 @@ export function Commitment({ unit, value, onValidation, onChange }: Props) {
onChange={onValueChange}
onGroupChange={onUnitChange}
value={value}
min={0}
max={TESTNET_MAX_VALUE}
group={[
["days", "days"],
["months", "months"],
// ["months", "months"],
]}
groupValue={unit}
/>
Expand Down
23 changes: 18 additions & 5 deletions src/components/StorageRequestSetup/StorageRequestReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const durabilities = [
{ nodes: 5, tolerance: 2, proofProbability: 4 },
];

const TESTNET_MAX_VALUE = 7;

const findDurabilityIndex = (d: Durability) => {
const s = JSON.stringify({
nodes: d.nodes,
Expand Down Expand Up @@ -58,10 +60,10 @@ export function StorageRequestReview({
);

useEffect(() => {
const invalid = isInvalidConstrainst(
storageRequest.nodes,
storageRequest.tolerance
);
const invalid =
isInvalidConstrainst(storageRequest.nodes, storageRequest.tolerance) ||
storageRequest.availability > TESTNET_MAX_VALUE ||
storageRequest.availability == 0;

dispatch({
type: "toggle-buttons",
Expand Down Expand Up @@ -134,7 +136,10 @@ export function StorageRequestReview({
const isInvalidAvailability = (data: string) => {
const [value] = data.split(" ");

const error = isInvalidNumber(value);
const error =
isInvalidNumber(value) ||
isInvalidAvailabilityNumber(value) ||
isRequiredNumber(value);

if (error) {
return error;
Expand All @@ -146,6 +151,14 @@ export function StorageRequestReview({
const isInvalidNumber = (value: string) =>
isNaN(Number(value)) ? "The value is not a number" : "";

const isRequiredNumber = (value: string) =>
value == "0" ? "The value has to be more than 0." : "";

const isInvalidAvailabilityNumber = (value: string) =>
parseInt(value, 10) > TESTNET_MAX_VALUE
? "The maximum value is on the current Testnet is 7 days"
: "";

const onNodesChange = (value: string) =>
onUpdateDurability({ nodes: Number(value) });

Expand Down

0 comments on commit e6e7730

Please sign in to comment.