Skip to content

Commit

Permalink
Treasury creation e2e test (#201)
Browse files Browse the repository at this point in the history
Resolves e2e part of
#167
  • Loading branch information
rubycop authored Jan 8, 2025
1 parent 8f0ae28 commit dc4a23d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
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();
});
});

0 comments on commit dc4a23d

Please sign in to comment.