Skip to content

Commit

Permalink
feat: gateway for all instances (#913)
Browse files Browse the repository at this point in the history
* feat: gateway for all instances

* replace all references to http://localhost:2000 with MOCK_RPC_URL

remove modifySocialNearGetRPCResponsesInsteadOfGettingWidgetsFromBOSLoader ( not needed when RPC proxy handles this )

mock RPC request must check on path, would not work on origin

* transaction submit RPC intercept must still check with https://rpc.mainnet.near.org

* no need for bosloader flags. need longer timeout for scrolling into view when no cache

* longer timeout is needed to wait for comment element to be visible

* don't check for bos loader environment

* longer timeout waiting for comment button

remove posthog from aliases in events/infrastructure

* must import MOCK_RPC_URL

* import MOCK_RPC_URL

* import MOCK_RPC_URL

* add timeouts when running without rpc cache

* without cache, don't use empty functions when waiting for vm.require, rather wait for them to be loaded

* wait for label options to be available

* wait for labels to appear

* remove unused scripts

* replace posthog api key in aliases file before creating replacement script

* remove console.log
  • Loading branch information
petersalomonsen authored Aug 5, 2024
1 parent 698a8dc commit 4af0f4d
Show file tree
Hide file tree
Showing 43 changed files with 140 additions and 469 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy-prod-mainnet-devhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
- name: Set replacements
id: set_replacements
run: |
echo "replacements=$(jq -r '[to_entries[] | .["find"] = "${" + .key + "}" | .["replace"] = .value | del(.key, .value), {"find": "${REPL_POSTHOG_API_KEY}", "replace": "'${{ secrets.POSTHOG_API_KEY }}'"}]' aliases.mainnet.json | tr -d "\n\r")" >> $GITHUB_OUTPUT
jq '.REPL_POSTHOG_API_KEY = "${{ secrets.POSTHOG_API_KEY }}"' aliases.mainnet.json > temp.aliases.mainnet.json && mv temp.aliases.mainnet.json aliases.mainnet.json
echo "replacements=$(jq -r '[to_entries[] | .["find"] = "${" + .key + "}" | .["replace"] = .value | del(.key, .value)]' aliases.mainnet.json | tr -d "\n\r")" >> $GITHUB_OUTPUT
- name: Replace placeholders
uses: flcdrg/replace-multiple-action@v1
Expand Down
3 changes: 2 additions & 1 deletion instances/devhub.near/aliases.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"REPL_SOCIAL_CONTRACT": "social.near",
"REPL_RPC_URL": "https://rpc.mainnet.near.org",
"REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME": "polyprogrammist_near_devhub_prod_v1_proposals_with_latest_snapshot",
"REPL_INDEXER_HASURA_ROLE": "polyprogrammist_near"
"REPL_INDEXER_HASURA_ROLE": "polyprogrammist_near",
"REPL_POSTHOG_API_KEY": "01234567890123456789012345678901234567890123456"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const { uuid, withUUIDIndex } = VM.require(
"${REPL_DEVHUB}/widget/core.lib.uuid"
);

uuid || (uuid = () => {});
withUUIDIndex || (withUUIDIndex = () => {});
useQuery || (useQuery = () => {});

const AttractableDiv = styled.div`
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) !important;
transition: box-shadow 0.6s;
Expand Down Expand Up @@ -105,8 +101,7 @@ function isValidGitHubRepoLink(url) {

const GithubViewConfigurator = ({ kanbanBoards, permissions, onSubmit }) => {
const data = kanbanBoards ? Object.values(kanbanBoards)?.[0] : {};

if (!data) {
if (!data || !withUUIDIndex || !useQuery || !uuid) {
return (
<div class="alert alert-danger" role="alert">
Loading...
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
"bw:dev:devhub": "bw dev instances/devhub.near",
"bw:build:instance": "npm run bw build instances/$npm_config_instance build/$npm_config_instance && mv build/$npm_config_instance/src/widget/* build/$npm_config_instance/src/ && rm -Rf build/$npm_config_instance/src/widget",
"bw:build:devhub": "npm run bw:build:instance --instance=devhub.near",
"gateway:devhub": "node scripts/dev-gateway.mjs devhub.near",
"gateway:all": "bw ws dev -g $(node scripts/create-static-hosting-web-gateway-folder.mjs)",
"dry-run:devhub": "npm run bw:build:devhub && cd ./build/devhub.near && bos components diff devhub.near network-config mainnet",
"bw:dev:infrastructure": "bw dev instances/infrastructure-committee.near",
"bw:build:infrastructure": "npm run bw:build:instance --instance=infrastructure-committee.near",
"gateway:infrastructure": "node scripts/dev-gateway.mjs infrastructure-committee.near",
"deploy:infrastructure": "npm run bw:build:infrastructure && cd ./build/infrastructure-committee.near && bos components deploy",
"dry-run:infrastructure": "npm run bw:build:infrastructure && cd ./build/infrastructure-committee.near && bos components diff infrastructure-committee.near network-config mainnet",
"bw:dev:events": "bw dev instances/events-committee.near",
"bw:build:events": "npm run bw:build:instance --instance=events-committee.near",
"gateway:events": "node scripts/dev-gateway.mjs events-committee.near",
"deploy:events": "npm run bw:build:events && cd ./build/events-committee.near && bos components deploy",
"dry-run:events": "npm run bw:build:events && cd ./build/events-committee.near && bos components diff events-committee.near network-config mainnet",
"test": "npx playwright test",
Expand Down
4 changes: 0 additions & 4 deletions playwright-tests/storage-states/wallet-connected-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "theori.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "orangejoe.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "petersalomonsen.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "neardevdao.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "notkycverified.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
4 changes: 0 additions & 4 deletions playwright-tests/storage-states/wallet-connected-peter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "petersalomonsen.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
4 changes: 0 additions & 4 deletions playwright-tests/storage-states/wallet-connected.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "efiz.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
12 changes: 1 addition & 11 deletions playwright-tests/storage-states/wallet-not-connected.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cookies": [],
"origins": [
{
"origin": "http://localhost:8080",
"localStorage": [
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
],
"origins": [],
"sessionStorage": []
}
4 changes: 0 additions & 4 deletions playwright-tests/storage-states/wallet-permissioned.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
{
"name": "near-social-vm:v01::accountId:",
"value": "ori.near"
},
{
"name": "flags",
"value": "{\"bosLoaderUrl\":\"http://127.0.0.1:3030\"}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
decodeResultJSON,
encodeResultJSON,
} from "../../util/transaction.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

const baseUrl =
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=first-blog";

const communityAccount = "webassemblymusic.community.devhub.near";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});

Expand Down
3 changes: 2 additions & 1 deletion playwright-tests/tests/blog/blogv2.admin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { expect, test } from "@playwright/test";
import { pauseIfVideoRecording } from "../../testUtils.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { mockBlogs } from "../../util/blogs.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";
const baseUrl =
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=first-blog";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});

Expand Down
3 changes: 2 additions & 1 deletion playwright-tests/tests/blog/blogv2.search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
waitForTestIdToBeVisible,
} from "../../testUtils.js";
import { setupBlogContentResponses } from "../../util/blogs.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

const baseUrl =
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=first-blog";
Expand All @@ -14,7 +15,7 @@ async function configureSearchAndCategoriesEnabled({
categoriesEnabled,
searchEnabled,
}) {
await page.route("http://localhost:20000", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
const postData = route.request().postDataJSON();

if (
Expand Down
3 changes: 2 additions & 1 deletion playwright-tests/tests/blog/blogv2.settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
decodeResultJSON,
encodeResultJSON,
} from "../../util/transaction.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

const baseUrl =
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=first-blog";
Expand All @@ -39,7 +40,7 @@ const blogPageThirdInstance =
"/devhub.near/widget/app?page=blogv2&community=webassemblymusic&id=this-is-the-blog-title-xfxkzh";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});

Expand Down
3 changes: 2 additions & 1 deletion playwright-tests/tests/blog/blogv2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from "@playwright/test";
import { pauseIfVideoRecording } from "../../testUtils.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { mockBlogs } from "../../util/blogs.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

const baseUrl =
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=first-blog";
Expand All @@ -11,7 +12,7 @@ const blogPage =
"/devhub.near/widget/app?page=blogv2&id=published-w5cj1y&community=webassemblymusic";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});

Expand Down
5 changes: 3 additions & 2 deletions playwright-tests/tests/community/addons.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { test, expect } = require("@playwright/test");
import { pauseIfVideoRecording } from "../../testUtils.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});
});
Expand Down Expand Up @@ -33,7 +34,7 @@ test.describe("Wallet is not connected", () => {
});

test("should load teams addon", async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});

Expand Down
8 changes: 5 additions & 3 deletions playwright-tests/tests/community/announcements.links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { test, expect } from "@playwright/test";
import { pauseIfVideoRecording, showPageURLInTest } from "../../testUtils.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { mockSocialIndexResponses } from "../../util/socialapi.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});
});
Expand Down Expand Up @@ -60,7 +61,7 @@ test.describe("Clipboard permissions", () => {
const copyUrlButton = await page
.locator('[data-component="near/widget/CopyUrlButton"]')
.first();
await expect(copyUrlButton).toBeVisible({ timeout: 10000 });
await expect(copyUrlButton).toBeVisible({ timeout: 20000 });
await copyUrlButton.hover();
await expect(await page.getByText("Copy URL to clipboard")).toBeVisible();
await copyUrlButton.click();
Expand Down Expand Up @@ -118,6 +119,7 @@ test.describe("Clipboard permissions", () => {
test("announcement should scroll into view and be highlighted", async ({
page,
}) => {
test.setTimeout(120000);
await page.goto(
"/devhub.near/widget/app?page=community&handle=webassemblymusic&tab=announcements&accountId=webassemblymusic.community.devhub.near&blockHeight=112244156"
);
Expand All @@ -127,7 +129,7 @@ test.describe("Clipboard permissions", () => {
const announcementElement = await viewer.locator(
"css=div#webassemblymusiccommunitydevhubnear112244156"
);
await expect(announcementElement).toBeVisible({ timeout: 10000 });
await expect(announcementElement).toBeVisible({ timeout: 20000 });

await expect(announcementElement).toContainText(
"WebAssembly Music is the concept of storing a full length track of music in a tiny file"
Expand Down
3 changes: 2 additions & 1 deletion playwright-tests/tests/community/announcements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
encodeResultJSON,
} from "../../util/transaction.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

test.beforeEach(async ({ page }) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});
});
Expand Down
8 changes: 5 additions & 3 deletions playwright-tests/tests/community/community.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from "@playwright/test";
import { pauseIfVideoRecording } from "../../testUtils.js";
import { mockDefaultTabs } from "../../util/addons.js";
import { MOCK_RPC_URL } from "../../util/rpcmock.js";

test("should load a community page if handle exists", async ({ page }) => {
await page.goto(
Expand Down Expand Up @@ -45,7 +46,7 @@ test.describe("Wallet is connected", () => {
test("should allow connected user to post from community page", async ({
page,
}) => {
await page.route("http://localhost:20000/", async (route) => {
await page.route(MOCK_RPC_URL, async (route) => {
await mockDefaultTabs(route);
});
test.setTimeout(60000);
Expand Down Expand Up @@ -213,6 +214,7 @@ test.describe("Is DevHUB platform community admin", () => {
});

test("should configure github addon", async ({ page }) => {
test.setTimeout(120000);
await page.goto(
"/devhub.near/widget/app?page=community&handle=devhub-platform&tab=github"
);
Expand All @@ -223,7 +225,7 @@ test.describe("Is DevHUB platform community admin", () => {
await pauseIfVideoRecording(page);
await expect(
await page.getByText("GitHub board configuration")
).toBeVisible();
).toBeVisible({ timeout: 10000 });

await expect(
await page.getByRole("button", { name: "Save" })
Expand All @@ -244,7 +246,7 @@ test.describe("Is DevHUB platform community admin", () => {
const boardTitleField = await board.locator(
'input[placeholder="👀 Review"]'
);
await boardTitleField.scrollIntoViewIfNeeded();
await boardTitleField.scrollIntoViewIfNeeded({ timeout: 20000 });
await boardTitleField.fill("Bugs");
await pauseIfVideoRecording(page);
const labelsInput = await board.locator(".rbt-input-multi");
Expand Down
Loading

0 comments on commit 4af0f4d

Please sign in to comment.