Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settings quorum tests #101

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ return (
type="button"
data-bs-toggle="dropdown"
aria-expanded="false"
data-testid="dropdown-btn"
>
{selected.label}
</button>
Expand Down
40 changes: 27 additions & 13 deletions instances/treasury-devdao.near/widget/pages/settings/Thresholds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url") || {
href: () => {},
};

if (typeof getRoleWiseData !== "function") {
return <></>;
}
const [selectedGroup, setSelectedGroup] = useState(null);
const [selectedVoteOption, setSelectedVoteOption] = useState(null);
const [selectedVoteValue, setSelectedVoteValue] = useState(null);
Expand All @@ -31,7 +34,7 @@ const hasCreatePermission = hasPermission(
);

useEffect(() => {
if (Array.isArray(rolesData) && rolesData.length && !selectedGroup) {
if (Array.isArray(rolesData) && rolesData.length) {
setSelectedGroup(rolesData[0]);
}
}, [rolesData]);
Expand All @@ -57,9 +60,10 @@ function getLastProposalId() {
}

useEffect(() => {
if (typeof getRoleWiseData === "function") {
getRoleWiseData(treasuryDaoID).then((resp) => setRolesData(resp));
}
setRolesData([]);
getRoleWiseData(treasuryDaoID).then((resp) => {
setRolesData(resp);
});
}, [refreshData]);

useEffect(() => {
Expand All @@ -73,11 +77,16 @@ function checkProposalStatus(proposalId) {
Near.asyncView(treasuryDaoID, "get_proposal", {
id: proposalId,
}).then((result) => {
if (result.status === "Approved") {
setRefreshData(!refreshData);
if (Object.keys(result.votes).length === 1) {
if (result.status === "Approved") {
setRefreshData(!refreshData);
}
setToastStatus(result.status);
setVoteProposalId(proposalId);
setTxnCreated(false);
} else {
setTimeout(() => checkProposalStatus(proposalId), 1000);
}
setToastStatus(result.status);
setVoteProposalId(proposalId);
});
}

Expand Down Expand Up @@ -230,7 +239,7 @@ function updateDaoPolicy() {
weight_kind: "RoleWeight",
quorum: "0",
threshold: isPercentageSelected
? [selectedVoteValue, 100]
? [parseInt(selectedVoteValue), 100]
: selectedVoteValue,
};
return policy;
Expand Down Expand Up @@ -350,7 +359,7 @@ return (
instance,
heading: "Are you sure?",
content: (
<div>
<div className="d-flex flex-column gap-2">
This action will result in significant changes to the system.
<div className="d-flex gap-3 warning px-3 py-2 rounded-3">
<i class="bi bi-exclamation-triangle h5"></i>
Expand Down Expand Up @@ -400,7 +409,10 @@ return (
<div className="d-flex flex-column gap-1">
{Array.isArray(selectedGroup.members) &&
selectedGroup.members.map((member) => (
<div className="p-1 px-3">
<div
className="p-1 px-3 text-truncate"
style={{ width: "85%" }}
>
<Widget
src="mob.near/widget/Profile.ShortInlineBlock"
props={{ accountId: member, tooltip: true }}
Expand Down Expand Up @@ -438,9 +450,11 @@ return (
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Input`}
props={{
className: "flex-grow-1 p-0",
key: `threshold-input`,
onChange: (e) => {
setSelectedVoteValue(e.target.value);
const number = parseInt(e.target.value);
const value = e.target.value.replace(/[^0-9]/g, "");
setSelectedVoteValue(value);
const number = parseInt(value);
setValueError(null);
if (isPercentageSelected) {
if (number > 100)
Expand Down
197 changes: 197 additions & 0 deletions playwright-tests/tests/members/create-threshold-request.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { expect } from "@playwright/test";
import { test } from "../../util/test.js";

import { getTransactionModalObject } from "../../util/transaction.js";
import {
getMockedPolicy,
mockRpcRequest,
updateDaoPolicyMembers,
} from "../../util/rpcmock.js";

const lastProposalId = 3;

const votePolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: [0, 100],
};

async function updateLastProposalId(page) {
await mockRpcRequest({
page,
filterParams: {
method_name: "get_last_proposal_id",
},
modifyOriginalResultFunction: (originalResult) => {
originalResult = lastProposalId;
return originalResult;
},
});
}

async function checkForVoteApproveTxn(page) {
const txnLocator = await page
.locator("div.modal-body code")
.nth(1)
.innerText();
const dataReceived = JSON.parse(txnLocator);
expect(dataReceived).toEqual({
id: lastProposalId,
action: "VoteApprove",
});
}

test.describe("without login", function () {
test.beforeEach(async ({ page, instanceAccount }) => {
await updateDaoPolicyMembers({ page });
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.getByText("Voting Thresholds").click({ timeout: 20_000 });
});

test("should show members of different roles", async ({ page }) => {
test.setTimeout(60_000);
await expect(page.getByText("Permission Groups")).toBeVisible({
timeout: 20_000,
});
await expect(page.getByText("Members 6")).toBeVisible();
await expect(page.getByText("Voting Policy")).toBeVisible();
await expect(
page.getByText(
"@2dada969f3743a4a41cfdb1a6e39581c2844ce8fbe25948700c85c598090b3e1",
{ exact: true }
)
).toBeVisible();
await page.getByText("Manage Members").click();
await expect(
page.getByText("@megha19.near", { exact: true })
).toBeVisible();
await page.getByText("Vote", { exact: true }).click();
await expect(page.getByText("@test04.near", { exact: true })).toBeVisible();
});

test("should disable input and hide submit button for non authorised people", async ({
page,
}) => {
test.setTimeout(60_000);
await expect(page.getByText("Permission Groups")).toBeVisible({
timeout: 20_000,
});
await expect(page.getByTestId("dropdown-btn")).toBeDisabled();
await expect(page.getByText("Submit")).toBeHidden();
await expect(page.getByTestId("threshold-input")).toBeDisabled();
});
});

async function fillInput(page, value) {
const submitBtn = page.getByText("Submit");
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.type(value);
expect(submitBtn).toBeVisible();
}

test.describe("admin connected", function () {
test.use({
storageState: "playwright-tests/storage-states/wallet-connected-admin.json",
});

test.beforeEach(async ({ page, instanceAccount }) => {
await updateLastProposalId(page);
await updateDaoPolicyMembers({ page });
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.getByText("Voting Thresholds").click({ timeout: 20_000 });
await expect(page.getByText("Submit")).toBeVisible({
timeout: 20_000,
});
await page.getByTestId("dropdown-btn").click();
});

test("should allow only valid input for threshold", async ({ page }) => {
test.setTimeout(20_000);
await page.getByRole("list").getByText("Number of votes").click();
await fillInput(page, "20097292");
await fillInput(page, "10.323");
await fillInput(page, "werwr");
await fillInput(page, "$&$^&%&");
await page.getByTestId("dropdown-btn").click();
await page.getByRole("list").getByText("Percentage of members").click();
await fillInput(page, "3423");
await fillInput(page, "13.123");
await fillInput(page, "wqeqewq");
await fillInput(page, "$&$^&%&");
});

test("should be able to update policy by fixed vote count", async ({
page,
}) => {
test.setTimeout(60_000);
const submitBtn = page.getByText("Submit");
await page.getByRole("list").getByText("Number of votes").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("20");
await expect(page.getByText("Maximum members allowed is ")).toBeVisible();
await expect(submitBtn).toBeDisabled();
await thresholdInput.fill("2");
await submitBtn.click();
await expect(
page.getByText(
"Changing this setting will require 2 vote(s) to approve requests. You will no longer be able to approve requests with 1 vote(s)."
)
).toBeVisible();
await page.getByRole("button", { name: "Confirm" }).click();
const updatedPolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: "2",
};

expect(await getTransactionModalObject(page)).toEqual({
proposal: {
description: "Update Policy",
kind: {
ChangePolicy: {
policy: getMockedPolicy(updatedPolicy, votePolicy, votePolicy),
},
},
},
});
await checkForVoteApproveTxn(page);
});

test("should be able to update policy by percentage", async ({ page }) => {
test.setTimeout(60_000);
const submitBtn = page.getByText("Submit");
await page.getByRole("list").getByText("Percentage of members").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("101");
await expect(
page.getByText("Maximum percentage allowed is ")
).toBeVisible();
await expect(submitBtn).toBeDisabled();
await thresholdInput.fill("20");
await expect(page.getByText("Heads up, Bro!")).toBeVisible();
await submitBtn.click();
await expect(
page.getByText(
"Changing this setting will require 2 vote(s) to approve requests. You will no longer be able to approve requests with 1 vote(s)."
)
).toBeVisible();
await page.getByRole("button", { name: "Confirm" }).click();
const updatedPolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: [20, 100],
};

await expect(await getTransactionModalObject(page)).toEqual({
proposal: {
description: "Update Policy",
kind: {
ChangePolicy: {
policy: getMockedPolicy(updatedPolicy, votePolicy, votePolicy),
},
},
},
});
await checkForVoteApproveTxn(page);
});
});
Loading
Loading