Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions extension/e2e-tests/helpers/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const stubTokenPrices = async (page: Page | BrowserContext) => {
});
};

export const stubAccountBalances = async (page: Page) => {
export const stubAccountBalances = async (page: Page, xlmBalance?: string) => {
await page.route("**/account-balances/**", async (route) => {
const json = {
balances: {
Expand All @@ -143,8 +143,8 @@ export const stubAccountBalances = async (page: Page) => {
type: "native",
code: "XLM",
},
total: "9697.8556678",
available: "9697.8556678",
total: xlmBalance || "9697.8556678",
available: xlmBalance || "9697.8556678",
sellingLiabilities: "0",
buyingLiabilities: "0",
minimumBalance: "1",
Expand Down
225 changes: 223 additions & 2 deletions extension/e2e-tests/loadAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test("Load accounts on standalone network", async ({
await expect(page.getByTestId("account-assets")).toContainText("XLM");
});

test("Switches account and fetches correct balances", async ({
test("Switches account and fetches correct balances while clearing cache", async ({
page,
extensionId,
context,
Expand All @@ -74,6 +74,227 @@ test("Switches account and fetches correct balances", async ({
.textContent();

await expect(account1XlmBalance).not.toEqual(account2XlmBalance);

// go back to account 1 and make sure we do a fresh balance fetch
await page.route("**/account-balances/**", async (route) => {
const json = {
balances: {
native: {
token: {
type: "native",
code: "XLM",
},
total: "999111",
available: "99911",
sellingLiabilities: "0",
buyingLiabilities: "0",
minimumBalance: "1",
blockaidData: {
result_type: "Benign",
malicious_score: "0.0",
attack_types: {},
chain: "stellar",
address: "",
metadata: {
type: "",
},
fees: {},
features: [],
trading_limits: {},
financial_stats: {},
},
},
},
isFunded: true,
subentryCount: 0,
error: {
horizon: null,
soroban: null,
},
};

await route.fulfill({ json });
});

await page.getByTestId("account-view-account-name").click();
await page.getByText("Account 1").click();
const updatedAccount1XlmBalance = await page
.getByTestId("asset-amount")
.textContent();
await expect(updatedAccount1XlmBalance).not.toEqual(account1XlmBalance);
await expect(updatedAccount1XlmBalance).toEqual("999,111");
});

test("Switches network and fetches correct balances while clearing cache", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);

await page.route("**/account-balances/**", async (route) => {
let json = {};

if (route.request().url().includes("TESTNET")) {
json = {
balances: {
native: {
token: {
type: "native",
code: "XLM",
},
total: "2",
available: "2",
sellingLiabilities: "0",
buyingLiabilities: "0",
minimumBalance: "1",
blockaidData: {
result_type: "Benign",
malicious_score: "0.0",
attack_types: {},
chain: "stellar",
address: "",
metadata: {
type: "",
},
fees: {},
features: [],
trading_limits: {},
financial_stats: {},
},
},
},
isFunded: true,
subentryCount: 0,
error: {
horizon: null,
soroban: null,
},
};
} else {
json = {
balances: {
native: {
token: {
type: "native",
code: "XLM",
},
total: "1",
available: "1",
sellingLiabilities: "0",
buyingLiabilities: "0",
minimumBalance: "1",
blockaidData: {
result_type: "Benign",
malicious_score: "0.0",
attack_types: {},
chain: "stellar",
address: "",
metadata: {
type: "",
},
fees: {},
features: [],
trading_limits: {},
financial_stats: {},
},
},
},
isFunded: true,
subentryCount: 0,
error: {
horizon: null,
soroban: null,
},
};
}

await route.fulfill({ json });
});

test.slow();
await loginToTestAccount({ page, extensionId });
await expect(page.getByTestId("account-assets")).toContainText("XLM");
await expect(page.getByTestId("asset-amount")).toHaveText("2");

await page.getByTestId("network-selector-open").click();
await page.getByText("Main Net").click();

await expect(page.getByTestId("asset-amount")).toHaveText("1");

// now go back to Testnet and make sure we do a fresh balance fetch
await page.route("**/account-balances/**", async (route) => {
const json = {
balances: {
native: {
token: {
type: "native",
code: "XLM",
},
total: "999111",
available: "99911",
sellingLiabilities: "0",
buyingLiabilities: "0",
minimumBalance: "1",
blockaidData: {
result_type: "Benign",
malicious_score: "0.0",
attack_types: {},
chain: "stellar",
address: "",
metadata: {
type: "",
},
fees: {},
features: [],
trading_limits: {},
financial_stats: {},
},
},
},
isFunded: true,
subentryCount: 0,
error: {
horizon: null,
soroban: null,
},
};

await route.fulfill({ json });
});
await page.getByTestId("network-selector-open").click();
await page.getByText("Test Net").click();
await expect(page.getByTestId("asset-amount")).toHaveText("999,111");
});

test("Account Balances should be loaded once and cached", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);

test.slow();
await loginToTestAccount({ page, extensionId });

let accountBalancesRequestWasMade = false;
page.on("request", (request) => {
if (request.url().includes("/account-balances/")) {
accountBalancesRequestWasMade = true;
}
});

await page.getByTestId("account-options-dropdown").click();
await page.getByText("Settings").click();
await page.getByTestId("BackButton").click();
await expect(accountBalancesRequestWasMade).toBeFalsy();
});

test("Switches account without password prompt", async ({
Expand All @@ -94,7 +315,7 @@ test("Switches account without password prompt", async ({
await page.getByText("Account 2").click();

await page.getByTestId("account-options-dropdown").click();
await page.getByText("Manage assets").click({ force: true });
await page.getByText("Manage assets").click();

await expect(page.getByText("Your assets")).toBeVisible();
});
Expand Down
49 changes: 39 additions & 10 deletions extension/e2e-tests/sendPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
stubTokenPrices,
} from "./helpers/stubs";

const MUXED_ACCOUNT_ADDRESS =
"MCCRNOIMODZT7HVQA3NM46YMLOBAXMSMHK3XXIN62CTWIPPP3J2E4AAAAAAAAAAAAEIAM";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I accidentally funded the muxed test acct, so creating a new one here


test("Swap doesn't throw error when account is unfunded", async ({
page,
extensionId,
Expand Down Expand Up @@ -202,11 +205,7 @@ test("Send doesn't throw error when creating muxed account", async ({
await page.getByTestId("nav-link-send").click({ force: true });

await expect(page.getByText("Send")).toBeVisible();
await page
.getByTestId("send-to-input")
.fill(
"MAUPPMNJUS76SG5NA6UXVCSO5HYVAJT422LBISV6LMCX37OIEPDJGAAAAAAAAAAAAF54C",
);
await page.getByTestId("send-to-input").fill(MUXED_ACCOUNT_ADDRESS);
await expect(
page.getByText("The destination account doesn’t exist."),
).toBeVisible();
Expand All @@ -227,11 +226,7 @@ test("Send can review formatted inputs", async ({ page, extensionId }) => {
await page.getByTestId("nav-link-send").click({ force: true });

await expect(page.getByText("Send")).toBeVisible();
await page
.getByTestId("send-to-input")
.fill(
"MAUPPMNJUS76SG5NA6UXVCSO5HYVAJT422LBISV6LMCX37OIEPDJGAAAAAAAAAAAAF54C",
);
await page.getByTestId("send-to-input").fill(MUXED_ACCOUNT_ADDRESS);
await expect(
page.getByText("The destination account doesn’t exist."),
).toBeVisible();
Expand Down Expand Up @@ -298,9 +293,17 @@ test("Send XLM payments to recent federated addresses", async ({
await submitAction.waitFor({ state: "visible" });
await submitAction.click({ force: true });

let accountBalancesRequestWasMade = false;
page.on("request", (request) => {
if (request.url().includes("/account-balances/")) {
accountBalancesRequestWasMade = true;
}
});

await expect(page.getByText("Sent!")).toBeVisible({
timeout: 60000,
});
expect(accountBalancesRequestWasMade).toBeTruthy();
});

test("Send XLM payment to C address", async ({ page, extensionId }) => {
Expand Down Expand Up @@ -329,9 +332,17 @@ test("Send XLM payment to C address", async ({ page, extensionId }) => {

await page.getByTestId(`SubmitAction`).click({ force: true });

let accountBalancesRequestWasMade = false;
page.on("request", (request) => {
if (request.url().includes("/account-balances/")) {
accountBalancesRequestWasMade = true;
}
});

await expect(page.getByText("Sent!")).toBeVisible({
timeout: 60000,
});
expect(accountBalancesRequestWasMade).toBeTruthy();
});

test("Send XLM payment to M address", async ({ page, extensionId }) => {
Expand Down Expand Up @@ -362,9 +373,18 @@ test("Send XLM payment to M address", async ({ page, extensionId }) => {
await submitButton.scrollIntoViewIfNeeded();
await submitButton.click();

let accountBalancesRequestWasMade = false;
page.on("request", (request) => {
if (request.url().includes("/account-balances/")) {
accountBalancesRequestWasMade = true;
}
});

await expect(page.getByText("Sent!")).toBeVisible({
timeout: 60000,
});

expect(accountBalancesRequestWasMade).toBeTruthy();
});

test.skip("Send SAC to C address", async ({ page, extensionId }) => {
Expand Down Expand Up @@ -492,9 +512,18 @@ test("Send token payment to C address", async ({ page, extensionId }) => {

await page.getByTestId(`SubmitAction`).click({ force: true });

let accountBalancesRequestWasMade = false;
page.on("request", (request) => {
if (request.url().includes("/account-balances/")) {
accountBalancesRequestWasMade = true;
}
});

await expect(page.getByText("Sent!")).toBeVisible({
timeout: 60000,
});

expect(accountBalancesRequestWasMade).toBeTruthy();
});

test.afterAll(async ({ page, extensionId }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ describe("useGetAssetDomainsWithBalances (cached path)", () => {
publicKey: TEST_PUBLIC_KEY,
},
cache: {
balanceData: { [publicKey]: cachedBalanceData },
balanceData: {
[TESTNET_NETWORK_DETAILS.network]: { [publicKey]: cachedBalanceData },
},
icons: cachedIcons,
tokenLists: tokenListData,
homeDomains: {
Expand Down
4 changes: 3 additions & 1 deletion extension/src/helpers/__tests__/useGetBalances.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe("useGetBalances (cached path)", () => {

const preloadedState = {
cache: {
balanceData: { [publicKey]: cachedBalanceData },
balanceData: {
[TESTNET_NETWORK_DETAILS.network]: { [publicKey]: cachedBalanceData },
},
icons: cachedIcons,
tokenLists: tokenListData,
},
Expand Down
Loading