mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
[e2e] Using ganache requests to getBalance and getAccounts (#18215)
* Using ganache requests to get balances * Replace getBalance getAccounts with ganache funcs * Add secondary ganache server to testsuite
This commit is contained in:
parent
33a25cd6e9
commit
c940f744a5
@ -23,6 +23,27 @@ class Ganache {
|
|||||||
return this._server.provider;
|
return this._server.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAccounts() {
|
||||||
|
return await this.getProvider().request({
|
||||||
|
method: 'eth_accounts',
|
||||||
|
params: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBalance() {
|
||||||
|
const accounts = await this.getAccounts();
|
||||||
|
const balanceHex = await this.getProvider().request({
|
||||||
|
method: 'eth_getBalance',
|
||||||
|
params: [accounts[0], 'latest'],
|
||||||
|
});
|
||||||
|
const balanceInt = parseInt(balanceHex, 16) / 10 ** 18;
|
||||||
|
|
||||||
|
const balanceFormatted =
|
||||||
|
balanceInt % 1 === 0 ? balanceInt : balanceInt.toFixed(4);
|
||||||
|
|
||||||
|
return balanceFormatted;
|
||||||
|
}
|
||||||
|
|
||||||
async quit() {
|
async quit() {
|
||||||
if (!this._server) {
|
if (!this._server) {
|
||||||
throw new Error('Server not running yet');
|
throw new Error('Server not running yet');
|
||||||
|
@ -145,6 +145,8 @@ async function withFixtures(options, testSuite) {
|
|||||||
driver: driverProxy ?? driver,
|
driver: driverProxy ?? driver,
|
||||||
mockServer,
|
mockServer,
|
||||||
contractRegistry,
|
contractRegistry,
|
||||||
|
ganacheServer,
|
||||||
|
secondaryGanacheServer,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
failed = true;
|
failed = true;
|
||||||
|
@ -25,7 +25,7 @@ describe('Deploy contract and call contract methods', function () {
|
|||||||
smartContract,
|
smartContract,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver, contractRegistry }) => {
|
async ({ driver, contractRegistry, ganacheServer }) => {
|
||||||
const contractAddress = await contractRegistry.getContractAddress(
|
const contractAddress = await contractRegistry.getContractAddress(
|
||||||
smartContract,
|
smartContract,
|
||||||
);
|
);
|
||||||
@ -99,15 +99,15 @@ describe('Deploy contract and call contract methods', function () {
|
|||||||
|
|
||||||
// renders the correct ETH balance
|
// renders the correct ETH balance
|
||||||
await driver.switchToWindow(extension);
|
await driver.switchToWindow(extension);
|
||||||
const balance = await driver.waitForSelector(
|
const balance = await ganacheServer.getBalance();
|
||||||
|
const balanceElement = await driver.waitForSelector(
|
||||||
{
|
{
|
||||||
css: '[data-testid="eth-overview__primary-currency"]',
|
css: '[data-testid="eth-overview__primary-currency"]',
|
||||||
text: '21.',
|
text: balance,
|
||||||
},
|
},
|
||||||
{ timeout: 10000 },
|
{ timeout: 10000 },
|
||||||
);
|
);
|
||||||
const tokenAmount = await balance.getText();
|
assert.equal(`${balance}\nETH`, await balanceElement.getText());
|
||||||
assert.ok(/^21.*\s*ETH.*$/u.test(tokenAmount));
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -84,7 +84,7 @@ describe('MetaMask Responsive UI', function () {
|
|||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
failOnConsoleError: false,
|
failOnConsoleError: false,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
|
|
||||||
// Import Secret Recovery Phrase
|
// Import Secret Recovery Phrase
|
||||||
@ -104,9 +104,10 @@ describe('MetaMask Responsive UI', function () {
|
|||||||
await driver.press('#confirm-password', driver.Key.ENTER);
|
await driver.press('#confirm-password', driver.Key.ENTER);
|
||||||
|
|
||||||
// balance renders
|
// balance renders
|
||||||
|
const balance = await ganacheServer.getBalance();
|
||||||
await driver.waitForSelector({
|
await driver.waitForSelector({
|
||||||
css: '[data-testid="eth-overview__primary-currency"]',
|
css: '[data-testid="eth-overview__primary-currency"]',
|
||||||
text: '1000 ETH',
|
text: `${balance} ETH`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -228,7 +228,7 @@ describe('Navigate transactions', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
@ -236,10 +236,11 @@ describe('Navigate transactions', function () {
|
|||||||
// reject transactions
|
// reject transactions
|
||||||
await driver.clickElement({ text: 'Reject 4', tag: 'a' });
|
await driver.clickElement({ text: 'Reject 4', tag: 'a' });
|
||||||
await driver.clickElement({ text: 'Reject all', tag: 'button' });
|
await driver.clickElement({ text: 'Reject all', tag: 'button' });
|
||||||
const balance = await driver.findElement(
|
const balance = await ganacheServer.getBalance();
|
||||||
|
const balanceElement = await driver.findElement(
|
||||||
'[data-testid="eth-overview__primary-currency"]',
|
'[data-testid="eth-overview__primary-currency"]',
|
||||||
);
|
);
|
||||||
assert.ok(/^25\sETH$/u.test(await balance.getText()));
|
assert.equal(`${balance}\nETH`, await balanceElement.getText());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -260,7 +260,7 @@ describe('MetaMask onboarding', function () {
|
|||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
|
|
||||||
async ({ driver }) => {
|
async ({ driver, secondaryGanacheServer }) => {
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await importSRPOnboardingFlow(driver, testSeedPhrase, testPassword);
|
await importSRPOnboardingFlow(driver, testSeedPhrase, testPassword);
|
||||||
|
|
||||||
@ -300,10 +300,11 @@ describe('MetaMask onboarding', function () {
|
|||||||
);
|
);
|
||||||
assert.equal(await networkDisplay.getText(), networkName);
|
assert.equal(await networkDisplay.getText(), networkName);
|
||||||
|
|
||||||
const balance1 = await driver.findElement(
|
const balance = await secondaryGanacheServer.getBalance();
|
||||||
|
const balanceElement = await driver.findElement(
|
||||||
'[data-testid="eth-overview__primary-currency"]',
|
'[data-testid="eth-overview__primary-currency"]',
|
||||||
);
|
);
|
||||||
assert.ok(/^10\sETH$/u.test(await balance1.getText()));
|
assert.equal(`${balance}\nETH`, await balanceElement.getText());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,6 @@ describe('Permissions', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -21,7 +20,9 @@ describe('Permissions', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
@ -13,7 +13,6 @@ describe('Personal sign', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -23,7 +22,9 @@ describe('Personal sign', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
@ -24,7 +24,9 @@ describe('MetaMask', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
@ -60,10 +62,7 @@ describe('MetaMask', function () {
|
|||||||
|
|
||||||
assert.equal(await switchedNetworkDiv.getText(), '0x1');
|
assert.equal(await switchedNetworkDiv.getText(), '0x1');
|
||||||
assert.equal(await switchedChainIdDiv.getText(), '0x1');
|
assert.equal(await switchedChainIdDiv.getText(), '0x1');
|
||||||
assert.equal(
|
assert.equal(await accountsDiv.getText(), publicAddress);
|
||||||
await accountsDiv.getText(),
|
|
||||||
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -129,13 +129,14 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
|
|||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
failOnConsoleError: false,
|
failOnConsoleError: false,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
const balanceAfterDeployment = await ganacheServer.getBalance();
|
||||||
await driver.waitForSelector({
|
await driver.waitForSelector({
|
||||||
css: '[data-testid="eth-overview__primary-currency"]',
|
css: '[data-testid="eth-overview__primary-currency"]',
|
||||||
text: '24.9977 ETH',
|
text: `${balanceAfterDeployment} ETH`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send TST
|
// Send TST
|
||||||
@ -194,13 +195,14 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
|
|||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
failOnConsoleError: false,
|
failOnConsoleError: false,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
const balanceAfterDeployment = await ganacheServer.getBalance();
|
||||||
await driver.waitForSelector({
|
await driver.waitForSelector({
|
||||||
css: '[data-testid="eth-overview__primary-currency"]',
|
css: '[data-testid="eth-overview__primary-currency"]',
|
||||||
text: '24.9977 ETH',
|
text: `${balanceAfterDeployment} ETH`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send TST
|
// Send TST
|
||||||
|
@ -17,7 +17,6 @@ describe('Sign Typed Data V4 Signature Request', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -27,7 +26,9 @@ describe('Sign Typed Data V4 Signature Request', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
@ -97,7 +98,6 @@ describe('Sign Typed Data V3 Signature Request', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -107,7 +107,9 @@ describe('Sign Typed Data V3 Signature Request', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
@ -178,7 +180,6 @@ describe('Sign Typed Data Signature Request', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -188,7 +189,9 @@ describe('Sign Typed Data Signature Request', function () {
|
|||||||
ganacheOptions,
|
ganacheOptions,
|
||||||
title: this.test.title,
|
title: this.test.title,
|
||||||
},
|
},
|
||||||
async ({ driver }) => {
|
async ({ driver, ganacheServer }) => {
|
||||||
|
const addresses = await ganacheServer.getAccounts();
|
||||||
|
const publicAddress = addresses[0];
|
||||||
await driver.navigate();
|
await driver.navigate();
|
||||||
await driver.fill('#password', 'correct horse battery staple');
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
await driver.press('#password', driver.Key.ENTER);
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user