Skip to content

Commit

Permalink
feat: added check balance test
Browse files Browse the repository at this point in the history
  • Loading branch information
javiergarciavera committed Dec 20, 2024
1 parent 6d8bd52 commit f828fb5
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 36 deletions.
8 changes: 8 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,14 @@ class FixtureBuilder {
});
}

withUseNativeCurrencyAsPrimaryCurrency() {
return this.withPreferencesController({
preferences: {
useNativeCurrencyAsPrimaryCurrency: true,
},
});
}

build() {
this.fixture.meta = {
version: FIXTURE_STATE_METADATA_VERSION,
Expand Down
33 changes: 10 additions & 23 deletions test/e2e/flask/solana/check-balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,26 @@ import AccountListPage from '../../page-objects/pages/account-list-page';
import { SOL_BALANCE, USD_BALANCE, withSolanaAccountSnap } from './common-solana';
import { logging } from 'selenium-webdriver';
import SettingsPage from '../../page-objects/pages/settings/settings-page';
import { ACCOUNT_TYPE } from '../../page-objects/common';
import HomePage from '../../page-objects/pages/home/homepage';
import SolanaHomepage from '../../page-objects/pages/home/solana-homepage';

const EXPECTED_MAINNET_BALANCE_USD = `$${USD_BALANCE}`;

describe('Switching between account from different networks', function (this: Suite) {
this.timeout(120000)
it.only('Switch from Solana account to another Network account', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle() },
{ title: this.test?.fullTitle(),},
async (driver) => {
const headerNavbar = new HeaderNavbar(driver);
await headerNavbar.check_pageIsLoaded();
await headerNavbar.check_accountLabel('Solana 1');
const accountListPage = new AccountListPage(driver);
await accountListPage.check_accountValueAndSuffixDisplayed(
"0.00011294SOL",
);
const homePage = new SolanaHomepage(driver)
const balanceText = await homePage.getSolanaBalance()
console.log('BalanceText ', balanceText)
console.log('xpectedText ', "0 SOL")
assert.equal(balanceText, "0 SOL");
},
);

it('Show native token as main balance', async function () {
await withSolanaAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
const headerNavbar = new HeaderNavbar(driver);
await headerNavbar.check_pageIsLoaded();
await headerNavbar.check_accountLabel('Solana 1');
const accountListPage = new AccountListPage(driver);
await headerNavbar.openSettingsPage();
const settingsPage = new SettingsPage(driver);
await settingsPage.toggleBalanceSetting();
await settingsPage.closeSettingsPage()

},
);
});
});
});
109 changes: 99 additions & 10 deletions test/e2e/flask/solana/common-solana.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mockttp } from 'mockttp';
import { withFixtures, unlockWallet } from '../../helpers';
import { withFixtures } from '../../helpers';
import { Driver } from '../../webdriver/driver';
import HeaderNavbar from '../../page-objects/pages/header-navbar';
import AccountListPage from '../../page-objects/pages/account-list-page';
Expand All @@ -26,12 +26,24 @@ export const USD_BALANCE = SOL_BALANCE * SOL_TO_USD_RATE;

export async function mockSolanaBalanceQuote(mockServer: Mockttp) {
return await mockServer
.forPost(SOLANA_URL_REGEX)
.forPost('https://api.devnet.solana.com/')
.withJsonBodyIncluding({
method: 'getBalance',
})
.thenCallback(() => {
console.log('Entra?');
console.log('Entra y returning ', {
statusCode: 200,
json: {
result: {
context: {
apiVersion: '2.0.18',
slot: 308460925,
},
value: SOL_BALANCE,
},
id: 1337,
},
});
return {
statusCode: 200,
json: {
Expand All @@ -42,6 +54,84 @@ export async function mockSolanaBalanceQuote(mockServer: Mockttp) {
},
value: SOL_BALANCE,
},
id: 1337,
},
};
});
}
export async function mockGetSignaturesForAddress(mockServer: Mockttp) {
return await mockServer
.forGet(SOLANA_URL_REGEX)
.withBodyIncluding('getSignaturesForAddress')
.thenCallback(() => {
return {
statusCode: 200,
json: {
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,
},
{
blockTime: 1734619758,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'2vgL59tfVa2VJkf7kmsGhbdBFjHdspLa1wfL72zZqHfJuzhmKfqS4YoLofpMTnZzzZfiA6712pwURheMUh5S2RXd',
slot: 348092568,
},
{
blockTime: 1734619697,
confirmationStatus: 'finalized',
err: null,
memo: null,
signature:
'32fqeHudeNBuDmyCrmRemFppVPpWmXwT4cbfai5D7G2Vzah1BvVguLqkNuk9Pdu4xVyBD32dhnSV8AN9k4qnffSB',
slot: 348092404,
},
],
},
};
});
Expand Down Expand Up @@ -93,16 +183,15 @@ export async function withSolanaAccountSnap(
.withPreferencesControllerAndFeatureFlag({
solanaSupportEnabled: solanaSupportEnabled ?? true,
})
.withUseNativeCurrencyAsPrimaryCurrency()
.build(),
title,
dapp: true,
testSpecificMock: async (mockServer: Mockttp) => {
console.log('Setting up test-specific mocks');
return [
await mockSolanaBalanceQuote(mockServer),
await mockSolanaRatesCall(mockServer),
];
},
testSpecificMock: async (mockServer: Mockttp) => [
/*await mockSolanaBalanceQuote(mockServer),
await mockSolanaRatesCall(mockServer),
await mockGetSignaturesForAddress(mockServer),*/
],
},
async ({ driver, mockServer }: { driver: Driver; mockServer: Mockttp }) => {
await loginWithBalanceValidation(driver);
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/page-objects/flows/login.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const loginWithBalanceValidation = async (
localBlockchainServer,
);
} else {
await homePage.check_expectedBalanceIsDisplayed();
console.log('Entra aqui')
await homePage.check_expectedBalanceIsDisplayed('0', 'SOL');
}
};
5 changes: 3 additions & 2 deletions test/e2e/page-objects/pages/account-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,16 @@ class AccountListPage {
);
const solBalanceValue = await this.driver.findElement(
this.accountValueAndSuffix,
200000,
);
console.log(solBalanceValue.getText());
console.log(await solBalanceValue.getText());
await this.driver.waitForSelector(
{
css: this.accountValueAndSuffix,
text: expectedValueAndSuffix,
},
{
timeout: 60000,
timeout: 20000,
},
);
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/page-objects/pages/home/asset-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class AssetListPage {
const allNetworksValueElement = await this.driver.findElement(
this.currentNetworksTotal,
);
console.log('Aqui llega o no?')
const value = await allNetworksValueElement.getText();
return value;
}
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/page-objects/pages/home/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ class HomePage {
}
await this.check_expectedBalanceIsDisplayed(expectedBalance);
}

async getBalanceText(): Promise<string> {
const balanceValue = await this.driver.waitForSelector(this.balance, {
timeout: 120000,
});
const singleBalanceText = await balanceValue.getText();
return singleBalanceText;
}
}

export default HomePage;
69 changes: 69 additions & 0 deletions test/e2e/page-objects/pages/home/solana-homepage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import HomePage from './homepage';

class SolanaHomepage extends HomePage {
protected readonly solanaBalance =
'.coin-overview__primary-balance';

private readonly bridgeButton = {
text: 'Bridge',
tag: 'button',
};

private readonly buySellButton = '[data-testid="coin-overview-buy"]';

private readonly receiveButton = '[data-testid="coin-overview-receive"]';

protected readonly sendButton = '[data-testid="coin-overview-send"]';

private readonly swapButton = {
text: 'Swap',
tag: 'button',
};

/**
* Checks if the expected solana balance is displayed on homepage.
*
* @param expectedBalance - The expected bitcoin balance to be displayed. Defaults to '0'.
*/
async getSolanaBalance(
expectedBalance: number = 0,
): Promise<string> {
console.log(
`Check if expected Solana balance is displayed: ${expectedBalance} SOL`,
);
const balanceValue = await this.driver.waitForSelector(this.solanaBalance, { timeout: 120000 })
const singleBalanceText = await balanceValue.getText();
const trimmedBalance = singleBalanceText.replaceAll(/\s+/g, ' ').trim()
return singleBalanceText.replaceAll(/\s+/g, ' ').trim()
}

/**
* Checks if the receive button is enabled on bitcoin account homepage.
*/
async check_isReceiveButtonEnabled(): Promise<boolean> {
try {
await this.driver.findClickableElement(this.receiveButton, 1000);
} catch (e) {
console.log('Receive button not enabled', e);
return false;
}
console.log('Receive button is enabled');
return true;
}

/**
* Checks if the swap button is enabled on bitcoin account homepage.
*/
async check_isSwapButtonEnabled(): Promise<boolean> {
try {
await this.driver.findClickableElement(this.swapButton, 1000);
} catch (e) {
console.log('Swap button not enabled', e);
return false;
}
console.log('Swap button is enabled');
return true;
}
}

export default SolanaHomepage;

0 comments on commit f828fb5

Please sign in to comment.