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

Set new Tezos RPC nodes #2163

Merged
merged 4 commits into from
Dec 3, 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
2 changes: 1 addition & 1 deletion apps/embed-iframe-mainnet/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"headers": [
{
"key": "Content-Security-Policy",
"value": "default-src 'self'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' https://fonts.gstatic.com; script-src 'self'; object-src 'none'; connect-src 'self' https://umamiwallet.com https://www.googleapis.com https://graph.facebook.com https://kukai.eu.auth0.com https://fnd.web3auth.io https://*.node.web3auth.io https://*.tor.us https://prod.tcinfra.net https://api.mainnet.tzkt.io https://vitals.vercel-insights.com; img-src 'self' data:; frame-ancestors 'self' https://kanvas-poa.vercel.app https://kanvas-poa-git-poa-release-trili-tech.vercel.app"
"value": "default-src 'self'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' https://fonts.gstatic.com; script-src 'self'; object-src 'none'; connect-src 'self' https://umamiwallet.com https://www.googleapis.com https://graph.facebook.com https://mainnet.tezos.ecadinfra.com https://kukai.eu.auth0.com https://fnd.web3auth.io https://*.node.web3auth.io https://*.tor.us https://prod.tcinfra.net https://api.mainnet.tzkt.io https://vitals.vercel-insights.com; img-src 'self' data:; frame-ancestors 'self' https://kanvas-poa.vercel.app https://kanvas-poa-git-poa-release-trili-tech.vercel.app"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/embed-iframe/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"headers": [
{
"key": "Content-Security-Policy",
"value": "default-src 'self'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' https://fonts.gstatic.com; script-src 'self'; object-src 'none'; connect-src 'self' https://umamiwallet.com https://www.googleapis.com https://graph.facebook.com https://kukai.eu.auth0.com https://fnd.web3auth.io https://*.node.web3auth.io https://*.tor.us https://ghostnet.ecadinfra.com https://api.ghostnet.tzkt.io https://vitals.vercel-insights.com; img-src 'self' data:"
"value": "default-src 'self'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' https://fonts.gstatic.com; script-src 'self'; object-src 'none'; connect-src 'self' https://umamiwallet.com https://www.googleapis.com https://graph.facebook.com https://kukai.eu.auth0.com https://fnd.web3auth.io https://*.node.web3auth.io https://*.tor.us https://ghostnet.tezos.ecadinfra.com https://api.ghostnet.tzkt.io https://vitals.vercel-insights.com; img-src 'self' data:"
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/AccountCard/AccountBalance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe("<AccountBalance />", () => {

expect(button).toBeVisible();

await act(() => user.click(button));
await waitFor(async () => {
await act(() => user.click(button));
});

await waitFor(() =>
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ describe("<DeriveMnemonicAccountModal />", () => {
await act(() => user.type(screen.getByLabelText("Account name (Optional)"), newAccount.label));
await act(() => user.click(screen.getByRole("button", { name: "Continue" })));
await act(() => user.type(screen.getByLabelText("Password"), "test-password"));
await act(() => user.click(screen.getByRole("button", { name: "Submit" })));
await waitFor(async () => {
await act(() => user.click(screen.getByRole("button", { name: "Submit" })));
});

expect(mockDeriveMnemonicAccount).toHaveBeenCalledWith({
fingerPrint: account.seedFingerPrint,
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/CopyButton/CopyButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CopyButton } from "./CopyButton";
import { act, render, screen, userEvent } from "../../testUtils";
import { act, render, screen, userEvent, waitFor } from "../../testUtils";

describe("<CopyButton />", () => {
it("copies the value to the clipboard", async () => {
Expand All @@ -8,7 +8,9 @@ describe("<CopyButton />", () => {

render(<CopyButton value="hello">Copy</CopyButton>);

await act(() => user.click(screen.getByTestId("copy-button")));
await waitFor(async () => {
await act(() => user.click(screen.getByTestId("copy-button")));
});

expect(navigator.clipboard.writeText).toHaveBeenCalledWith("hello");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MasterPasswordModal } from "./MasterPasswordModal";
import { renderInModal, screen, userEvent } from "../../testUtils";
import { renderInModal, screen, userEvent, waitFor } from "../../testUtils";

const mockOnSubmit = jest.fn();

Expand All @@ -9,9 +9,16 @@ describe("<MasterPasswordModal />", () => {
await renderInModal(<MasterPasswordModal onSubmit={mockOnSubmit} />);

await user.type(screen.getByLabelText("Password"), "testpassword");
await user.click(screen.getByRole("button", { name: "Submit" }));
await waitFor(
async () => {
await user.click(screen.getByRole("button", { name: "Submit" }));
},
{
timeout: 5000,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need timeout here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried act like in the other tests?

}
);

expect(mockOnSubmit).toHaveBeenCalledWith({ password: "testpassword" });
await waitFor(() => expect(mockOnSubmit).toHaveBeenCalledWith({ password: "testpassword" }));
});

it("shows validation error when submitting without a password", async () => {
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/Menu/AdvancedMenu/AdvancedMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { mockImplicitAccount } from "@umami/core";
import { type UmamiStore, accountsActions, addTestAccount, makeStore } from "@umami/state";

import { AdvancedMenu } from "./AdvancedMenu";
import { dynamicDrawerContextMock, renderInDrawer, screen, userEvent } from "../../../testUtils";
import {
dynamicDrawerContextMock,
renderInDrawer,
screen,
userEvent,
waitFor,
} from "../../../testUtils";
import { ChangePasswordMenu } from "../ChangePasswordMenu/ChangePasswordMenu";
import { ErrorLogsMenu } from "../ErrorLogsMenu/ErrorLogsMenu";
import { NetworkMenu } from "../NetworkMenu/NetworkMenu";
Expand Down Expand Up @@ -35,7 +41,9 @@ describe("<AdvancedMenu />", () => {

await renderInDrawer(<AdvancedMenu />, store);

await userEvent.click(screen.getByText(label));
await waitFor(async () => {
await userEvent.click(screen.getByText(label));
});
expect(openWith).toHaveBeenCalledWith(<Component />);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ describe("<ImportBackupTab />", () => {

await act(() => user.upload(screen.getByTestId("file-input"), file));
await act(() => user.type(screen.getByLabelText("Password"), "wrong password"));
await act(() => user.click(screen.getByRole("button", { name: "Import Wallet" })));

await waitFor(async () => {
await act(() => user.click(screen.getByRole("button", { name: "Import Wallet" })));
});

await waitFor(() => expect(mockToast).toHaveBeenCalledTimes(1));
expect(mockToast).toHaveBeenCalledWith({
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/SendFlow/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ describe("SendFlow utils", () => {
render(<TestComponent onSubmit={mockSingle} />);

await waitFor(() => expect(screen.getByText("Preview")).toBeEnabled());
await act(() => user.click(screen.getByText("Preview")));

await waitFor(async () => {
await act(() => user.click(screen.getByText("Preview")));
});

expect(mockSingle).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type PermissionRequestOutput,
PermissionScope,
} from "@airgap/beacon-wallet";
import { fireEvent } from "@testing-library/react";
import { fireEvent, waitFor } from "@testing-library/react";
import { mockMnemonicAccount } from "@umami/core";
import { type UmamiStore, WalletClient, addTestAccounts, makeStore } from "@umami/state";

Expand Down Expand Up @@ -85,7 +85,9 @@ describe("<PermissionRequestModal />", () => {
// grant permission
const grantButton = screen.getByRole("button", { name: "Allow" });
expect(grantButton).toBeEnabled();
await act(() => user.click(grantButton));
await waitFor(async () => {
await act(() => user.click(grantButton));
});

expect(store.getState().beacon).toEqual({
[SENDER_ID]: {
Expand Down
59 changes: 51 additions & 8 deletions apps/web/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,45 @@ import { mockToast } from "@umami/state";
import { mockLocalStorage } from "@umami/test-utils";
import { setupJestCanvasMock } from "jest-canvas-mock";

const writeText = jest.fn();

Object.assign(navigator, {
clipboard: {
writeText,
},
});

const XMLHttpRequestMock = jest.fn(() => ({
open: jest.fn(),
send: jest.fn(),
setRequestHeader: jest.fn(),
readyState: 4,
status: 200,
responseText: "",
onload: jest.fn(),
onerror: jest.fn(),
ontimeout: jest.fn(),
upload: {
onprogress: jest.fn(),
},
}));

Object.defineProperties(XMLHttpRequestMock, {
UNSENT: { value: 0 },
OPENED: { value: 1 },
HEADERS_RECEIVED: { value: 2 },
LOADING: { value: 3 },
DONE: { value: 4 },
});

XMLHttpRequestMock.prototype = {
open: jest.fn(),
send: jest.fn(),
setRequestHeader: jest.fn(),
};

global.XMLHttpRequest = XMLHttpRequestMock as unknown as typeof XMLHttpRequest;

const mockIntersectionObserver = class MockIntersectionObserver {
callback: jest.Mock;
options: jest.Mock;
Expand All @@ -30,14 +69,6 @@ jest.doMock("@chakra-ui/react", () => ({
useColorMode: () => ({ colorMode: "light", toggleColorMode: jest.fn() }),
}));

Object.defineProperties(global, {
crypto: { value: webcrypto, writable: true },
TextDecoder: { value: TextDecoder, writable: true },
TextEncoder: { value: TextEncoder, writable: true },
IntersectionObserver: { value: mockIntersectionObserver, writable: true, configurable: true },
fetch: { value: jest.fn(), writable: true },
});

jest.mock("./utils/persistor", () => ({
pause: jest.fn(),
}));
Expand All @@ -48,6 +79,18 @@ beforeEach(() => {
Object.defineProperty(window, "localStorage", {
value: mockLocalStorage(),
});

Object.defineProperties(global, {
crypto: { value: webcrypto, writable: true },
TextDecoder: { value: TextDecoder, writable: true },
TextEncoder: { value: TextEncoder, writable: true },
IntersectionObserver: { value: mockIntersectionObserver, writable: true, configurable: true },
fetch: { value: jest.fn(), writable: true },
});
});

afterEach(() => {
jest.clearAllMocks();
});

// TODO: fix act warnings
Expand Down
61 changes: 61 additions & 0 deletions packages/state/src/migrations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mockLedgerAccount, mockMnemonicAccount, mockSecretKeyAccount } from "@umami/core";
import { mockImplicitAddress } from "@umami/tezos";
import { produce } from "immer";

import { accountsMigrations, mainStoreMigrations } from "./migrations";

Expand Down Expand Up @@ -97,6 +98,66 @@ describe("migrations", () => {
assets: { accountStates: {}, block: { level: 5 } },
});
});

describe("9", () => {
const migration = mainStoreMigrations[9];

it("should update rpcUrl for mainnet", () => {
const initialState = {
networks: {
current: { name: "mainnet", rpcUrl: "" },
available: [
{ name: "mainnet", rpcUrl: "" },
{ name: "ghostnet", rpcUrl: "" },
{ name: "testnet", rpcUrl: "" },
],
},
};

const expectedState = {
networks: {
current: { name: "mainnet", rpcUrl: "https://mainnet.tezos.ecadinfra.com" },
available: [
{ name: "mainnet", rpcUrl: "https://mainnet.tezos.ecadinfra.com" },
{ name: "ghostnet", rpcUrl: "https://ghostnet.tezos.ecadinfra.com" },
{ name: "testnet", rpcUrl: "" }, // Unchanged
],
},
};

const migratedState = produce(initialState, (draft: any) => migration(draft));

expect(migratedState).toEqual(expectedState);
});

it("should update rpcUrl for ghostnet", () => {
const initialState = {
networks: {
current: { name: "ghostnet", rpcUrl: "" },
available: [
{ name: "mainnet", rpcUrl: "" },
{ name: "ghostnet", rpcUrl: "" },
{ name: "testnet", rpcUrl: "" },
],
},
};

const expectedState = {
networks: {
current: { name: "ghostnet", rpcUrl: "https://ghostnet.tezos.ecadinfra.com" },
available: [
{ name: "mainnet", rpcUrl: "https://mainnet.tezos.ecadinfra.com" },
{ name: "ghostnet", rpcUrl: "https://ghostnet.tezos.ecadinfra.com" },
{ name: "testnet", rpcUrl: "" }, // Unchanged
],
},
};

const migratedState = produce(initialState, (draft: any) => migration(draft));

expect(migratedState).toEqual(expectedState);
});
});
});

describe("account migrations", () => {
Expand Down
18 changes: 17 additions & 1 deletion packages/state/src/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fromPairs, identity } from "lodash";

import { announcementInitialState as announcementsInitialState } from "./slices/announcement";

export const VERSION = 8;
export const VERSION = 9;

export const mainStoreMigrations = {
0: (state: any) =>
Expand Down Expand Up @@ -65,6 +65,21 @@ export const mainStoreMigrations = {
delete draft.assets["delegationLevels"];
}),
8: identity,
9: (state: any) =>
produce(state, (draft: any) => {
if (draft.networks.current.name === "mainnet") {
draft.networks.current.rpcUrl = "https://mainnet.tezos.ecadinfra.com";
} else if (draft.networks.current.name === "ghostnet") {
draft.networks.current.rpcUrl = "https://ghostnet.tezos.ecadinfra.com";
}
for (const network of draft.networks.available) {
if (network.name === "mainnet") {
network.rpcUrl = "https://mainnet.tezos.ecadinfra.com";
} else if (network.name === "ghostnet") {
network.rpcUrl = "https://ghostnet.tezos.ecadinfra.com";
}
}
}),
} as any;

export const accountsMigrations = {
Expand Down Expand Up @@ -104,4 +119,5 @@ export const accountsMigrations = {
}
});
}),
9: identity,
} as any;
4 changes: 2 additions & 2 deletions packages/tezos/src/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { type Network } from "./types";

export const MAINNET: Network = {
name: "mainnet",
rpcUrl: "https://prod.tcinfra.net/rpc/mainnet/",
rpcUrl: "https://mainnet.tezos.ecadinfra.com",
tzktApiUrl: "https://api.mainnet.tzkt.io",
tzktExplorerUrl: "https://tzkt.io",
buyTezUrl: "https://widget.wert.io",
};

export const GHOSTNET: Network = {
name: "ghostnet",
rpcUrl: "https://ghostnet.ecadinfra.com",
rpcUrl: "https://ghostnet.tezos.ecadinfra.com",
tzktApiUrl: "https://api.ghostnet.tzkt.io",
tzktExplorerUrl: "https://ghostnet.tzkt.io",
buyTezUrl: "https://faucet.ghostnet.teztnets.com/",
Expand Down
Loading