1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

e2e test erc20 fixtures (#18154)

* add fixture

* update test

* update test

* wait for ETH balance
This commit is contained in:
Peter 2023-03-17 09:55:52 +00:00 committed by GitHub
parent 3c622cd395
commit e1ce248364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 82 deletions

View File

@ -701,6 +701,43 @@ class FixtureBuilder {
return this;
}
withTokensControllerERC20() {
merge(this.fixture.data.TokensController, {
tokens: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`,
symbol: 'TST',
decimals: 4,
image:
'https://static.metafi.codefi.network/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png',
isERC721: false,
aggregators: [],
},
],
ignoredTokens: [],
detectedTokens: [],
allTokens: {
'0x539': {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`,
symbol: 'TST',
decimals: 4,
image:
'https://static.metafi.codefi.network/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png',
isERC721: false,
aggregators: [],
},
],
},
},
allIgnoredTokens: {},
allDetectedTokens: {},
suggestedAssets: [],
});
return this;
}
withTransactionController(data) {
merge(
this.fixture.data.TransactionController

View File

@ -123,43 +123,20 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
fixtures: new FixtureBuilder().withTokensControllerERC20().build(),
ganacheOptions,
smartContract,
title: this.test.title,
failOnConsoleError: false,
},
async ({ driver, contractRegistry }) => {
const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await driver.openNewPage(
`http://127.0.0.1:8080/?contract=${contractAddress}`,
);
let windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
// Using the line below to make wait time deterministic and avoid using a delay
// See more here https://github.com/MetaMask/metamask-extension/pull/15604/files#r949300551
await driver.findClickableElement('#deployButton');
// Add token
await driver.clickElement('#watchAsset');
await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ text: 'Add token', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.waitForSelector({
css: '[data-testid="eth-overview__primary-currency"]',
text: '24.9977 ETH',
});
// Send TST
await driver.clickElement('[data-testid="home__asset-tab"]');
@ -175,7 +152,10 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
css: '.ens-input__selected-input__title',
text: hexPrefixedAddress,
});
await driver.delay(2000);
await driver.waitForSelector({
css: '.transaction-detail-item',
text: '0.00008346 ETH',
});
await driver.clickElement({ text: 'Next', tag: 'button' });
// Confirm transaction
@ -208,42 +188,20 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
fixtures: new FixtureBuilder().withTokensControllerERC20().build(),
ganacheOptions,
smartContract,
title: this.test.title,
failOnConsoleError: false,
},
async ({ driver, contractRegistry }) => {
const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
// Create TST
await driver.openNewPage(
`http://127.0.0.1:8080/?contract=${contractAddress}`,
);
let windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
// Add token
await driver.findClickableElement('#deployButton');
await driver.clickElement('#watchAsset');
await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ text: 'Add token', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.waitForSelector({
css: '[data-testid="eth-overview__primary-currency"]',
text: '24.9977 ETH',
});
// Send TST
await driver.clickElement('[data-testid="home__asset-tab"]');
@ -259,7 +217,10 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () {
css: '.ens-input__selected-input__title',
text: hexPrefixedAddress,
});
await driver.delay(2000);
await driver.waitForSelector({
css: '.transaction-detail-item',
text: '0.00008346 ETH',
});
await driver.clickElement({ text: 'Next', tag: 'button' });
// Confirm transaction

View File

@ -18,9 +18,7 @@ describe('Send ERC20 token to contract address', function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
fixtures: new FixtureBuilder().withTokensControllerERC20().build(),
ganacheOptions,
smartContract,
title: this.test.title,
@ -34,26 +32,6 @@ describe('Send ERC20 token to contract address', function () {
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
// Create TST
await driver.openNewPage(
`http://127.0.0.1:8080/?contract=${contractAddress}`,
);
let windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
// Add token
await driver.findClickableElement('#deployButton');
await driver.clickElement('#watchAsset');
await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.clickElement({ text: 'Add token', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
// Send TST
await driver.clickElement('[data-testid="home__asset-tab"]');
await driver.clickElement('.token-cell');