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

Sol 26 check balance switching networks e2e tests #29345

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2c8211f
chore: solana changes to work locally
ulissesferreira Nov 11, 2024
17c2be1
feat: added mocks for solana snap on flask tests
javiergarciavera Dec 2, 2024
0d894c6
feat: added create solana account test
javiergarciavera Dec 3, 2024
1338d6e
feat: updated snapId to not run locally
javiergarciavera Dec 3, 2024
236603b
feat: create-account scenario working
javiergarciavera Dec 3, 2024
cccee7d
feat: added create/remove solana account
javiergarciavera Dec 3, 2024
2144433
feat: fixed tests
javiergarciavera Dec 3, 2024
7fd295c
feat: tests done
javiergarciavera Dec 5, 2024
54a195a
feat: rebase main
javiergarciavera Dec 5, 2024
a0e0313
feat: rebase
javiergarciavera Dec 5, 2024
7960ad6
feat: revert builds.yml
javiergarciavera Dec 5, 2024
9f81c4e
Merge branch 'main' into create-solana-account-e2e
danjm Dec 6, 2024
7834f81
feat: upgraded solana snap version
javiergarciavera Dec 10, 2024
4df5496
feat: rebase
javiergarciavera Dec 10, 2024
6ad09a4
feat: upgrade snap version
javiergarciavera Dec 10, 2024
b5b3f4f
feat: added solana to the flask build
javiergarciavera Dec 10, 2024
3ba9c0d
feat: fix lint
javiergarciavera Dec 10, 2024
a2c10f5
feat: fixed flakiness
javiergarciavera Dec 10, 2024
3ff0057
feat: updated policy
javiergarciavera Dec 10, 2024
faa7e9d
feat: fix lint
javiergarciavera Dec 10, 2024
ea3683f
feat: fixes conflicts
javiergarciavera Dec 10, 2024
625f83f
feat: fix conflict
javiergarciavera Dec 10, 2024
cae684d
feat: fixed conflicts on yarn.lock
javiergarciavera Dec 10, 2024
6dac98b
feat: fix flakiness waiting for a component
javiergarciavera Dec 10, 2024
8dddaef
feat: fix flakiness
javiergarciavera Dec 10, 2024
0c4d836
feat: fixed flakiness
javiergarciavera Dec 10, 2024
45f6a7f
feat: added beforeEach to make sure there is no data from previous tests
javiergarciavera Dec 10, 2024
ec0f28a
feat: adding logs for debugging
javiergarciavera Dec 10, 2024
869945e
feat: lint
javiergarciavera Dec 10, 2024
952170c
Merge branch 'main' into create-solana-account-e2e
javiergarciavera Dec 10, 2024
290bd40
feat: commit signedg
javiergarciavera Dec 10, 2024
87ac7ce
Merge branch 'create-solana-account-e2e' of github.com:MetaMask/metam…
javiergarciavera Dec 10, 2024
64b1659
feat: added e2e logic and tests for network switching and check balan…
javiergarciavera Dec 11, 2024
6c02c40
feat: added more changes
javiergarciavera Dec 13, 2024
19be9b8
feat: rebasing main
javiergarciavera Dec 19, 2024
6d8bd52
feat: updated tests
javiergarciavera Dec 19, 2024
f828fb5
feat: added check balance test
javiergarciavera Dec 20, 2024
1bb3b56
feat: check balance working
javiergarciavera Dec 20, 2024
3f4fe20
feat: added another check balance scenario
javiergarciavera Dec 20, 2024
fb5fbc3
feat: check balances
javiergarciavera Dec 20, 2024
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"test:e2e:chrome:multi-provider": "MULTIPROVIDER=true SELENIUM_BROWSER=chrome node test/e2e/run-all.js --multi-provider",
"test:e2e:firefox": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js",
"test:e2e:firefox:flask": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js --build-type flask",
"test:e2e:single": "node test/e2e/run-e2e-test.js",
"test:e2e:single": "SELENIUM_BROWSER=chrome node test/e2e/run-e2e-test.js",
"ganache:start": "./development/run-ganache.sh",
"sentry:publish": "node ./development/sentry-publish.js",
"lint": "yarn lint:prettier && yarn lint:eslint && yarn lint:tsc && yarn lint:styles",
Expand Down Expand Up @@ -348,7 +348,7 @@
"@metamask/snaps-rpc-methods": "^11.7.0",
"@metamask/snaps-sdk": "^6.13.0",
"@metamask/snaps-utils": "^8.6.1",
"@metamask/solana-wallet-snap": "^1.0.3",
"@metamask/solana-wallet-snap": "^1.0.4",
"@metamask/transaction-controller": "^42.0.0",
"@metamask/user-operation-controller": "^19.0.0",
"@metamask/utils": "^10.0.1",
Expand Down
4 changes: 3 additions & 1 deletion privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"accounts.api.cx.metamask.io",
"acl.execution.metamask.io",
"api.blockchair.com",
"api.devnet.solana.com",
"api.lens.dev",
"api.segment.io",
"api.web3modal.com",
Expand Down Expand Up @@ -59,6 +60,7 @@
"sepolia.infura.io",
"signature-insights.api.cx.metamask.io",
"snaps.metamask.io",
"solana.rpc.grove.city",
"sourcify.dev",
"start.metamask.io",
"static.cx.metamask.io",
Expand All @@ -75,4 +77,4 @@
"user-storage.api.cx.metamask.io",
"verify.walletconnect.com",
"www.4byte.directory"
]
]
2 changes: 1 addition & 1 deletion shared/constants/multichain/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum MultichainNetworks {
BITCOIN = 'bip122:000000000019d6689c085ae165831e93',
BITCOIN_TESTNET = 'bip122:000000000933ea01ad0ee984209779ba',

SOLANA = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
SOLANA = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
SOLANA_DEVNET = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
SOLANA_TESTNET = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
}
Expand Down
51 changes: 51 additions & 0 deletions test/e2e/flask/solana/check-balance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Suite } from 'mocha';
import { strict as assert } from 'assert';
import HeaderNavbar from '../../page-objects/pages/header-navbar';import { LAMPORTS_PER_SOL, SOL_BALANCE, SOL_TO_USD_RATE, USD_BALANCE, withSolanaAccountSnap } from './common-solana';
import BitcoinHomepage from '../../page-objects/pages/home/bitcoin-homepage';


const EXPECTED_MAINNET_BALANCE_USD = `$${USD_BALANCE}`;

describe('Check tbalance', function (this: Suite) {
this.timeout(120000)
it('Just created Solana account shows 0 SOL when native token is enabled', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle(),},
async (driver) => {
await driver.refresh()
const homePage = new BitcoinHomepage(driver)
const balanceText = await homePage.getBalanceText()
assert.equal(balanceText, "0 SOL"); },
);
});
it('Just created Solana account shows 0 USD when native token is not enabled', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle(), solanaSupportEnabled: true, showNativeTokenAsMainBalance: false},
async (driver) => {
await driver.refresh()
const homePage = new BitcoinHomepage(driver)
const balanceText = await homePage.getBalanceText()
assert.equal(balanceText, "0 USD"); },
);
});
it('For a non 0 balance account - SOL balance', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle(), solanaSupportEnabled: true, showNativeTokenAsMainBalance: true, mockCalls: true},
async (driver) => {
await driver.refresh()
const homePage = new BitcoinHomepage(driver)
const balanceText = await homePage.getBalanceText()
assert.equal(balanceText, `${SOL_BALANCE/LAMPORTS_PER_SOL} SOL`); },
);
});
it.only('For a non 0 balance account - USD balance', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle(), solanaSupportEnabled: true, showNativeTokenAsMainBalance: false, mockCalls: true},
async (driver) => {
await driver.refresh()
const homePage = new BitcoinHomepage(driver)
const balanceText = await homePage.getBalanceText()
assert.equal(balanceText, `${(SOL_BALANCE/LAMPORTS_PER_SOL)*SOL_TO_USD_RATE} USD`); },
);
});
});
197 changes: 178 additions & 19 deletions test/e2e/flask/solana/common-solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,175 @@ import AccountListPage from '../../page-objects/pages/account-list-page';
import FixtureBuilder from '../../fixture-builder';
import { ACCOUNT_TYPE } from '../../page-objects/common';
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
import { DEFAULT_SOL_CONVERSION_RATE } from '../../constants';
import { withFixturesOptions } from '../../tests/swaps/shared';

const SOLANA_URL_REGEX = /^https:\/\/.*\.solana.*/u;

const SOLANA_URL_REGEX = /^https:\/\/.*\..*/u;
const SOLANA_PRICE_REGEX =
/^https:\/\/price-api\.metamask-institutional\.io\/v2\/chains\/solana:/u;
const SOLANA_BITCOIN_MIN_API =
/^https:\/\/min-api\.cryptocompare\.com\/data\/pricemulti/u;
export enum SendFlowPlaceHolders {
AMOUNT = 'Enter amount to send',
RECIPIENT = 'Enter receiving address',
LOADING = 'Preparing transaction',
}

export const SOL_BALANCE = 50000000000;

export const SOL_TO_USD_RATE = 225.88;

export const USD_BALANCE = SOL_BALANCE * SOL_TO_USD_RATE;

export const LAMPORTS_PER_SOL = 1_000_000_000;

export async function mockMultiCoinPrice(mockServer: Mockttp) {
return await mockServer.forGet(SOLANA_BITCOIN_MIN_API).thenCallback(() => {
console.log('Entra en api min ');
return {
statusCode: 200,
json: {
BTC: {
USD: 96155.06,
},
SOL: {
USD: 180.5,
},
},
};
});
}

export async function mockSolanaBalanceQuote(mockServer: Mockttp) {
const response = {
statusCode: 200,
json: {
result: {
context: {
apiVersion: '2.0.18',
slot: 308460925,
},
value: SOL_BALANCE,
},
id: 1337,
},
};
return await mockServer
.forPost(SOLANA_URL_REGEX)
.forPost('https://api.devnet.solana.com/')
.withJsonBodyIncluding({
method: 'getBalance',
})
.thenCallback(() => {
console.log('Entra y returning ', response);
return response;
});
}
export async function mockGetSignaturesForAddress(mockServer: Mockttp) {
console.log('Mocking getSignaturesForAddress call');
return await mockServer
.forPost(SOLANA_URL_REGEX)
.withBodyIncluding('getSignaturesForAddress')
.thenCallback(() => {
return {
statusCode: 200,
json: {
result: {
context: {
apiVersion: '2.0.15',
slot: 305352614,
result: [
{
blockTime: 1734620122,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'5THAXC3pHCRwwwrMHR6PJiSqFfgSkZrBhn59C7YEbTMVbiAnjZhqpPvJYs4v5aRcqUiokunfbdTgo9HLfv6bogNR',
slot: 348093552,
},
{
blockTime: 1734619950,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'5KHuDsTMjre6rWU5Qkf8ugG31PjWoZ8NbV21ThY8RwcHpn3dKbTafdizUkEj4sU2AfrRzVxgyGkX8MLxK5nWHJ6J',
slot: 348093088,
},
{
blockTime: 1734619916,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'2RcW9iJCGnYuGVbDbaDi93t2f2347a6gzjoQf9idDdfFTjHsC7yMYcUvGqNzouKgA8T8tdYqjNUtDf4vR4e9iUoF',
slot: 348092996,
},
{
blockTime: 1734619899,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'2kCcoXZxe14384c8JTvq1g63pSjmmyuDnye9y3ReBMEiaZeGWspsmooEdC4RoyzP6uTfaDyFpCupBAKXnZwXCKMg',
slot: 348092952,
},
{
blockTime: 1734619885,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'4fzwGY4Tw5C4nYMaVAY7e3ZMwz691CbT7By4F4YFdukzBxd7yspmZEHhBtuPhFrqLj1yBn6zpc4kh1GLzgcovEbx',
slot: 348092914,
},
value: 0,
},
{
blockTime: 1734619758,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'2vgL59tfVa2VJkf7kmsGhbdBFjHdspLa1wfL72zZqHfJuzhmKfqS4YoLofpMTnZzzZfiA6712pwURheMUh5S2RXd',
slot: 348092568,
},
{
blockTime: 1734619697,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'32fqeHudeNBuDmyCrmRemFppVPpWmXwT4cbfai5D7G2Vzah1BvVguLqkNuk9Pdu4xVyBD32dhnSV8AN9k4qnffSB',
slot: 348092404,
},
],
},
};
});
}

export async function mockSolanaRatesCall(mockServer: Mockttp) {
return await mockServer
.forGet(SOLANA_PRICE_REGEX)
.withQuery({ vsCurrency: 'usd' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
id: 'wrapped-solana',
price: 210.57,
marketCap: 0,
allTimeHigh: 263.68,
allTimeLow: 8.11,
totalVolume: 3141761864,
high1d: 218.26,
low1d: 200.85,
circulatingSupply: 0,
dilutedMarketCap: 124394527657,
marketCapPercentChange1d: 0,
priceChange1d: -7.68288033909846,
pricePercentChange1h: 0.5794201955743261,
pricePercentChange1d: -3.520101943578202,
pricePercentChange7d: -8.192700158252544,
pricePercentChange14d: -12.477367449577399,
pricePercentChange30d: -14.588630064677465,
pricePercentChange200d: 28.111509321033513,
pricePercentChange1y: 181.48381055890258,
},
};
});
Expand All @@ -41,23 +184,39 @@ export async function withSolanaAccountSnap(
{
title,
solanaSupportEnabled,
}: { title?: string; solanaSupportEnabled?: boolean },
showNativeTokenAsMainBalance,
mockCalls,
}: {
title?: string;
solanaSupportEnabled?: boolean;
showNativeTokenAsMainBalance?: boolean;
mockCalls?: boolean;
},
test: (driver: Driver, mockServer: Mockttp) => Promise<void>,
) {
console.log('Starting withSolanaAccountSnap');
let fixtures = new FixtureBuilder().withPreferencesControllerAndFeatureFlag({
solanaSupportEnabled: solanaSupportEnabled ?? true,
});
if (!showNativeTokenAsMainBalance) {
fixtures =
fixtures.withPreferencesControllerShowNativeTokenAsMainBalanceDisabled();
}
// withFixturesOptions.ganacheOptions.miner.blockTime = 10;
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
solanaSupportEnabled: solanaSupportEnabled ?? true,
})
.build(),
fixtures: fixtures.build(),
title,
dapp: true,
testSpecificMock: async (mockServer: Mockttp) => {
console.log('Setting up test-specific mocks');
return [await mockSolanaBalanceQuote(mockServer)];
},
testSpecificMock: async (mockServer: Mockttp) =>
mockCalls
? [
await mockSolanaBalanceQuote(mockServer),
await mockSolanaRatesCall(mockServer),
await mockGetSignaturesForAddress(mockServer),
await mockMultiCoinPrice(mockServer),
]
: [],
},
async ({ driver, mockServer }: { driver: Driver; mockServer: Mockttp }) => {
await loginWithBalanceValidation(driver);
Expand Down
41 changes: 41 additions & 0 deletions test/e2e/flask/solana/switching-network-accounts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Suite } from 'mocha';
import { strict as assert } from 'assert';
import HeaderNavbar from '../../page-objects/pages/header-navbar';
import AccountListPage from '../../page-objects/pages/account-list-page';
import { withSolanaAccountSnap } from './common-solana';
import { logging } from 'selenium-webdriver';

import SelectNetwork from '../../page-objects/pages/dialog/select-network';

describe('Switching between account from different networks', function (this: Suite) {
beforeEach(async function () {
// Setup code to run before each test
// For example, you can reset the application state or create a fresh environment
});

afterEach(async function () {
// Teardown code to run after each test
// For example, you can clean up any data created during the test
});
it('Switch from Solana account to another Network account', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
const logs = await driver.driver.manage().logs().get(logging.Type.BROWSER)
logs.forEach(log => {
console.log(`[${log.level.name}] ${log.message}`);
});
const headerNavbar = new HeaderNavbar(driver);
await headerNavbar.check_pageIsLoaded();
await headerNavbar.check_accountLabel('Solana 1');
assert.equal(await headerNavbar.isNetworkPickerEnabled(), false)
await headerNavbar.check_currentSelectedNetwork('Solana')
await headerNavbar.openAccountMenu()
const accountListPage = new AccountListPage(driver);
await accountListPage.selectAccount('Account 1')
assert.equal(await headerNavbar.isNetworkPickerEnabled(), true)
await headerNavbar.check_currentSelectedNetwork('Localhost 8545')
},
);
});
});
Loading
Loading