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

Treasury creation e2e test #201

Merged
merged 7 commits into from
Jan 8, 2025
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 @@ -37,6 +37,7 @@ const checkAccountAvailable = async (accountId) => {
return (
<div className="position-relative d-flex align-items-center">
<input
className="account-input"
type="text"
placeholder="app-account"
value={value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ return (
</Section>
<Link
className={`btn btn-primary w-100 ${
balance < REQUIRED_BALANCE ? "disabled" : ""
balance < REQUIRED_BALANCE ? "disabled" : "active"
}`}
href={`/${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/app?page=create-treasury&step=1`}
>
Expand Down
98 changes: 91 additions & 7 deletions playwright-tests/tests/page.treasury-factory.near.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect } from "@playwright/test";
import { test } from "../util/test.js";
import { SandboxRPC } from "../util/sandboxrpc.js";
import nearApi from "near-api-js";

test.afterEach(async ({ page }, testInfo) => {
console.log(`Finished ${testInfo.title} with status ${testInfo.status}`);
Expand All @@ -18,17 +20,99 @@ test.describe("admin connected", function () {
page,
factoryAccount,
}) => {
await page.goto(`/${factoryAccount}/widget/app?page`);
test.setTimeout(120_000);
const accName = Math.random().toString(36).slice(2, 7);

await expect(
await page.locator("h3").filter({ hasText: "Treasury Creation" })
).toBeVisible();
const setupSandboxTxnProcessing = async () => {
const widget_reference_account_id = "treasury-testing.near";
const sandbox = new SandboxRPC();

await sandbox.init();
await sandbox.attachRoutes(page);
await sandbox.setupWidgetReferenceAccount(widget_reference_account_id);

const transactionToSendPromise = page.evaluate(async () => {
const selector = await document.querySelector("near-social-viewer")
.selectorPromise;

const wallet = await selector.wallet();

return new Promise((resolve) => {
wallet.signAndSendTransactions = async (transactions) => {
resolve(transactions.transactions[0]);

return await new Promise(
(transactionSentPromiseResolve) =>
(window.transactionSentPromiseResolve =
transactionSentPromiseResolve)
);
};
});
});

await page.getByRole("button", { name: "Confirm", exact: true }).click();

await expect(await page.getByText("Treasury Creation")).toBeVisible();
const transactionToSend = await transactionToSendPromise;
const transactionResult = await sandbox.account.functionCall({
contractId: "treasury-factory.near",
methodName: "create_instance",
args: transactionToSend.actions[0].params.args,
gas: 300000000000000,
attachedDeposit: nearApi.utils.format.parseNearAmount("12"),
});

await page.evaluate((transactionResult) => {
window.transactionSentPromiseResolve(transactionResult);
}, transactionResult);

await sandbox.quitSandbox();
};

// innitial step
await page.goto(`/${factoryAccount}/widget/app`);
await expect(
await page.locator("h3", { hasText: "Confirm your wallet" })
).toBeVisible();
await page
.locator("a")
.filter({ hasText: "Yes, use this wallet and continue" })
.locator("a.active", {
hasText: "Yes, use this wallet and continue",
})
.click();

// create application account name step
await expect(
await page.locator("h3", { hasText: "Create Application Account" })
).toBeVisible();
await page.locator("input.account-input").fill(accName);
await page.locator("a", { hasText: "Next" }).click();

// create sputnik dao account step
await expect(
await page.locator("h3", { hasText: "Create Sputnik DAO Account" })
).toBeVisible();
await page.locator("input.account-input").fill(accName);
await page.locator("a", { hasText: "Next" }).click();

// add members step
await expect(
await page.locator("h3", { hasText: "Add Members" })
).toBeVisible();
await page.locator("a", { hasText: "Next" }).click();

// confirm transaction step
await expect(
await page.locator("h3", { hasText: "Summary" })
).toBeVisible();

const submitBtn = page.locator("button", { hasText: "Confirm and Create" });
await submitBtn.scrollIntoViewIfNeeded();
await submitBtn.click();

// bos txn confirmation modal
await setupSandboxTxnProcessing();

await expect(
await page.locator("h5", { hasText: "Congrats! Your Treasury is ready" })
).toBeVisible();
});
});
Loading